hobo-ssh
This commit is contained in:
parent
2353ea1f81
commit
3e98fc44e5
|
@ -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
|
|
@ -3,19 +3,12 @@ module Hobo
|
|||
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
|
||||
options = {}
|
||||
[:port, :host, :pass, :uname].each do |param|
|
||||
options[param] = opts[param] || Hobo.config[:ssh][param]
|
||||
end
|
||||
|
||||
private
|
||||
module ClassMethods
|
||||
private
|
||||
[:port, :host, :pass, :uname].each do |method|
|
||||
define_method(method) do |opts|
|
||||
opts[method] || Hobo.config[:ssh][method]
|
||||
Kernel.exec "#{SCRIPT} #{options[:uname]} #{options[:pass]} #{options[:host]} #{options[:port]}".strip
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
extend ClassMethods
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue