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
|
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
|
||||||
|
|
||||||
|
|
|
@ -32,17 +32,13 @@ 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
|
|
||||||
run `vagrant down` first.
|
|
||||||
error
|
|
||||||
end
|
|
||||||
|
|
||||||
Env.require_box
|
Env.require_box
|
||||||
VM.execute!(Actions::VM::Up)
|
VM.execute!(Actions::VM::Up)
|
||||||
end
|
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
|
||||||
# (if its running), but also deletes it from the system, including the
|
# (if its running), but also deletes it from the system, including the
|
||||||
|
|
|
@ -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?
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue