Module: Expect4r::Router::Ios::Modes
- Included in:
- Ios
- Defined in:
- lib/router/cisco/ios/modes.rb
Instance Method Summary (collapse)
- - (Boolean) _mode_?
- - (Object) config(config = nil, arg = {})
- - (Boolean) config?
- - (Object) exec(cmd = nil, arg = {})
-
- (Boolean) exec?
returns true if router is in :exec (enabled) mode, false otherwise.
-
- (Boolean) in?(mode = :none)
Adds a in? mixin.
- - (Object) to_config
- - (Object) to_exec
- - (Object) to_user
-
- (Boolean) user?
returns true if router is in :user mode, false otherwise.
Instance Method Details
- (Boolean) _mode_?
54 55 56 57 58 59 60 61 62 |
# File 'lib/router/cisco/ios/modes.rb', line 54 def _mode_? if user? :user elsif config? :config elsif exec? :exec end end |
- (Object) config(config = nil, arg = {})
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/router/cisco/ios/modes.rb', line 22 def config(config=nil, arg={}) login unless connected? if config mode = in? change_mode_to :config output = exp_send(config, arg) change_mode_to mode output else change_mode_to :config end end |
- (Boolean) config?
64 65 66 |
# File 'lib/router/cisco/ios/modes.rb', line 64 def config? @lp =~ /\(config(|.+)\)/ end |
- (Object) exec(cmd = nil, arg = {})
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/router/cisco/ios/modes.rb', line 35 def exec(cmd=nil, arg={}) login unless connected? if cmd.nil? change_mode_to :exec else if exec? output = exp_send(cmd, arg) elsif config? output = exp_send("do #{cmd}", arg) else mode = in? change_mode_to :exec output = exp_send(cmd, arg) change_mode_to mode output end end end |
- (Boolean) exec?
returns true if router is in :exec (enabled) mode, false otherwise.
71 72 73 |
# File 'lib/router/cisco/ios/modes.rb', line 71 def exec? ! user? and ! config? end |
- (Boolean) in?(mode = :none)
Adds a in? mixin.
Returns the mode the router is in: :user, :exec, :config
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/router/cisco/ios/modes.rb', line 10 def in?(mode=:none) login unless connected? case mode when :exec ; exec? when :user ; user? when :config ; config? else _mode_? end end |
- (Object) to_config
82 83 84 85 86 87 88 |
# File 'lib/router/cisco/ios/modes.rb', line 82 def to_config return :config if config? to_exec putline 'configure terminal' if exec? raise RuntimeError, "unable to get to config mode" unless config? :config end |
- (Object) to_exec
90 91 92 93 94 95 96 97 |
# File 'lib/router/cisco/ios/modes.rb', line 90 def to_exec return :exec if exec? if config? 1.upto(config_lvl?) { putline 'exit'} end raise RuntimeError, "unable to get to exec mode" unless exec? :exec end |
- (Object) to_user
99 100 101 102 103 104 |
# File 'lib/router/cisco/ios/modes.rb', line 99 def to_user return if user? putline "exit" raise RuntimeError, "unable to get to user mode" unless exec? :user end |
- (Boolean) user?
returns true if router is in :user mode, false otherwise.
78 79 80 |
# File 'lib/router/cisco/ios/modes.rb', line 78 def user? @lp =~ /.+>\s*$/ end |