`vagrant ssh` works with multi-VM
This commit is contained in:
parent
81e1e8932a
commit
fd12018114
|
@ -10,8 +10,28 @@ module Vagrant
|
|||
description "SSH into the currently running environment"
|
||||
|
||||
def execute(args=[])
|
||||
env.require_persisted_vm
|
||||
env.vm.ssh.connect
|
||||
args = parse_options(args)
|
||||
ssh_connect(args[0])
|
||||
end
|
||||
|
||||
def ssh_connect(name)
|
||||
if name.nil? && env.multivm?
|
||||
error_and_exit(:ssh_multivm)
|
||||
return # for tests
|
||||
end
|
||||
|
||||
vm = name.nil? ? env.vms.values.first : env.vms[name.to_sym]
|
||||
if vm.nil?
|
||||
error_and_exit(:unknown_vm, :vm => name)
|
||||
return # for tests
|
||||
end
|
||||
|
||||
if !vm.created?
|
||||
error_and_exit(:environment_not_created)
|
||||
return
|
||||
else
|
||||
vm.ssh.connect
|
||||
end
|
||||
end
|
||||
|
||||
def options_spec(opts)
|
||||
|
@ -19,4 +39,4 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -143,6 +143,11 @@
|
|||
For a more detailed guide please consult:
|
||||
|
||||
http://vagrantup.com/docs/getting-started/windows.html
|
||||
:ssh_multivm: |-
|
||||
Because this Vagrant environment represents multiple VMs, a
|
||||
specific VM must be specified. This can be done by calling
|
||||
`vagrant ssh NAME` where NAME is a valid VM represented by
|
||||
your Vagrantfile.
|
||||
:system_invalid_class: |-
|
||||
The specified system does not inherit from `Vagrant::Systems::Base`. The
|
||||
specified system class must inherit from this class.
|
||||
|
|
|
@ -5,28 +5,54 @@ class CommandsSSHTest < Test::Unit::TestCase
|
|||
@klass = Vagrant::Commands::SSH
|
||||
|
||||
@env = mock_environment
|
||||
@env.stubs(:require_persisted_vm)
|
||||
|
||||
@persisted_vm = mock_vm(@env)
|
||||
@persisted_vm.stubs(:execute!)
|
||||
@env.stubs(:vm).returns(@persisted_vm)
|
||||
|
||||
@instance = @klass.new(@env)
|
||||
end
|
||||
|
||||
context "executing" do
|
||||
setup do
|
||||
@persisted_vm.ssh.stubs(:connect)
|
||||
should "connect to the given argument" do
|
||||
@instance.expects(:ssh_connect).with("foo").once
|
||||
@instance.execute(["foo"])
|
||||
end
|
||||
|
||||
should "require a persisted VM" do
|
||||
@env.expects(:require_persisted_vm).once
|
||||
@instance.execute
|
||||
end
|
||||
|
||||
should "connect to SSH" do
|
||||
@persisted_vm.ssh.expects(:connect).once
|
||||
should "connect with nil name if none is given" do
|
||||
@instance.expects(:ssh_connect).with(nil).once
|
||||
@instance.execute
|
||||
end
|
||||
end
|
||||
|
||||
context "ssh connecting" do
|
||||
setup do
|
||||
@vm = mock("vm")
|
||||
@vm.stubs(:created?).returns(true)
|
||||
|
||||
@vms = {:bar => @vm}
|
||||
@env.stubs(:vms).returns(@vms)
|
||||
@env.stubs(:multivm?).returns(false)
|
||||
end
|
||||
|
||||
should "error and exit if no VM is specified and multivm" do
|
||||
@env.stubs(:multivm?).returns(true)
|
||||
@instance.expects(:error_and_exit).with(:ssh_multivm).once
|
||||
@instance.ssh_connect(nil)
|
||||
end
|
||||
|
||||
should "error and exit if VM is nil" do
|
||||
@instance.expects(:error_and_exit).with(:unknown_vm, :vm => :foo).once
|
||||
@instance.ssh_connect(:foo)
|
||||
end
|
||||
|
||||
should "error and exit if VM isn't created" do
|
||||
@vm.stubs(:created?).returns(false)
|
||||
@instance.expects(:error_and_exit).with(:environment_not_created).once
|
||||
@instance.ssh_connect(:bar)
|
||||
end
|
||||
|
||||
should "ssh connect" do
|
||||
ssh = mock("ssh")
|
||||
@vm.stubs(:ssh).returns(ssh)
|
||||
ssh.expects(:connect)
|
||||
|
||||
@instance.ssh_connect(:bar)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|||
|
||||
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
||||
s.authors = ["Mitchell Hashimoto", "John Bender"]
|
||||
s.date = %q{2010-05-16}
|
||||
s.date = %q{2010-05-17}
|
||||
s.default_executable = %q{vagrant}
|
||||
s.description = %q{Vagrant is a tool for building and distributing virtualized development environments.}
|
||||
s.email = ["mitchell.hashimoto@gmail.com", "john.m.bender@gmail.com"]
|
||||
|
|
Loading…
Reference in New Issue