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 banner <<-EOS
Usage: #{command.full_name} #{all_options_string} 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 EOS

View File

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

View File

@ -25,6 +25,15 @@ module Vagrant
execute! execute!
end 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 def destroy
execute!(Actions::VM::Halt) if @vm.running? execute!(Actions::VM::Halt) if @vm.running?

View File

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

View File

@ -78,5 +78,19 @@ class VMTest < Test::Unit::TestCase
@vm.save_state @vm.save_state
end end
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
end end