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
- #newline(newline_str = "\n") ⇒ 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 29 |
# File 'lib/oxidized/input/cli.rb', line 22 def connect_cli logger.debug "Running post_login commands at #{node.name}" @post_login.each do |command, block| logger.debug "Running post_login command: #{command.inspect}, " \ "block: #{block.inspect} at #{node.name}" block ? block.call : (cmd command) end end |
#disconnect_cli ⇒ Object
31 32 33 34 |
# File 'lib/oxidized/input/cli.rb', line 31 def disconnect_cli logger.debug "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
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/oxidized/input/cli.rb', line 60 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 |
#newline(newline_str = "\n") ⇒ Object
56 57 58 |
# File 'lib/oxidized/input/cli.rb', line 56 def newline(newline_str = "\n") @newline || (@newline = newline_str) end |
#password(regex = /^Password/) ⇒ Object
52 53 54 |
# File 'lib/oxidized/input/cli.rb', line 52 def password(regex = /^Password/) @password || (@password = regex) end |
#post_login(cmd = nil, &block) ⇒ Object
36 37 38 39 40 |
# File 'lib/oxidized/input/cli.rb', line 36 def post_login(cmd = nil, &block) return if @exec @post_login << [cmd, block] end |
#pre_logout(cmd = nil, &block) ⇒ Object
42 43 44 45 46 |
# File 'lib/oxidized/input/cli.rb', line 42 def pre_logout(cmd = nil, &block) return if @exec @pre_logout << [cmd, block] end |
#username(regex = /^(Username|login)/) ⇒ Object
48 49 50 |
# File 'lib/oxidized/input/cli.rb', line 48 def username(regex = /^(Username|login)/) @username || (@username = regex) end |