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

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

View File

@ -15,6 +15,12 @@ module Hobo
Env.persisted_vm.destroy Env.persisted_vm.destroy
end 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 # Finds a virtual machine by a given UUID and either returns
# a Hobo::VM object or returns nil. # a Hobo::VM object or returns nil.
def find(uuid) def find(uuid)

View File

@ -4,13 +4,30 @@ class VMTest < Test::Unit::TestCase
setup do setup do
@mock_vm = mock("vm") @mock_vm = mock("vm")
Hobo.config!(hobo_mock_config) 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 end
context "hobo down" do context "hobo down" do
setup do setup do
@persisted_vm = mock("persisted_vm")
@persisted_vm.stubs(:destroy) @persisted_vm.stubs(:destroy)
Hobo::Env.stubs(:persisted_vm).returns(@persisted_vm)
end end
should "require a persisted VM" do should "require a persisted VM" do