Fixing up VM actions to try to get them working again

This commit is contained in:
Mitchell Hashimoto 2011-12-09 20:39:08 -08:00
parent 739d5ffb5f
commit 1758970a53
10 changed files with 54 additions and 44 deletions

View File

@ -63,8 +63,8 @@ module Vagrant
registry.register(:reload) do
Builder.new do
use VM::CheckAccessible
use Action[:halt]
use Action[:start]
use registry.get(:halt)
use registry.get(:start)
end
end
@ -76,7 +76,7 @@ module Vagrant
use VM::Import
use VM::MatchMACAddress
use VM::CheckGuestAdditions
use Action[:start]
use registry.get(:start)
end
end
@ -84,7 +84,7 @@ module Vagrant
registry.register(:destroy) do
Builder.new do
use VM::CheckAccessible
use Action[:halt], :force => true
use registry.get(:halt), :force => true
use VM::ProvisionerCleanup
use VM::ClearNFSExports
use VM::Destroy
@ -97,7 +97,7 @@ module Vagrant
registry.register(:package) do
Builder.new do
use VM::CheckAccessible
use Action[:halt]
use registry.get(:halt)
use VM::ClearForwardedPorts
use VM::ClearSharedFolders
use VM::Modify

View File

@ -7,16 +7,16 @@ module Vagrant
end
def call(env)
box_name = env["config"].vm.box
box_name = env[:vm].config.vm.box
raise Errors::BoxNotSpecified if !box_name
if !env.env.boxes.find(box_name)
box_url = env["config"].vm.box_url
if !env[:box_collection].find(box_name)
box_url = env[:vm].config.vm.box_url
raise Errors::BoxSpecifiedDoesntExist, :name => box_name if !box_url
# Add the box then reload the box collection so that it becomes
# aware of it.
env.ui.info I18n.t("vagrant.actions.vm.check_box.not_found", :name => box_name)
env[:ui].info I18n.t("vagrant.actions.vm.check_box.not_found", :name => box_name)
Vagrant::Box.add(env.env, box_name, box_url)
env["boxes"].reload!

View File

@ -12,9 +12,9 @@ module Vagrant
def call(env)
# Use the raw interface for now, while the virtualbox gem
# doesn't support guest properties (due to cross platform issues)
version = env["vm"].vm.interface.get_guest_property_value("/VirtualBox/GuestAdd/Version")
version = env[:vm].vm.interface.get_guest_property_value("/VirtualBox/GuestAdd/Version")
if version.empty?
env.ui.warn I18n.t("vagrant.actions.vm.check_guest_additions.not_detected")
env[:ui].warn I18n.t("vagrant.actions.vm.check_guest_additions.not_detected")
else
# Strip the -OSE/_OSE off from the guest additions and the virtual box
# version since all the matters are that the version _numbers_ match up.
@ -23,9 +23,9 @@ module Vagrant
end
if guest_version != vb_version
env.ui.warn(I18n.t("vagrant.actions.vm.check_guest_additions.version_mismatch",
:guest_version => version,
:virtualbox_version => VirtualBox.version))
env[:ui].warn(I18n.t("vagrant.actions.vm.check_guest_additions.version_mismatch",
:guest_version => version,
:virtualbox_version => VirtualBox.version))
end
end

View File

@ -22,7 +22,7 @@ module Vagrant
# This method checks for any forwarded ports on the host below
# 1024, which causes the forwarded ports to fail.
def threshold_check
@env.env.config.vm.forwarded_ports.each do |name, options|
@env[:vm].config.vm.forwarded_ports.each do |name, options|
if options[:hostport] <= 1024
@env.ui.warn I18n.t("vagrant.actions.vm.forward_ports.privileged_ports")
return
@ -36,7 +36,7 @@ module Vagrant
# automatically if the port is configured to do so.
def external_collision_check
existing = used_ports
@env.env.config.vm.forwarded_ports.each do |name, options|
@env[:vm].config.vm.forwarded_ports.each do |name, options|
if existing.include?(options[:hostport].to_i)
handle_collision(name, options, existing)
end

View File

@ -7,31 +7,32 @@ module Vagrant
end
def call(env)
env.ui.info I18n.t("vagrant.actions.vm.import.importing", :name => env.env.box.name)
env[:ui].info I18n.t("vagrant.actions.vm.import.importing", :name => env[:vm].box.name)
# Import the virtual machine
env.env.vm.vm = VirtualBox::VM.import(env.env.box.ovf_file.to_s) do |progress|
env.ui.clear_line
env.ui.report_progress(progress.percent, 100, false)
env[:vm].vm = VirtualBox::VM.import(env[:vm].box.directory.join("box.ovf").to_s) do |progress|
env[:ui].clear_line
env[:ui].report_progress(progress.percent, 100, false)
end
# Clear the line one last time since the progress meter doesn't disappear
# immediately.
env.ui.clear_line
env[:ui].clear_line
# Flag as erroneous and return if import failed
raise Errors::VMImportFailure if !env["vm"].vm
raise Errors::VMImportFailure if !env[:vm].vm
# Import completed successfully. Continue the chain
@app.call(env)
end
def recover(env)
if env["vm"].created?
if env[:vm].created?
return if env["vagrant.error"].is_a?(Errors::VagrantError)
# Interrupted, destroy the VM
env["actions"].run(:destroy)
# TODO
# env[:action_runner].run(:destroy)
end
end
end

View File

@ -7,12 +7,12 @@ module Vagrant
end
def call(env)
raise Errors::VMBaseMacNotSpecified if !env.env.config.vm.base_mac
raise Errors::VMBaseMacNotSpecified if !env[:vm].config.vm.base_mac
# Create the proc which we want to use to modify the virtual machine
proc = lambda do |vm|
env.ui.info I18n.t("vagrant.actions.vm.match_mac.matching")
vm.network_adapters.first.mac_address = env["config"].vm.base_mac
env[:ui].info I18n.t("vagrant.actions.vm.match_mac.matching")
vm.network_adapters.first.mac_address = env[:vm].config.vm.base_mac
end
# Add the proc to the modification chain

View File

@ -12,7 +12,7 @@ module Vagrant
raise Errors::NetworkNotImplemented
end
env["config"].vm.network_options.compact.each do |network_options|
env[:vm].config.vm.network_options.compact.each do |network_options|
raise Errors::NetworkCollision if !verify_no_bridge_collision(network_options)
end
end
@ -24,10 +24,10 @@ module Vagrant
@app.call(env)
if enable_network?
@env.ui.info I18n.t("vagrant.actions.vm.network.enabling")
@env[:ui].info I18n.t("vagrant.actions.vm.network.enabling")
# Prepare for new networks...
options = @env.env.config.vm.network_options.compact
options = @env[:vm].config.vm.network_options.compact
options.each do |network_options|
@env["vm"].system.prepare_host_only_network(network_options)
end
@ -59,7 +59,7 @@ module Vagrant
end
def enable_network?
!@env.env.config.vm.network_options.compact.empty?
!@env[:vm].config.vm.network_options.compact.empty?
end
# Enables and assigns the host only network to the proper

View File

@ -141,7 +141,7 @@ module Vagrant
# Checks if there are any NFS enabled shared folders.
def nfs_enabled?
@env["config"].vm.shared_folders.each do |key, opts|
@env[:vm].config.vm.shared_folders.each do |key, opts|
return true if opts[:nfs]
end

View File

@ -211,9 +211,10 @@ module Vagrant
def action_runner
@action_runner ||= Action::Runner.new(action_registry) do |env|
{
:global_config => config.global,
:tmp_path => tmp_path,
:ui => @ui
:global_config => config.global,
:box_collection => boxes,
:tmp_path => tmp_path,
:ui => @ui
}
end
end

View File

@ -7,6 +7,7 @@ module Vagrant
attr_reader :env
attr_reader :name
attr_reader :vm
attr_reader :box
attr_reader :config
def initialize(name, env, config, vm=nil)
@ -16,6 +17,7 @@ module Vagrant
@vm = vm
@env = env
@config = config
@box = env.boxes.find(config.vm.box)
# Load the associated system.
load_system!
@ -112,11 +114,11 @@ module Vagrant
end
def package(options=nil)
env.actions.run(:package, { "validate" => false }.merge(options || {}))
run_action(:package, { "validate" => false }.merge(options || {}))
end
def up(options=nil)
env.actions.run(:up, options)
run_action(:up, options)
end
def start(options=nil)
@ -124,31 +126,31 @@ module Vagrant
return if @vm.running?
return resume if @vm.saved?
env.actions.run(:start, options)
run_action(:start, options)
end
def halt(options=nil)
env.actions.run(:halt, options)
run_action(:halt, options)
end
def reload
env.actions.run(:reload)
run_action(:reload)
end
def provision
env.actions.run(:provision)
run_action(:provision)
end
def destroy
env.actions.run(:destroy)
run_action(:destroy)
end
def suspend
env.actions.run(:suspend)
run_action(:suspend)
end
def resume
env.actions.run(:resume)
run_action(:resume)
end
def saved?
@ -156,5 +158,11 @@ module Vagrant
end
def powered_off?; @vm.powered_off? end
protected
def run_action(name, options=nil)
env.action_runner.run(name, { :vm => self }.merge(options || {}))
end
end
end