SSH subcommand

This commit is contained in:
Mitchell Hashimoto 2010-04-13 16:24:39 -07:00
parent 0a1f2158f7
commit 4674b1983e
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,22 @@
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.
class SSH < Base
Base.subcommand "ssh", self
description "SSH into the currently running environment"
def execute(args=[])
env.require_persisted_vm
env.ssh.connect
end
def options_spec(opts)
opts.banner = "Usage: vagrant ssh"
end
end
end
end

View File

@ -0,0 +1,32 @@
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
class CommandsSSHTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Commands::SSH
@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
@env.ssh.stubs(:connect)
end
should "require a persisted VM" do
@env.expects(:require_persisted_vm).once
@instance.execute
end
should "connect to SSH" do
@env.ssh.expects(:connect).once
@instance.execute
end
end
end