vagrant-up now starts the VM if its already created, rather than giving an error.
This commit is contained in:
parent
c119a34f0e
commit
c7f040f14c
|
@ -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
|
||||
|
||||
|
|
|
@ -32,17 +32,13 @@ 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
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
# Tear down a vagrant instance. This not only shuts down the instance
|
||||
# (if its running), but also deletes it from the system, including the
|
||||
|
|
|
@ -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?
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue