From 4674b1983e5e262c363057c95f9fc6185c5a9f4c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 13 Apr 2010 16:24:39 -0700 Subject: [PATCH] SSH subcommand --- lib/vagrant/commands/ssh.rb | 22 +++++++++++++++++++++ test/vagrant/commands/ssh_test.rb | 32 +++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 lib/vagrant/commands/ssh.rb create mode 100644 test/vagrant/commands/ssh_test.rb diff --git a/lib/vagrant/commands/ssh.rb b/lib/vagrant/commands/ssh.rb new file mode 100644 index 000000000..876e3f0aa --- /dev/null +++ b/lib/vagrant/commands/ssh.rb @@ -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 \ No newline at end of file diff --git a/test/vagrant/commands/ssh_test.rb b/test/vagrant/commands/ssh_test.rb new file mode 100644 index 000000000..ac06ba63e --- /dev/null +++ b/test/vagrant/commands/ssh_test.rb @@ -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