Module: SystemConnect
- Included in:
- Netid
- Defined in:
- lib/system-connect.rb
Instance Method Summary collapse
-
#connect(host, user) ⇒ Object
def initialize_ssh_connections connections = [] systems.each do |host| puts “Attempting connection for #system_user@#host” connections << SystemSSH.new(host,connect(host, system_user)) puts “Connection successful for #host” end @connections = connections end.
- #find_connection_for_host(host) ⇒ Object
- #lazy_load_connection_for_host(host) ⇒ Object
- #loop ⇒ Object
- #run_remote_command(command, host) ⇒ Object
Instance Method Details
#connect(host, user) ⇒ Object
def initialize_ssh_connections
connections = []
systems.each do |host|
puts "Attempting connection for #{system_user}@#{host}"
connections << SystemSSH.new(host,connect(host, system_user))
puts "Connection successful for #{host}"
end
@connections = connections
end
13 14 15 |
# File 'lib/system-connect.rb', line 13 def connect(host,user) Net::SSH.start(host,user,{auth_methods: %w(publickey)}) end |
#find_connection_for_host(host) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/system-connect.rb', line 35 def find_connection_for_host(host) @connections ||= [] unless @connections.select{ |conn| conn.hostname == host}.empty? @connections.select{ |conn| conn.hostname == host}.first.connection_object else lazy_load_connection_for_host(host) find_connection_for_host(host) end end |
#lazy_load_connection_for_host(host) ⇒ Object
45 46 47 |
# File 'lib/system-connect.rb', line 45 def lazy_load_connection_for_host(host) @connections << SystemSSH.new(host,connect(host,system_user)) end |
#loop ⇒ Object
31 32 33 |
# File 'lib/system-connect.rb', line 31 def loop connection.loop end |
#run_remote_command(command, host) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/system-connect.rb', line 17 def run_remote_command(command, host) connection = find_connection_for_host(host) connection.exec!(command) # if connection # connection.exec(command) do |ch, stream, data| # unless stream == :stderr # puts data # end # end # else # puts "No connection found for host: #{host}" # end end |