This commit is contained in:
Mitchell Hashimoto 2010-01-31 18:53:35 -08:00
parent 2353ea1f81
commit 3e98fc44e5
4 changed files with 57 additions and 15 deletions

26
bin/hobo-ssh Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env ruby
begin
require File.expand_path(File.join(File.dirname(__FILE__), "../vendor/gems/ruby/1.8/environment"))
rescue LoadError
end
require 'git-style-binary/command'
# Get hobo
hobodir = File.join(File.dirname(__FILE__), '..', 'lib')
$:.unshift(hobodir) unless $:.include?(hobodir)
require 'hobo'
GitStyleBinary.command do
short_desc "opens an SSH connection into the VM"
banner <<-EOS
Usage: #{command.full_name} #{all_options_string}
Opens an SSH connection into the created VM.
EOS
run do |command|
Hobo::VM.ssh
end
end

View File

@ -1,21 +1,14 @@
module Hobo
class SSH
SCRIPT = File.join(File.dirname(__FILE__), '..', '..', 'script', 'hobo-ssh-expect.sh')
def self.connect(opts={})
Kernel.exec "#{SCRIPT} #{uname(opts)} #{pass(opts)} #{host(opts)} #{port(opts)}".strip
end
private
module ClassMethods
private
[:port, :host, :pass, :uname].each do |method|
define_method(method) do |opts|
opts[method] || Hobo.config[:ssh][method]
end
options = {}
[:port, :host, :pass, :uname].each do |param|
options[param] = opts[param] || Hobo.config[:ssh][param]
end
end
extend ClassMethods
Kernel.exec "#{SCRIPT} #{options[:uname]} #{options[:pass]} #{options[:host]} #{options[:port]}".strip
end
end
end

View File

@ -15,6 +15,12 @@ module Hobo
Env.persisted_vm.destroy
end
# SSHs into the VM and replaces the ruby process with the SSH process
def ssh
Env.require_persisted_vm
SSH.connect
end
# Finds a virtual machine by a given UUID and either returns
# a Hobo::VM object or returns nil.
def find(uuid)

View File

@ -4,13 +4,30 @@ class VMTest < Test::Unit::TestCase
setup do
@mock_vm = mock("vm")
Hobo.config!(hobo_mock_config)
@persisted_vm = mock("persisted_vm")
Hobo::Env.stubs(:persisted_vm).returns(@persisted_vm)
end
context "hobo ssh" do
setup do
Hobo::SSH.stubs(:connect)
end
should "require a persisted VM" do
Hobo::Env.expects(:require_persisted_vm).once
Hobo::VM.ssh
end
should "connect to SSH" do
Hobo::SSH.expects(:connect).once
Hobo::VM.ssh
end
end
context "hobo down" do
setup do
@persisted_vm = mock("persisted_vm")
@persisted_vm.stubs(:destroy)
Hobo::Env.stubs(:persisted_vm).returns(@persisted_vm)
end
should "require a persisted VM" do