providers/virtualbox: fix some crashing bugs

This commit is contained in:
Mitchell Hashimoto 2015-10-06 16:22:48 -04:00
parent 3b3de6e2e5
commit 0586412f9d
3 changed files with 10 additions and 9 deletions

View File

@ -18,6 +18,7 @@ module VagrantPlugins
end end
# Set the machine ID # Set the machine ID
env[:machine_id] = id
env[:machine].id = id if !env[:skip_machine] env[:machine].id = id if !env[:skip_machine]
# Clear the line one last time since the progress meter doesn't disappear # Clear the line one last time since the progress meter doesn't disappear
@ -29,14 +30,14 @@ module VagrantPlugins
return if env[:interrupted] return if env[:interrupted]
# Flag as erroneous and return if import failed # Flag as erroneous and return if import failed
raise Vagrant::Errors::VMImportFailure if !env[:machine].id raise Vagrant::Errors::VMImportFailure if !id
# Import completed successfully. Continue the chain # Import completed successfully. Continue the chain
@app.call(env) @app.call(env)
end end
def recover(env) def recover(env)
if env[:machine].state.id != :not_created if env[:machine] && env[:machine].state.id != :not_created
return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError) return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError)
# If we're not supposed to destroy on error then just return # If we're not supposed to destroy on error then just return

View File

@ -49,10 +49,10 @@ module VagrantPlugins
end end
env[:ui].info(I18n.t("vagrant.actions.vm.clone.setup_master")) env[:ui].info(I18n.t("vagrant.actions.vm.clone.setup_master"))
env[:ui].detail("\n"+I18n.t("vagrant.actions.vm.clone.setup_master_detail")) env[:ui].detail(I18n.t("vagrant.actions.vm.clone.setup_master_detail"))
# Import the virtual machine # Import the virtual machine
import_env = env[:action_runner].run(Import, skip_machine: true) import_env = env[:action_runner].run(Import, env.dup.merge(skip_machine: true))
env[:master_id] = import_env[:machine_id] env[:master_id] = import_env[:machine_id]
@logger.info( @logger.info(

View File

@ -36,13 +36,13 @@ module VagrantPlugins
def clonevm(master_id, box_name, snapshot_name) def clonevm(master_id, box_name, snapshot_name)
@logger.debug("Creating linked clone from master vm with id #{master_id} from snapshot '#{snapshot_name}'") @logger.debug("Creating linked clone from master vm with id #{master_id} from snapshot '#{snapshot_name}'")
machine_name = "#{box_name}_#{snapshot_name}_clone_#{(Time.now.to_f * 1000.0).to_i}_#{rand(100000)}" machine_name = "#{box_name}_#{snapshot_name}_clone_#{(Time.now.to_f * 1000.0).to_i}_#{rand(100000)}"
execute("clonevm", master_id, "--snapshot", snapshot_name, "--options", "link", "--register", "--name", machine_name) execute("clonevm", master_id, "--snapshot", snapshot_name, "--options", "link", "--register", "--name", machine_name)
return get_machine_id machine_name return get_machine_id machine_name
end end
def create_dhcp_server(network, options) def create_dhcp_server(network, options)
execute("dhcpserver", "add", "--ifname", network, execute("dhcpserver", "add", "--ifname", network,
"--ip", options[:dhcp_ip], "--ip", options[:dhcp_ip],
@ -85,7 +85,7 @@ module VagrantPlugins
def create_snapshot(machine_id, snapshot_name) def create_snapshot(machine_id, snapshot_name)
execute("snapshot", machine_id, "take", snapshot_name) execute("snapshot", machine_id, "take", snapshot_name)
end end
def delete def delete
execute("unregistervm", @uuid, "--delete") execute("unregistervm", @uuid, "--delete")
end end
@ -186,7 +186,7 @@ module VagrantPlugins
return match[1].to_s if match return match[1].to_s if match
nil nil
end end
def halt def halt
execute("controlvm", @uuid, "poweroff") execute("controlvm", @uuid, "poweroff")
end end