Class: SshClass

Inherits:
Object
  • Object
show all
Defined in:
lib/miq_utilities/ssh.rb

Overview

This wrapper class is used to run ssh commands on linux machines

Instance Method Summary collapse

Instance Method Details

#ssh_run(script, ipaddr, linux_user = nil, linux_password = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/miq_utilities/ssh.rb', line 16

def ssh_run(script, ipaddr, linux_user = nil, linux_password = nil)
  @logger = LoggingClass.new("#{self.class}:(#{__method__})")
  linux_user ||= 'root'
  linux_password ||= $evm.object.decrypt('linux_password').to_s
  begin
    Net::SSH.start(ipaddr, linux_user, password: linux_password, paranoid: Net::SSH::Verifiers::Null.new) do |ssh|
      command = script
      output = ssh.exec!(command)
      @logger.log(level: 'info', message: "ssh command being run on #{ipaddr}")
      @logger.log(level: 'info', message: "ssh script being run is #{script}")
      @logger.log(level: 'info', message: "SSH output = #{output}")
    end
  rescue => err
    raise("\n    Class:<#{self.class}>\n    Method:<#{__method__}>\n    Error:<#{err} - #{err.backtrace.join("\n")}>")
  end
end