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

View File

@ -7,16 +7,16 @@ module Vagrant
end end
def call(env) def call(env)
box_name = env["config"].vm.box box_name = env[:vm].config.vm.box
raise Errors::BoxNotSpecified if !box_name raise Errors::BoxNotSpecified if !box_name
if !env.env.boxes.find(box_name) if !env[:box_collection].find(box_name)
box_url = env["config"].vm.box_url box_url = env[:vm].config.vm.box_url
raise Errors::BoxSpecifiedDoesntExist, :name => box_name if !box_url raise Errors::BoxSpecifiedDoesntExist, :name => box_name if !box_url
# Add the box then reload the box collection so that it becomes # Add the box then reload the box collection so that it becomes
# aware of it. # 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) Vagrant::Box.add(env.env, box_name, box_url)
env["boxes"].reload! env["boxes"].reload!

View File

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

View File

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

View File

@ -7,31 +7,32 @@ module Vagrant
end end
def call(env) 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 # Import the virtual machine
env.env.vm.vm = VirtualBox::VM.import(env.env.box.ovf_file.to_s) do |progress| env[:vm].vm = VirtualBox::VM.import(env[:vm].box.directory.join("box.ovf").to_s) do |progress|
env.ui.clear_line env[:ui].clear_line
env.ui.report_progress(progress.percent, 100, false) env[:ui].report_progress(progress.percent, 100, false)
end end
# 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
# immediately. # immediately.
env.ui.clear_line env[:ui].clear_line
# Flag as erroneous and return if import failed # 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 # Import completed successfully. Continue the chain
@app.call(env) @app.call(env)
end end
def recover(env) def recover(env)
if env["vm"].created? if env[:vm].created?
return if env["vagrant.error"].is_a?(Errors::VagrantError) return if env["vagrant.error"].is_a?(Errors::VagrantError)
# Interrupted, destroy the VM # Interrupted, destroy the VM
env["actions"].run(:destroy) # TODO
# env[:action_runner].run(:destroy)
end end
end end
end end

View File

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

View File

@ -12,7 +12,7 @@ module Vagrant
raise Errors::NetworkNotImplemented raise Errors::NetworkNotImplemented
end 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) raise Errors::NetworkCollision if !verify_no_bridge_collision(network_options)
end end
end end
@ -24,10 +24,10 @@ module Vagrant
@app.call(env) @app.call(env)
if enable_network? 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... # 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| options.each do |network_options|
@env["vm"].system.prepare_host_only_network(network_options) @env["vm"].system.prepare_host_only_network(network_options)
end end
@ -59,7 +59,7 @@ module Vagrant
end end
def enable_network? def enable_network?
!@env.env.config.vm.network_options.compact.empty? !@env[:vm].config.vm.network_options.compact.empty?
end end
# Enables and assigns the host only network to the proper # 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. # Checks if there are any NFS enabled shared folders.
def nfs_enabled? 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] return true if opts[:nfs]
end end

View File

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

View File

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