lib/virtualbox/vm.rb in virtualbox-0.3.0 vs lib/virtualbox/vm.rb in virtualbox-0.4.0
- old
+ new
@@ -73,10 +73,12 @@
# understand this, read {Relatable}.
#
# relationship :nics, Nic
# relationship :storage_controllers, StorageController, :dependent => :destroy
# relationship :shared_folders, SharedFolder
+ # relationship :extra_data, ExtraData
+ # relationship :forwarded_ports, ForwardedPort
#
class VM < AbstractModel
attribute :uuid, :readonly => true
attribute :name
attribute :ostype
@@ -104,10 +106,12 @@
attribute :vrdp
attribute :state, :populate_key => :vmstate, :readonly => true
relationship :nics, Nic
relationship :storage_controllers, StorageController, :dependent => :destroy
relationship :shared_folders, SharedFolder
+ relationship :extra_data, ExtraData
+ relationship :forwarded_ports, ForwardedPort
class <<self
# Returns an array of all available VMs.
#
# @return [Array<VM>]
@@ -142,27 +146,27 @@
#
# **This method typically won't be used except internally.**
#
# @return [String]
def human_info(name)
- Command.vboxmanage("showvminfo #{name}")
+ Command.vboxmanage("showvminfo #{Command.shell_escape(name)}")
end
# Gets the VM info (machine readable) for a given VM and returns it
# as a hash.
#
# @return [Hash] Parsed VM info.
def raw_info(name)
- raw = Command.vboxmanage("showvminfo #{name} --machinereadable")
+ raw = Command.vboxmanage("showvminfo #{Command.shell_escape(name)} --machinereadable")
parse_vm_info(raw)
end
# Parses the machine-readable format outputted by VBoxManage showvminfo
# into a hash. Ignores lines which don't match the format.
def parse_vm_info(raw)
parsed = {}
- raw.lines.each do |line|
+ raw.split("\n").each do |line|
# Some lines aren't configuration, we just ignore them
next unless line =~ /^"?(.+?)"?="?(.+?)"?$/
parsed[$1.downcase.to_sym] = $2.strip
end
@@ -175,10 +179,10 @@
# **This method typically won't be used except internally.**
#
# @return [Array] Array of virtual machines.
def parse_vm_list(raw)
results = []
- raw.lines.each do |line|
+ raw.split("\n").each do |line|
next unless line =~ /^"(.+?)"\s+\{(.+?)\}$/
results.push(find($1.to_s))
end
results
\ No newline at end of file