Module: Expect4r::Router::Iox::Modes
- Included in:
- Iox
- Defined in:
- lib/router/cisco/iox/modes.rb
Instance Method Summary collapse
-
#config(config = nil, arg = {}) ⇒ Object
Adds an Iox
config
mixin. - #config? ⇒ Boolean
- #exec(cmd = nil, arg = {}) ⇒ Object
- #exec? ⇒ Boolean
- #shell(cmd = nil, arg = {}) ⇒ Object
- #shell? ⇒ Boolean
- #submode? ⇒ Boolean
- #to_config ⇒ Object
- #to_exec ⇒ Object
- #to_shell ⇒ Object
Instance Method Details
#config(config = nil, arg = {}) ⇒ Object
Adds an Iox config
mixin.
Options are:
Option examples:
iox.config %{
interface GigabitEthernet0/2/0/0
desc to switch port 13'
ipv4 address 190.0.0.9 255.255.255.252'
no shut'
}
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/router/cisco/iox/modes.rb', line 19 def config(config=nil, arg={}) login unless connected? if config mode = in? change_mode_to :config output = exp_send(config, arg) output << commit change_mode_to mode output else change_mode_to :config end end |
#config? ⇒ Boolean
71 72 73 |
# File 'lib/router/cisco/iox/modes.rb', line 71 def config? @lp =~ /\(config(|.+)\)/ end |
#exec(cmd = nil, arg = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/router/cisco/iox/modes.rb', line 33 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 |
#exec? ⇒ Boolean
81 82 83 |
# File 'lib/router/cisco/iox/modes.rb', line 81 def exec? ! shell? and ! config? end |
#shell(cmd = nil, arg = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/router/cisco/iox/modes.rb', line 52 def shell(cmd=nil, arg={}) connected = connected? login unless connected? if cmd.nil? to_shell else if shell? output = exp_send(cmd, arg) elsif config? output = exp_send("do run #{cmd}", arg) elsif exec? output = exp_send("run #{cmd}", arg) else raise RuntimeError # TODO end output end end |
#shell? ⇒ Boolean
85 86 87 |
# File 'lib/router/cisco/iox/modes.rb', line 85 def shell? @lp == '# ' end |
#submode? ⇒ Boolean
75 76 77 78 79 |
# File 'lib/router/cisco/iox/modes.rb', line 75 def submode? return '' unless config? @lp =~ /\(config(|.+)\)/ Regexp.last_match(1).split('-')[1..-1].join('-') end |
#to_config ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/router/cisco/iox/modes.rb', line 89 def to_config return :config if config? to_exec putline 'configure' raise RuntimeError, "unable to get to config mode" unless config? :config end |
#to_exec ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/router/cisco/iox/modes.rb', line 105 def to_exec return :exec if exec? putline "exit" if shell? putline "abort" if config? raise RuntimeError, "unable to get to exec mode" unless exec? :exec end |
#to_shell ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/router/cisco/iox/modes.rb', line 97 def to_shell return :shell if shell? to_exec putline 'run' raise RuntimeError, "unable to get to shell mode" unless shell? :shell end |