Halt command

This commit is contained in:
Mitchell Hashimoto 2010-04-13 16:34:29 -07:00
parent fa3ca57c9f
commit 28a2fd5466
3 changed files with 53 additions and 5 deletions

View File

@ -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

View File

@ -1,10 +1,7 @@
module Vagrant module Vagrant
class Commands class Commands
# Reload the environment. This is almost equivalent to the {up} command # Outputs a valid entry for .ssh/config which can be used to connect
# except that it doesn't import the VM and do the initialize bootstrapping # to this environment.
# 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.
class SSHConfig < Base class SSHConfig < Base
Base.subcommand "ssh-config", self Base.subcommand "ssh-config", self
description "outputs .ssh/config valid syntax for connecting to this environment via ssh" description "outputs .ssh/config valid syntax for connecting to this environment via ssh"

View File

@ -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