Class: Oxidized::Model
- Inherits:
-
Object
show all
- Includes:
- Config::Vars
- Defined in:
- lib/oxidized/model/model.rb,
lib/oxidized/model/outputs.rb
Direct Known Subclasses
ACOS, AOS, AOS7, AOSW, ASA, Aireos, Airos, C4CMTS, Catos, CiscoSMB, Comware, Cumulus, DNOS, DataCom, EOS, EdgeSwitch, Edgeos, FTOS, FabricOS, FortiOS, IOS, IOSXR, IPOS, ISAM, IronWare, JunOS, MasterOS, Mtrlrfs, NOS, NXOS, NetScaler, Netonix, OpenGear, PanOS, PowerConnect, Procurve, RouterOS, SAOS, ScreenOS, Supermicro, TMOS, TiMOS, VRP, Vyatta, XOS, ZyNOS
Defined Under Namespace
Classes: Outputs
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#vars
Instance Attribute Details
Returns the value of attribute input.
79
80
81
|
# File 'lib/oxidized/model/model.rb', line 79
def input
@input
end
|
#node ⇒ Object
Returns the value of attribute node.
79
80
81
|
# File 'lib/oxidized/model/model.rb', line 79
def node
@node
end
|
Class Method Details
.cfg(*methods, &block) ⇒ Object
24
25
26
27
28
|
# File 'lib/oxidized/model/model.rb', line 24
def cfg *methods, &block
[methods].flatten.each do |method|
@cfg[method.to_s] << block
end
end
|
.cfgs ⇒ Object
29
30
31
|
# File 'lib/oxidized/model/model.rb', line 29
def cfgs
@cfg
end
|
.cmd(_cmd = nil, &block) ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/oxidized/model/model.rb', line 32
def cmd _cmd=nil, &block
if _cmd.class == Symbol
@cmd[_cmd] << block
else
@cmd[:cmd] << [_cmd, block]
end
end
|
.cmds ⇒ Object
39
40
41
|
# File 'lib/oxidized/model/model.rb', line 39
def cmds
@cmd
end
|
17
18
19
20
|
# File 'lib/oxidized/model/model.rb', line 17
def ='# '
return @comment if @comment
@comment = block_given? ? yield :
end
|
.expect(re, &block) ⇒ Object
42
43
44
|
# File 'lib/oxidized/model/model.rb', line 42
def expect re, &block
@expect << [re, block]
end
|
.expects ⇒ Object
45
46
47
|
# File 'lib/oxidized/model/model.rb', line 45
def expects
@expect
end
|
.inherited(klass) ⇒ Object
9
10
11
12
13
14
15
16
|
# File 'lib/oxidized/model/model.rb', line 9
def inherited klass
klass.instance_variable_set '@cmd', Hash.new { |h,k| h[k] = [] }
klass.instance_variable_set '@cfg', Hash.new { |h,k| h[k] = [] }
klass.instance_variable_set '@procs', Hash.new { |h,k| h[k] = [] }
klass.instance_variable_set '@expect', []
klass.instance_variable_set '@comment', nil
klass.instance_variable_set '@prompt', nil
end
|
.post { ... } ⇒ void
This method returns an undefined value.
calls the block at the end of the model, adding the output of the block to the output string
67
68
69
|
# File 'lib/oxidized/model/model.rb', line 67
def post &block
@procs[:post] << block
end
|
.pre { ... } ⇒ void
This method returns an undefined value.
calls the block at the end of the model, prepending the output of the block to the output string
56
57
58
|
# File 'lib/oxidized/model/model.rb', line 56
def pre &block
@procs[:pre] << block
end
|
.procs ⇒ Hash
Returns hash proc procs :pre+:post to be prepended/postfixed to output.
74
75
76
|
# File 'lib/oxidized/model/model.rb', line 74
def procs
@procs
end
|
.prompt(_prompt = nil) ⇒ Object
21
22
23
|
# File 'lib/oxidized/model/model.rb', line 21
def prompt _prompt=nil
@prompt or @prompt = _prompt
end
|
Instance Method Details
#cfg ⇒ Object
108
109
110
|
# File 'lib/oxidized/model/model.rb', line 108
def cfg
self.class.cfgs
end
|
#cmd(string, &block) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/oxidized/model/model.rb', line 81
def cmd string, &block
out = @input.cmd(string)
return false unless out
self.class.cmds[:all].each do |all_block|
out = instance_exec Oxidized::String.new(out), string, &all_block
end
if vars :remove_secret
self.class.cmds[:secret].each do |all_block|
out = instance_exec Oxidized::String.new(out), string, &all_block
end
end
out = instance_exec Oxidized::String.new(out), &block if block
process_cmd_output out, string
end
|
146
147
148
149
150
151
152
|
# File 'lib/oxidized/model/model.rb', line 146
def
data = ''
.each_line do |line|
data << self.class. << line
end
data
end
|
#expect(re, &block) ⇒ Object
104
105
106
|
# File 'lib/oxidized/model/model.rb', line 104
def expect re, &block
self.class.expect re, &block
end
|
#expects(data) ⇒ Object
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/oxidized/model/model.rb', line 116
def expects data
self.class.expects.each do |re, cb|
if data.match re
if cb.arity == 2
data = instance_exec [data, re], &cb
else
data = instance_exec data, &cb
end
end
end
data
end
|
#get ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
# File 'lib/oxidized/model/model.rb', line 129
def get
outputs = Outputs.new
procs = self.class.procs
self.class.cmds[:cmd].each do |command, block|
out = cmd command, &block
return false unless out
outputs << out
end
procs[:pre].each do |pre_proc|
outputs.unshift process_cmd_output(instance_eval(&pre_proc), '')
end
procs[:post].each do |post_proc|
outputs << process_cmd_output(instance_eval(&post_proc), '')
end
outputs
end
|
#output ⇒ Object
96
97
98
|
# File 'lib/oxidized/model/model.rb', line 96
def output
@input.output
end
|
#prompt ⇒ Object
112
113
114
|
# File 'lib/oxidized/model/model.rb', line 112
def prompt
self.class.prompt
end
|
#send(data) ⇒ Object
100
101
102
|
# File 'lib/oxidized/model/model.rb', line 100
def send data
@input.send data
end
|