lib/vagrant/driver/virtualbox_4_0.rb in vagrantup-0.9.7 vs lib/vagrant/driver/virtualbox_4_0.rb in vagrantup-0.9.99.1
- old
+ new
@@ -21,11 +21,12 @@
execute("modifyvm", @uuid, *args) if !args.empty?
end
def clear_shared_folders
- execute("showvminfo", @uuid, "--machinereadable").split("\n").each do |line|
+ info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
+ info.split("\n").each do |line|
if line =~ /^SharedFolderNameMachineMapping\d+="(.+?)"$/
execute("sharedfolder", "remove", @uuid, "--name", $1.to_s)
end
end
end
@@ -68,12 +69,13 @@
networks << $1.to_s if line =~ /^Name:\s+(.+?)$/
end
execute("list", "vms").split("\n").each do |line|
if line =~ /^".+?"\s+\{(.+?)\}$/
- execute("showvminfo", $1.to_s, "--machinereadable").split("\n").each do |info|
- if info =~ /^hostonlyadapter\d+="(.+?)"$/
+ info = execute("showvminfo", $1.to_s, "--machinereadable", :retryable => true)
+ info.split("\n").each do |line|
+ if line =~ /^hostonlyadapter\d+="(.+?)"$/
networks.delete($1.to_s)
end
end
end
end
@@ -200,11 +202,12 @@
@logger.debug("read_forward_ports: uuid=#{uuid} active_only=#{active_only}")
results = []
current_nic = nil
- execute("showvminfo", uuid, "--machinereadable").split("\n").each do |line|
+ info = execute("showvminfo", uuid, "--machinereadable", :retryable => true)
+ info.split("\n").each do |line|
# This is how we find the nic that a FP is attached to,
# since this comes first.
current_nic = $1.to_i if line =~ /^nic(\d+)=".+?"$/
# If we care about active VMs only, then we check the state
@@ -244,11 +247,12 @@
info
end
end
def read_guest_additions_version
- output = execute("guestproperty", "get", @uuid, "/VirtualBox/GuestAdd/Version")
+ output = execute("guestproperty", "get", @uuid, "/VirtualBox/GuestAdd/Version",
+ :retryable => true)
if output =~ /^Value: (.+?)$/
# Split the version by _ since some distro versions modify it
# to look like this: 4.1.2_ubuntu, and the distro part isn't
# too important.
value = $1.to_s
@@ -258,11 +262,11 @@
return nil
end
def read_host_only_interfaces
dhcp = {}
- execute("list", "dhcpservers").split("\n\n").each do |block|
+ execute("list", "dhcpservers", :retryable => true).split("\n\n").each do |block|
info = {}
block.split("\n").each do |line|
if line =~ /^NetworkName:\s+HostInterfaceNetworking-(.+?)$/
info[:network] = $1.to_s
@@ -277,11 +281,11 @@
# Set the DHCP info
dhcp[info[:network]] = info
end
- execute("list", "hostonlyifs").split("\n\n").collect do |block|
+ execute("list", "hostonlyifs", :retryable => true).split("\n\n").collect do |block|
info = {}
block.split("\n").each do |line|
if line =~ /^Name:\s+(.+?)$/
info[:name] = $1.to_s
@@ -300,30 +304,32 @@
info
end
end
def read_mac_address
- execute("showvminfo", @uuid, "--machinereadable").split("\n").each do |line|
+ info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
+ info.split("\n").each do |line|
return $1.to_s if line =~ /^macaddress1="(.+?)"$/
end
nil
end
def read_machine_folder
- execute("list", "systemproperties").split("\n").each do |line|
+ execute("list", "systemproperties", :retryable => true).split("\n").each do |line|
if line =~ /^Default machine folder:\s+(.+?)$/i
return $1.to_s
end
end
nil
end
def read_network_interfaces
nics = {}
- execute("showvminfo", @uuid, "--machinereadable").split("\n").each do |line|
+ info = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
+ info.split("\n").each do |line|
if line =~ /^nic(\d+)="(.+?)"$/
adapter = $1.to_i
type = $2.to_sym
nics[adapter] ||= {}
@@ -345,11 +351,11 @@
nics
end
def read_state
- output = execute("showvminfo", @uuid, "--machinereadable")
+ output = execute("showvminfo", @uuid, "--machinereadable", :retryable => true)
if output =~ /^name="<inaccessible>"$/
return :inaccessible
elsif output =~ /^VMState="(.+?)"$/
return $1.to_sym
end
@@ -357,11 +363,11 @@
nil
end
def read_used_ports
ports = []
- execute("list", "vms").split("\n").each do |line|
+ execute("list", "vms", :retryable => true).split("\n").each do |line|
if line =~ /^".+?" \{(.+?)\}$/
uuid = $1.to_s
# Ignore our own used ports
next if uuid == @uuid
@@ -375,11 +381,11 @@
ports
end
def read_vms
results = []
- execute("list", "vms").split("\n").each do |line|
+ execute("list", "vms", :retryable => true).split("\n").each do |line|
if line =~ /^".+?" \{(.+?)\}$/
results << $1.to_s
end
end
@@ -415,10 +421,20 @@
nil
end
def start(mode)
- execute("startvm", @uuid, "--type", mode.to_s)
+ command = ["startvm", @uuid, "--type", mode.to_s]
+ r = raw(*command)
+
+ if r.exit_code == 0 || r.stdout =~ /VM ".+?" has been successfully started/
+ # Some systems return an exit code 1 for some reason. For that
+ # we depend on the output.
+ return true
+ end
+
+ # If we reached this point then it didn't work out.
+ raise Errors::VBoxManageError, :command => command.inspect
end
def suspend
execute("controlvm", @uuid, "savestate")
end