Class: Oxidized::Model
- Inherits:
-
Object
show all
- Includes:
- Config::Vars, SemanticLogger::Loggable
- Defined in:
- lib/oxidized/model/model.rb,
lib/oxidized/model/outputs.rb
Direct Known Subclasses
ACMEPACKET, ACOS, ACSW, ADVA, AEN, ALTEONOS, AOS, AOS7, AOSW, ARBOS, ASA, AWPlus, AddPack, Adtran, Aireos, Airfiber, Airos, Alvarion, Aoscx, Apc_aos, AricentISS, ArubaInstant, AsterNOS, AsyncOS, AudioCodes, AudioCodesMP, AxOS, BDCOM, BR6910, Boss, C4CMTS, CNOS, Cambium, CambiumePMP, Casa, Catos, CiscoCE, CiscoNGA, CiscoSMA, CiscoSMB, CiscoVPN3k, ComnetMS, Comtrol, Comware, Coriant8600, CoriantGroove, CoriantTmos, Cumulus, DCNOS, DNOS, DataCom, DellX, Dlink, DlinkNextGen, ECIapollo, EFOS, EOS, EatonNetwork, EdgeCOS, EdgeSwitch, Edgeos, Eltex, Enterasys, Enterasys800, Enterprise_SONiC, F5OS, FSOS, FTOS, FabricOS, FastIron, FiberDriver, FireLinuxOS, Firebrick, FirewareOS, FortiOS, FortiWLC, FujitsuPY, GaiaOS, Garderos, GcomBNPS, GrandStream, H3C, HPEBladeSystem, HPMSM, Hatteras, Hios, Hirschmann, HpeMsa, IBOS, IOS, IOSXR, IPOS, ISAM, Icotera, Ingate, IronWare, JunOS, KornfeldOS, LANCOM, LenovoNOS, LinksysSRW, LinuxGeneric, ML66, MLNXOS, MasterOS, Mimosab11, Mtrlrfs, NDMS, NOS, NSXConfig, NSXDfw, NSXFirewall, NXOS, NecIX, NetScaler, Netgear, Netonix, Nodegrid, OS10, OS6, OcNOS, OneFinity, OneOS, OpenGear, OpenWrt, Openbsd, OpnSense, PanOS, PanOS_API, PfSense, Planet, PowerConnect, Procurve, PurityOS, QTECH, QuantaOS, RAISECOM, RGOS, Riverbed, RouterOS, SAOS, SAOS10, SGOS, SLXOS, SROS, SROSMD, ScreenOS, Siklu, SikluMHTG, SixWind, SmartAX, SmartCS, SonicOS, SpeedTouch, StoneOS, SwOS, TDRE, TELCO, TMOS, TNSR, TPLink, Trango, TrueNAS, UCS, UPLINKOLT, Unifiap, VOLTAIRE, VRP, Viptela, Voss, Vyatta, WEOS, XOS, Yamaha, ZTEOLT, ZhoneOLT, Zy1308, ZyNOS, ZyNOSADSL, ZyNOSCLI, ZyNOSGS, ZyNOSMGS
Defined Under Namespace
Classes: Outputs
Class Attribute Summary collapse
-
.procs ⇒ Hash
readonly
Hash proc procs :pre+:post to be prepended/postfixed to output.
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#vars
Class Attribute Details
.procs ⇒ Hash
Returns hash proc procs :pre+:post to be prepended/postfixed to output.
100
101
102
|
# File 'lib/oxidized/model/model.rb', line 100
def procs
@procs
end
|
Instance Attribute Details
Returns the value of attribute input.
119
120
121
|
# File 'lib/oxidized/model/model.rb', line 119
def input
@input
end
|
#node ⇒ Object
Returns the value of attribute node.
119
120
121
|
# File 'lib/oxidized/model/model.rb', line 119
def node
@node
end
|
Class Method Details
.cfg(*methods, **args, &block) ⇒ Object
44
45
46
47
48
|
# File 'lib/oxidized/model/model.rb', line 44
def cfg(*methods, **args, &block)
[methods].flatten.each do |method|
process_args_block(@cfg[method.to_s], args, block)
end
end
|
.cfgs ⇒ Object
50
51
52
|
# File 'lib/oxidized/model/model.rb', line 50
def cfgs
@cfg
end
|
.cmd(cmd_arg = nil, **args, &block) ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/oxidized/model/model.rb', line 54
def cmd(cmd_arg = nil, **args, &block)
if cmd_arg.instance_of?(Symbol)
process_args_block(@cmd[cmd_arg], args, block)
else
process_args_block(@cmd[:cmd], args, [cmd_arg, block])
end
logger.debug "Added #{cmd_arg} to the commands list"
end
|
.cmds ⇒ Object
63
64
65
|
# File 'lib/oxidized/model/model.rb', line 63
def cmds
@cmd
end
|
30
31
32
33
34
35
36
37
38
|
# File 'lib/oxidized/model/model.rb', line 30
def (str = "# ")
@comment = if block_given?
yield
elsif not @comment
str
else
@comment
end
end
|
.expect(regex, **args, &block) ⇒ Object
67
68
69
|
# File 'lib/oxidized/model/model.rb', line 67
def expect(regex, **args, &block)
process_args_block(@expect, args, [regex, block])
end
|
.expects ⇒ Object
71
72
73
|
# File 'lib/oxidized/model/model.rb', line 71
def expects
@expect
end
|
.inherited(klass) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/oxidized/model/model.rb', line 12
def inherited(klass)
super
if klass.superclass == Oxidized::Model
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
else instance_variables.each do |var|
iv = instance_variable_get(var)
klass.instance_variable_set var, iv.dup
@cmd[:cmd] = iv[:cmd].dup if var.to_s == "@cmd"
end
end
end
|
.post(**args) { ... } ⇒ 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
93
94
95
|
# File 'lib/oxidized/model/model.rb', line 93
def post(**args, &block)
process_args_block(@procs[:post], args, block)
end
|
.pre(**args) { ... } ⇒ 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
82
83
84
|
# File 'lib/oxidized/model/model.rb', line 82
def pre(**args, &block)
process_args_block(@procs[:pre], args, block)
end
|
.prompt(regex = nil) ⇒ Object
40
41
42
|
# File 'lib/oxidized/model/model.rb', line 40
def prompt(regex = nil)
@prompt = regex || @prompt
end
|
Instance Method Details
#cfg ⇒ Object
151
152
153
|
# File 'lib/oxidized/model/model.rb', line 151
def cfg
self.class.cfgs
end
|
#cmd(string, &block) ⇒ Object
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/oxidized/model/model.rb', line 121
def cmd(string, &block)
logger.debug "Executing #{string}"
out = @input.cmd(string)
return false unless out
out = out.b unless Oxidized.config.input.utf8_encoded?
self.class.cmds[:all].each do |all_block|
out = instance_exec out, string, &all_block
end
if vars :remove_secret
self.class.cmds[:secret].each do |all_block|
out = instance_exec out, string, &all_block
end
end
out = instance_exec out, &block if block
process_cmd_output out, string
end
|
187
188
189
190
191
192
193
|
# File 'lib/oxidized/model/model.rb', line 187
def (str)
data = String.new('')
str.each_line do |line|
data << self.class. << line
end
data
end
|
#expect ⇒ Object
147
148
149
|
# File 'lib/oxidized/model/model.rb', line 147
def expect(...)
self.class.expect(...)
end
|
#expects(data) ⇒ Object
159
160
161
162
163
164
165
166
|
# File 'lib/oxidized/model/model.rb', line 159
def expects(data)
self.class.expects.each do |re, cb|
if data.match re
data = cb.arity == 2 ? instance_exec([data, re], &cb) : instance_exec(data, &cb)
end
end
data
end
|
#get ⇒ Object
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
# File 'lib/oxidized/model/model.rb', line 168
def get
logger.debug 'Collecting commands\' outputs'
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
139
140
141
|
# File 'lib/oxidized/model/model.rb', line 139
def output
@input.output
end
|
#prompt ⇒ Object
155
156
157
|
# File 'lib/oxidized/model/model.rb', line 155
def prompt
self.class.prompt
end
|
#screenscrape ⇒ Object
213
214
215
|
# File 'lib/oxidized/model/model.rb', line 213
def screenscrape
@input.class.to_s.match(/Telnet/) || vars(:ssh_no_exec)
end
|
#send(data) ⇒ Object
143
144
145
|
# File 'lib/oxidized/model/model.rb', line 143
def send(data)
@input.send data
end
|
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
# File 'lib/oxidized/model/model.rb', line 195
def (str)
data = String.new('')
str.each_line do |_line|
data << '<!-- ' << str.gsub(/-(?=-)/, '- ').chomp << " -->\n"
end
data
end
|