Top Level Namespace

Defined Under Namespace

Modules: Console, Puppet

Constant Summary collapse

PTS_PATH =
'/dev/pts'
LIBVIRT_USER =
'libvirt-qemu'
LIBVIRT_GROUP =
'kvm'

Instance Method Summary collapse

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, options = { } , &block)
    defaults={ :port => 22, :timeout => 2 , :pollrate => 5}
    options=defaults.merge(options)
    begin
	  Timeout::timeout(options[:timeout]) do
		connected=false
		while !connected do
		    begin
			  s = TCPSocket.new(ip, options[:port])
			  s.close
			  block.call(ip)
			  return true
		    rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, SocketError
			  sleep options[: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, options = {} , &block)
    execute_when_tcp_available(host,options) do |host|
	  ssh_to(host,options) 	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, options = {} , &block)
    Net::SSH.start(host,options[:user], options) do|ssh|
	  block.call(ssh)
    end   
end