`vagrant resume` with multiple VMs
This commit is contained in:
parent
228327c0ca
commit
38d485c29b
|
@ -10,8 +10,33 @@ module Vagrant
|
||||||
description "Resumes a suspend vagrant environment"
|
description "Resumes a suspend vagrant environment"
|
||||||
|
|
||||||
def execute(args=[])
|
def execute(args=[])
|
||||||
env.require_persisted_vm
|
args = parse_options(args)
|
||||||
env.vm.resume
|
|
||||||
|
if args[0]
|
||||||
|
resume_single(args[0])
|
||||||
|
else
|
||||||
|
resume_all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def resume_single(name)
|
||||||
|
vm = env.vms[name.to_sym]
|
||||||
|
if vm.nil?
|
||||||
|
error_and_exit(:unknown_vm, :vm => name)
|
||||||
|
return # for tests
|
||||||
|
end
|
||||||
|
|
||||||
|
if vm.created?
|
||||||
|
vm.resume
|
||||||
|
else
|
||||||
|
logger.info "VM '#{name}' not created. Ignoring."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def resume_all
|
||||||
|
env.vms.keys.each do |name|
|
||||||
|
resume_single(name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def options_spec(opts)
|
def options_spec(opts)
|
||||||
|
@ -19,4 +44,4 @@ module Vagrant
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,30 +4,58 @@ class CommandsResumeTest < Test::Unit::TestCase
|
||||||
setup do
|
setup do
|
||||||
@klass = Vagrant::Commands::Resume
|
@klass = Vagrant::Commands::Resume
|
||||||
|
|
||||||
@persisted_vm = mock("persisted_vm")
|
|
||||||
@persisted_vm.stubs(:execute!)
|
|
||||||
|
|
||||||
@env = mock_environment
|
@env = mock_environment
|
||||||
@env.stubs(:require_persisted_vm)
|
|
||||||
@env.stubs(:vm).returns(@persisted_vm)
|
|
||||||
|
|
||||||
@instance = @klass.new(@env)
|
@instance = @klass.new(@env)
|
||||||
end
|
end
|
||||||
|
|
||||||
context "executing" do
|
context "executing" do
|
||||||
|
should "call on all if no name is given" do
|
||||||
|
@instance.expects(:resume_all).once
|
||||||
|
@instance.execute
|
||||||
|
end
|
||||||
|
|
||||||
|
should "call on single if a name is given" do
|
||||||
|
@instance.expects(:resume_single).with("foo").once
|
||||||
|
@instance.execute(["foo"])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "resume all" do
|
||||||
|
should "resume each VM" do
|
||||||
|
vms = { :foo => nil, :bar => nil, :baz => nil }
|
||||||
|
@env.stubs(:vms).returns(vms)
|
||||||
|
|
||||||
|
vms.each do |name, value|
|
||||||
|
@instance.expects(:resume_single).with(name).once
|
||||||
|
end
|
||||||
|
|
||||||
|
@instance.resume_all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "resuming a single VM" do
|
||||||
setup do
|
setup do
|
||||||
@persisted_vm.stubs(:resume)
|
@foo_vm = mock("vm")
|
||||||
@persisted_vm.stubs(:saved?).returns(true)
|
vms = { :foo => @foo_vm }
|
||||||
|
@env.stubs(:vms).returns(vms)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "require a persisted VM" do
|
should "error and exit if the VM doesn't exist" do
|
||||||
@env.expects(:require_persisted_vm).once
|
@env.stubs(:vms).returns({})
|
||||||
@instance.execute
|
@instance.expects(:error_and_exit).with(:unknown_vm, :vm => :foo).once
|
||||||
|
@instance.resume_single(:foo)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "save the state of the VM" do
|
should "resume if its created" do
|
||||||
@persisted_vm.expects(:resume).once
|
@foo_vm.stubs(:created?).returns(true)
|
||||||
@instance.execute
|
@foo_vm.expects(:resume).once
|
||||||
|
@instance.execute(["foo"])
|
||||||
|
end
|
||||||
|
|
||||||
|
should "do nothing if its not created" do
|
||||||
|
@foo_vm.stubs(:created?).returns(false)
|
||||||
|
@foo_vm.expects(:resume).never
|
||||||
|
@instance.resume_single(:foo)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,13 +46,7 @@ class CommandsSuspendTest < Test::Unit::TestCase
|
||||||
@instance.suspend_single(:foo)
|
@instance.suspend_single(:foo)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "halt if its created" do
|
should "suspend if its created" do
|
||||||
@foo_vm.stubs(:created?).returns(true)
|
|
||||||
@foo_vm.expects(:suspend).once
|
|
||||||
@instance.execute(["foo"])
|
|
||||||
end
|
|
||||||
|
|
||||||
should "halt and force if specified" do
|
|
||||||
@foo_vm.stubs(:created?).returns(true)
|
@foo_vm.stubs(:created?).returns(true)
|
||||||
@foo_vm.expects(:suspend).once
|
@foo_vm.expects(:suspend).once
|
||||||
@instance.execute(["foo"])
|
@instance.execute(["foo"])
|
||||||
|
|
Loading…
Reference in New Issue