From 5efa7bded58a03d7feb033ab433c8f1c2e3b6b8f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 13 Apr 2010 16:36:08 -0700 Subject: [PATCH] Suspend subcommand --- lib/vagrant/commands/suspend.rb | 23 +++++++++++++++++++ test/vagrant/commands/suspend_test.rb | 33 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 lib/vagrant/commands/suspend.rb create mode 100644 test/vagrant/commands/suspend_test.rb 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