diff --git a/lib/vagrant/commands/suspend.rb b/lib/vagrant/commands/suspend.rb new file mode 100644 index 000000000..9bdaa3d11 --- /dev/null +++ b/lib/vagrant/commands/suspend.rb @@ -0,0 +1,23 @@ +module Vagrant + class Commands + # Suspend a running vagrant instance. This suspends the instance, saving + # the state of the VM and "pausing" it. The instance can be resumed + # again with {resume}. + # + # This command requires that an instance already be brought up with + # `vagrant up`. + class Suspend < Base + Base.subcommand "suspend", self + description "Suspends the currently running vagrant environment" + + def execute(args=[]) + env.require_persisted_vm + env.vm.suspend + end + + def options_spec(opts) + opts.banner = "Usage: vagrant suspend" + end + end + end +end \ No newline at end of file diff --git a/test/vagrant/commands/suspend_test.rb b/test/vagrant/commands/suspend_test.rb new file mode 100644 index 000000000..ec0f037f1 --- /dev/null +++ b/test/vagrant/commands/suspend_test.rb @@ -0,0 +1,33 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class CommandsSuspendTest < Test::Unit::TestCase + setup do + @klass = Vagrant::Commands::Suspend + + @persisted_vm = mock("persisted_vm") + @persisted_vm.stubs(:execute!) + + @env = mock_environment + @env.stubs(:require_persisted_vm) + @env.stubs(:vm).returns(@persisted_vm) + + @instance = @klass.new(@env) + end + + context "executing" do + setup do + @persisted_vm.stubs(:suspend) + @persisted_vm.stubs(:saved?).returns(false) + end + + should "require a persisted VM" do + @env.expects(:require_persisted_vm).once + @instance.execute + end + + should "suspend the VM" do + @persisted_vm.expects(:suspend).once + @instance.execute + end + end +end