Top Level Namespace
Defined Under Namespace
Constant Summary collapse
- PTS_PATH =
'/dev/pts'
- LIBVIRT_USER =
'libvirt-qemu'
- LIBVIRT_GROUP =
'kvm'
Instance Method Summary collapse
-
#execute_when_tcp_available(ip, options = { }, &block) ⇒ Object
see tinyurl.com/3ht46m5.
- #ssh_after_boot(host, options = {}, &block) ⇒ Object
- #ssh_to(host, options = {}, &block) ⇒ Object
Instance Method Details
#execute_when_tcp_available(ip, options = { }, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ssh/port.rb', line 18 def execute_when_tcp_available(ip, = { } , &block) defaults={ :port => 22, :timeout => 2 , :pollrate => 5} =defaults.merge() begin Timeout::timeout([:timeout]) do connected=false while !connected do begin s = TCPSocket.new(ip, [:port]) s.close block.call(ip) return true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError sleep [:pollrate] end end end rescue Timeout::Error raise 'timeout connecting to port' end return false end |
#ssh_after_boot(host, options = {}, &block) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/ssh/port.rb', line 9 def ssh_after_boot(host, = {} , &block) execute_when_tcp_available(host,) do |host| ssh_to(host,) do |ssh| block.call(ssh) end end end |
#ssh_to(host, options = {}, &block) ⇒ Object
3 4 5 6 7 |
# File 'lib/ssh/port.rb', line 3 def ssh_to(host, = {} , &block) Net::SSH.start(host,[:user], ) do|ssh| block.call(ssh) end end |