vagrant/lib/hobo/ssh.rb

32 lines
1.0 KiB
Ruby
Raw Normal View History

2010-01-26 08:01:17 +00:00
module Hobo
class SSH
SCRIPT = File.join(File.dirname(__FILE__), '..', '..', 'script', 'hobo-ssh-expect.sh')
2010-01-26 08:01:17 +00:00
class << self
2010-02-01 06:23:19 +00:00
def connect(opts={})
options = {}
[:host, :pass, :uname].each do |param|
2010-02-02 06:14:40 +00:00
options[param] = opts[param] || Hobo.config.ssh.send(param)
2010-02-01 06:23:19 +00:00
end
# The port is special
options[:port] = opts[:port] || Hobo.config.vm.forwarded_ports[Hobo.config.ssh.forwarded_port_key][:hostport]
2010-02-01 06:23:19 +00:00
Kernel.exec "#{SCRIPT} #{options[:uname]} #{options[:pass]} #{options[:host]} #{options[:port]}".strip
2010-01-26 08:01:17 +00:00
end
2010-02-01 06:23:19 +00:00
def execute
port = Hobo.config.vm.forwarded_ports[Hobo.config.ssh.forwarded_port_key][:hostport]
Net::SSH.start("localhost", Hobo.config[:ssh][:uname], :port => port, :password => Hobo.config[:ssh][:pass]) do |ssh|
2010-02-01 06:23:19 +00:00
yield ssh
end
end
def up?
port = Hobo.config.vm.forwarded_ports[Hobo.config.ssh.forwarded_port_key][:hostport]
Ping.pingecho "localhost", 1, port
end
2010-02-01 02:53:35 +00:00
end
2010-01-26 08:01:17 +00:00
end
end