Class: Oxidized::SSH
Defined Under Namespace
Classes: NoShell
Constant Summary collapse
- RESCUE_FAIL =
{ RuntimeError => :warn }.freeze
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Attributes included from Input::CLI
Class Method Summary collapse
Instance Method Summary collapse
- #cmd(cmd, expect = node.prompt) ⇒ Object
-
#connect(node) ⇒ Object
rubocop:disable Naming/PredicateMethod.
- #pty_options(hash) ⇒ Object
- #send(data) ⇒ Object
Methods inherited from SSHBase
#connected?, #make_ssh_opts, #make_ssh_proxy_command, #must_secure?
Methods inherited from Input
config_name, #config_name, to_sym, #to_sym
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.
68 69 70 |
# File 'lib/oxidized/input/ssh.rb', line 68 def output @output end |
Class Method Details
.rescue_fail ⇒ Object
14 15 16 |
# File 'lib/oxidized/input/ssh.rb', line 14 def self.rescue_fail super.merge(RESCUE_FAIL) end |
Instance Method Details
#cmd(cmd, expect = node.prompt) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/oxidized/input/ssh.rb', line 40 def cmd(cmd, expect = node.prompt) unless cmd.is_a?(String) logger.error "cmd must be a String (#{cmd.class}): #{cmd.inspect} @ #{node.name}" raise ArgumentError, "cmd must be a String" end logger.debug "Sending '#{cmd.dump}' @ #{node.name} with expect: #{expect.inspect}" cmd_output = if @exec @yaml_debug&.send_data(cmd) @text_debug&.send_data(cmd) @ssh.exec! cmd else cmd_shell(cmd, expect).gsub("\r\n", "\n") end # only logging @exec as cmd_shell is handled in the ssh loop @yaml_debug&.receive_data(cmd_output) if @exec @text_debug&.receive_data(cmd_output) if @exec # Make sure we return a String cmd_output.to_s end |
#connect(node) ⇒ Object
rubocop:disable Naming/PredicateMethod
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/oxidized/input/ssh.rb', line 18 def connect(node) # rubocop:disable Naming/PredicateMethod @node = node @output = String.new('') @pty_options = { term: "vt100" } @node.model.cfg['ssh'].each { |cb| instance_exec(&cb) } @yaml_debug = DebugYAML.new(Oxidized.config.input.debug, @node, config_name) @text_debug = DebugText.new(Oxidized.config.input.debug, @node, config_name) 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 |
#pty_options(hash) ⇒ Object
70 71 72 |
# File 'lib/oxidized/input/ssh.rb', line 70 def (hash) @pty_options = @pty_options.merge hash end |
#send(data) ⇒ Object
62 63 64 65 66 |
# File 'lib/oxidized/input/ssh.rb', line 62 def send(data) @yaml_debug&.send_data(data) @text_debug&.send_data(data) @ses.send_data data end |