diff --git a/lib/vagrant/commands/halt.rb b/lib/vagrant/commands/halt.rb new file mode 100644 index 000000000..181de57b1 --- /dev/null +++ b/lib/vagrant/commands/halt.rb @@ -0,0 +1,23 @@ +module Vagrant + class Commands + # Halts a running vagrant instance. This forcibly halts the instance; + # it is the equivalent of pulling the power on a machine. The instance + # can be restarted again with {up}. + # + # This command requires than an instance already be brought up with + # `vagrant up`. + class Halt < Base + Base.subcommand "halt", self + description "Halts the currently running vagrant environment" + + def execute(args=[]) + env.require_persisted_vm + env.vm.execute!(Actions::VM::Halt) + end + + def options_spec(opts) + opts.banner = "Usage: vagrant halt" + end + end + end +end \ No newline at end of file diff --git a/lib/vagrant/commands/ssh_config.rb b/lib/vagrant/commands/ssh_config.rb index fdbb33e7e..364f42689 100644 --- a/lib/vagrant/commands/ssh_config.rb +++ b/lib/vagrant/commands/ssh_config.rb @@ -1,10 +1,7 @@ module Vagrant class Commands - # Reload the environment. This is almost equivalent to the {up} command - # except that it doesn't import the VM and do the initialize bootstrapping - # of the instance. Instead, it forces a shutdown (if its running) of the - # VM, updates the metadata (shared folders, forwarded ports), restarts - # the VM, and then reruns the provisioning if enabled. + # Outputs a valid entry for .ssh/config which can be used to connect + # to this environment. class SSHConfig < Base Base.subcommand "ssh-config", self description "outputs .ssh/config valid syntax for connecting to this environment via ssh" diff --git a/test/vagrant/commands/halt_test.rb b/test/vagrant/commands/halt_test.rb new file mode 100644 index 000000000..291abf257 --- /dev/null +++ b/test/vagrant/commands/halt_test.rb @@ -0,0 +1,28 @@ +require File.join(File.dirname(__FILE__), '..', '..', 'test_helper') + +class CommandsHaltTest < Test::Unit::TestCase + setup do + @klass = Vagrant::Commands::Halt + + @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 + should "require a persisted VM" do + @env.expects(:require_persisted_vm).once + @instance.execute + end + + should "call the `halt` action on the VM" do + @persisted_vm.expects(:execute!).with(Vagrant::Actions::VM::Halt).once + @instance.execute + end + end +end