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')
|
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 = {}
|
||||||
end
|
[:port, :host, :pass, :uname].each do |param|
|
||||||
|
options[param] = opts[param] || Hobo.config[:ssh][param]
|
||||||
private
|
|
||||||
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
|
|
||||||
|
|
||||||
extend ClassMethods
|
Kernel.exec "#{SCRIPT} #{options[:uname]} #{options[:pass]} #{options[:host]} #{options[:port]}".strip
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue