Class: Oxidized::SSH
- Includes:
- Input::CLI
- Defined in:
- lib/oxidized/input/ssh.rb
Defined Under Namespace
Classes: NoShell
Constant Summary collapse
- RESCUE_FAIL =
{ debug: [ Net::SSH::Disconnect ], warn: [ RuntimeError, Net::SSH::AuthenticationFailed ] }.freeze
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Attributes included from Input::CLI
Instance Method Summary collapse
- #cmd(cmd, expect = node.prompt) ⇒ Object
-
#connect(node) ⇒ Object
rubocop:disable Naming/PredicateMethod.
- #connected? ⇒ Boolean
- #pty_options(hash) ⇒ Object
- #send(data) ⇒ Object
Methods included from Input::CLI
#connect_cli, #disconnect_cli, #get, #initialize, #login, #newline, #password, #post_login, #pre_logout, #username
Methods included from Config::Vars
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
71 72 73 |
# File 'lib/oxidized/input/ssh.rb', line 71 def output @output end |
Instance Method Details
#cmd(cmd, expect = node.prompt) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/oxidized/input/ssh.rb', line 48 def cmd(cmd, expect = node.prompt) logger.debug "Sending '#{cmd.dump}' @ #{node.name} with expect: #{expect.inspect}" if Oxidized.config.input.debug? @log.puts "sent cmd #{@exec ? cmd.dump : (cmd + newline).dump}" @log.flush end cmd_output = if @exec @ssh.exec! cmd else cmd_shell(cmd, expect).gsub("\r\n", "\n") end # Make sure we return a String cmd_output.to_s end |
#connect(node) ⇒ Object
rubocop:disable Naming/PredicateMethod
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/oxidized/input/ssh.rb', line 20 def connect(node) # rubocop:disable Naming/PredicateMethod @node = node @output = String.new('') = { term: "vt100" } @node.model.cfg['ssh'].each { |cb| instance_exec(&cb) } if Oxidized.config.input.debug? logfile = Oxidized::Config::LOG + "/#{@node.ip}-ssh" @log = File.open(logfile, 'w') logger.debug "I/O Debuging to #{logfile}" end logger.debug "Connecting to #{@node.name}" @ssh = Net::SSH.start(@node.ip, @node.auth[:username], make_ssh_opts) unless @exec shell_open @ssh begin login rescue Timeout::Error raise PromptUndetect, [@output, 'not matching configured prompt', @node.prompt].join(' ') end end connected? end |
#connected? ⇒ Boolean
44 45 46 |
# File 'lib/oxidized/input/ssh.rb', line 44 def connected? @ssh && (not @ssh.closed?) end |
#pty_options(hash) ⇒ Object
73 74 75 |
# File 'lib/oxidized/input/ssh.rb', line 73 def (hash) = .merge hash end |
#send(data) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/oxidized/input/ssh.rb', line 63 def send(data) if Oxidized.config.input.debug? @log.puts "sent data #{data.dump}" @log.flush end @ses.send_data data end |