Module: Oxidized::Input::CLI
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #connect_cli ⇒ Object
- #disconnect_cli ⇒ Object
- #get ⇒ Object
- #initialize ⇒ Object
- #login ⇒ Object
- #password(regex = /^Password/) ⇒ Object
- #post_login(cmd = nil, &block) ⇒ Object
- #pre_logout(cmd = nil, &block) ⇒ Object
- #username(regex = /^(Username|login)/) ⇒ Object
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
4 5 6 |
# File 'lib/oxidized/input/cli.rb', line 4 def node @node end |
Instance Method Details
#connect_cli ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/oxidized/input/cli.rb', line 22 def connect_cli Oxidized.logger.debug "lib/oxidized/input/cli.rb: Running post_login commands at #{node.name}" @post_login.each do |command, block| Oxidized.logger.debug "lib/oxidized/input/cli.rb: Running post_login command: #{command.inspect}, block: #{block.inspect} at #{node.name}" block ? block.call : (cmd command) end end |
#disconnect_cli ⇒ Object
30 31 32 33 |
# File 'lib/oxidized/input/cli.rb', line 30 def disconnect_cli Oxidized.logger.debug "lib/oxidized/input/cli.rb Running pre_logout commands at #{node.name}" @pre_logout.each { |command, block| block ? block.call : (cmd command, nil) } end |
#get ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/oxidized/input/cli.rb', line 12 def get connect_cli d = node.model.get disconnect d rescue PromptUndetect disconnect raise end |
#initialize ⇒ Object
6 7 8 9 10 |
# File 'lib/oxidized/input/cli.rb', line 6 def initialize @post_login = [] @pre_logout = [] @username, @password, @exec = nil end |
#login ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/oxidized/input/cli.rb', line 55 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 |
#password(regex = /^Password/) ⇒ Object
51 52 53 |
# File 'lib/oxidized/input/cli.rb', line 51 def password(regex = /^Password/) @password || (@password = regex) end |
#post_login(cmd = nil, &block) ⇒ Object
35 36 37 38 39 |
# File 'lib/oxidized/input/cli.rb', line 35 def post_login(cmd = nil, &block) return if @exec @post_login << [cmd, block] end |
#pre_logout(cmd = nil, &block) ⇒ Object
41 42 43 44 45 |
# File 'lib/oxidized/input/cli.rb', line 41 def pre_logout(cmd = nil, &block) return if @exec @pre_logout << [cmd, block] end |
#username(regex = /^(Username|login)/) ⇒ Object
47 48 49 |
# File 'lib/oxidized/input/cli.rb', line 47 def username(regex = /^(Username|login)/) @username || (@username = regex) end |