From 642db533eecc586cbe11a2428f0a88ae773b3881 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 6 Jul 2010 20:35:31 -0700 Subject: [PATCH] Start, reload, halt now use middleware stacks --- lib/vagrant/action/builtin.rb | 41 +++++++++++++++++++++++++++++------ lib/vagrant/vm.rb | 6 ++--- test/vagrant/vm_test.rb | 11 +++------- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/lib/vagrant/action/builtin.rb b/lib/vagrant/action/builtin.rb index 258da5812..f1c01b249 100644 --- a/lib/vagrant/action/builtin.rb +++ b/lib/vagrant/action/builtin.rb @@ -5,11 +5,9 @@ module Vagrant # all the necessary Vagrant libraries are loaded. Hopefully # in the future this will no longer be necessary with autoloading. def self.builtin! - up = Builder.new do - use VM::Import - use VM::Persist - use VM::MatchMACAddress - use VM::CheckGuestAdditions + # start - Starts a VM, assuming it already exists on the + # environment. + start = Builder.new do use VM::Customize use VM::ForwardPorts use VM::Provision @@ -18,13 +16,42 @@ module Vagrant use VM::Boot end - destroy = Builder.new do + register :start, start + + # halt - Halts the VM, attempting gracefully but then forcing + # a restart if fails. + halt = Builder.new do use VM::Halt + end + + register :halt, halt + + # reload - Halts then restarts the VM + reload = Builder.new do + use Action[:halt].mergeable + use Action[:start].mergeable + end + + register :reload, reload + + # up - Imports, prepares, then starts a fresh VM. + up = Builder.new do + use VM::Import + use VM::Persist + use VM::MatchMACAddress + use VM::CheckGuestAdditions + use Action[:start].mergeable + end + + register :up, up + + # destroy - Halts, cleans up, and destroys an existing VM + destroy = Builder.new do + use Action[:halt].mergeable use VM::DestroyUnusedNetworkInterfaces use VM::Destroy end - register :up, up register :destroy, destroy end end diff --git a/lib/vagrant/vm.rb b/lib/vagrant/vm.rb index aa50f17ff..4853f8ae7 100644 --- a/lib/vagrant/vm.rb +++ b/lib/vagrant/vm.rb @@ -106,15 +106,15 @@ module Vagrant def start return if @vm.running? - execute!(Actions::VM::Start) + env.actions.run(:start) end def halt(options=nil) - execute!(Actions::VM::Halt, options) + env.actions.run(:halt, options) end def reload - execute!(Actions::VM::Reload) + env.actions.run(:reload) end def provision diff --git a/test/vagrant/vm_test.rb b/test/vagrant/vm_test.rb index f6c65b008..9b699c3d7 100644 --- a/test/vagrant/vm_test.rb +++ b/test/vagrant/vm_test.rb @@ -170,19 +170,14 @@ class VMTest < Test::Unit::TestCase context "halting" do should "execute the halt action" do - @vm.expects(:execute!).with(Vagrant::Actions::VM::Halt, nil).once - @vm.halt - end - - should "force if specified" do - @vm.expects(:execute!).with(Vagrant::Actions::VM::Halt, {:foo => :bar}).once + @vm.env.actions.expects(:run).with(:halt, :foo => :bar).once @vm.halt({:foo => :bar}) end end context "reloading action" do should "execute the reload action" do - @vm.expects(:execute!).with(Vagrant::Actions::VM::Reload).once + @vm.env.actions.expects(:run).with(:reload).once @vm.reload end end @@ -227,7 +222,7 @@ class VMTest < Test::Unit::TestCase end should "execute the start action" do - @vm.expects(:execute!).once.with(Vagrant::Actions::VM::Start) + @vm.env.actions.expects(:run).with(:start).once @vm.start end end