Class: SSHRegistry

Inherits:
Registry show all
Defined in:
lib/smartos-manager/core.rb

Constant Summary

Constants inherited from Registry

Registry::LIST_COLUMNS

Instance Attribute Summary

Attributes inherited from Registry

#user_columns

Instance Method Summary collapse

Methods inherited from Registry

#diag, #find_host, #list_images, #list_vms, #sysinfo

Constructor Details

#initializeSSHRegistry



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'lib/smartos-manager/core.rb', line 307

def initialize(*)
  puts "(( Using live data ))"
  super
  
  @failed_connections = []
  
  @gateways = {}
  @connection = Net::SSH::Multi.start(:on_error => ->(server){
      @failed_connections << server.host
    })
  
  @hosts.each do |_, host|
    @connection.use(host.address,
        via: gateway_for(host.gateway, host.gateway_user),
        user: host.user,
        timeout: 20,
        auth_methods: %w(publickey),
        compression: false
      )
  end
end

Instance Method Details

#failed_connectionsObject



349
350
351
# File 'lib/smartos-manager/core.rb', line 349

def failed_connections
  @failed_connections.map{|address| @hosts[address] }
end

#run_on_all(cmd) ⇒ Object



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/smartos-manager/core.rb', line 329

def run_on_all(cmd)
  ret = {}
  
  # set the keys in cas we get nothing back
  # @hosts.each do |addr, _|
  #   ret[addr] = ""
  # end
  
  channel = @connection.exec(cmd) do |ch, stream, data|
    host = @hosts[ch[:host]]
    ret[host.address] << data
  end
  
  channel.wait()
  
  cache_result(cmd, ret)
  
  ret
end