summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2018-06-04 13:21:00 +0300
committerSaku Ytti <saku@ytti.fi>2018-06-07 10:17:56 +0300
commit194b6893bde341c4fc3ba4c8041d9a6b6775a97d (patch)
treeea4bf7b2c4fdff9d8d36b77fff3000a010253eca
parentea181e93f90ada5d74921cab7ba89e308b9ea1e3 (diff)
make login username/passord detection generic
-rw-r--r--lib/oxidized/input/cli.rb11
-rw-r--r--lib/oxidized/input/ssh.rb13
-rw-r--r--lib/oxidized/input/telnet.rb8
3 files changed, 12 insertions, 20 deletions
diff --git a/lib/oxidized/input/cli.rb b/lib/oxidized/input/cli.rb
index d434e33..5ebfc50 100644
--- a/lib/oxidized/input/cli.rb
+++ b/lib/oxidized/input/cli.rb
@@ -51,6 +51,17 @@ module Oxidized
def password re = /^Password/
@password or @password = re
end
+
+ def login
+ match_re = [@node.prompt]
+ match_re << @username if @username
+ match_re << @password if @password
+ until (match = expect(match_re)) == @node.prompt
+ cmd(@node.auth[:username], nil) if match == @username
+ cmd(@node.auth[:password], nil) if match == @password
+ match_re.delete match
+ end
+ end
end
end
end
diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb
index 780bdf2..d321a11 100644
--- a/lib/oxidized/input/ssh.rb
+++ b/lib/oxidized/input/ssh.rb
@@ -118,19 +118,6 @@ module Oxidized
end
end
- # some models have SSH auth or terminal auth based on version of code
- # if SSH is configured for terminal auth, we'll still try to detect prompt
- def login
- match_re = [@node.prompt]
- match_re << @username if @username
- match_re << @password if @password
- until (match = expect(match_re)) == @node.prompt
- cmd(@node.auth[:username], nil) if match == @username
- cmd(@node.auth[:password], nil) if match == @password
- match_re.delete match
- end
- end
-
def exec state = nil
state == nil ? @exec : (@exec = state) unless vars :ssh_no_exec
end
diff --git a/lib/oxidized/input/telnet.rb b/lib/oxidized/input/telnet.rb
index 4b9a656..102bc8c 100644
--- a/lib/oxidized/input/telnet.rb
+++ b/lib/oxidized/input/telnet.rb
@@ -20,14 +20,8 @@ module Oxidized
'Log' => @log }
@telnet = Net::Telnet.new telnet_opts
- if @node.auth[:username] and @node.auth[:username].length > 0
- expect username
- @telnet.puts @node.auth[:username]
- end
- expect password
- @telnet.puts @node.auth[:password]
begin
- expect @node.prompt
+ login
rescue Timeout::Error
raise PromptUndetect, ['unable to detect prompt:', @node.prompt].join(' ')
end