vagrant-up now starts the VM if its already created, rather than giving an error.

This commit is contained in:
Mitchell Hashimoto 2010-03-02 22:07:04 -08:00
parent c119a34f0e
commit c7f040f14c
5 changed files with 37 additions and 16 deletions

View File

@ -18,7 +18,9 @@ GitStyleBinary.command do
banner <<-EOS
Usage: #{command.full_name} #{all_options_string}
Create the vagrant environment.
Create the vagrant environment if it doesn't exist,
otherwise start the vagrant environment if its not
already running.
EOS

View File

@ -32,16 +32,12 @@ error
Env.load!
if Env.persisted_vm
error_and_exit(<<-error)
The task you're trying to run requires that the vagrant environment
not exist yet, but it appears you already have an instance running
or available. If you really want to rebuild this instance, please
run `vagrant down` first.
error
logger.info "VM already created. Starting VM if its not already running..."
Env.persisted_vm.start
else
Env.require_box
VM.execute!(Actions::VM::Up)
end
Env.require_box
VM.execute!(Actions::VM::Up)
end
# Tear down a vagrant instance. This not only shuts down the instance

View File

@ -25,6 +25,15 @@ module Vagrant
execute!
end
def start
actions = [Actions::VM::ForwardPorts, Actions::VM::SharedFolders, Actions::VM::Start]
actions.each do |action|
add_action(action)
end
execute!
end
def destroy
execute!(Actions::VM::Halt) if @vm.running?

View File

@ -46,15 +46,15 @@ class CommandsTest < Test::Unit::TestCase
Vagrant::Commands.up
end
should "error if a persisted VM already exists" do
Vagrant::Env.expects(:persisted_vm).returns(true)
Vagrant::Commands.expects(:error_and_exit).once
Vagrant::VM.expects(:up).never
should "call the up action on VM if it doesn't exist" do
Vagrant::VM.expects(:execute!).with(Vagrant::Actions::VM::Up).once
Vagrant::Commands.up
end
should "call the up action on VM" do
Vagrant::VM.expects(:execute!).with(Vagrant::Actions::VM::Up).once
should "call start on the persisted vm if it exists" do
Vagrant::Env.stubs(:persisted_vm).returns(@persisted_vm)
@persisted_vm.expects(:start).once
Vagrant::VM.expects(:execute!).never
Vagrant::Commands.up
end
end

View File

@ -78,5 +78,19 @@ class VMTest < Test::Unit::TestCase
@vm.save_state
end
end
context "starting" do
should "add and execute the proper actions" do
actions = [Vagrant::Actions::VM::ForwardPorts, Vagrant::Actions::VM::SharedFolders, Vagrant::Actions::VM::Start]
action_seq = sequence("action_seq")
actions.each do |action|
@vm.expects(:add_action).with(action).in_sequence(action_seq)
end
@vm.expects(:execute!).once.in_sequence(action_seq)
@vm.start
end
end
end
end