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, ACSW, AEN, ALTEONOS, AOS, AOS7, AOSW, ARBOS, ASA, AWPlus, Adtran, Aireos, Airfiber, Airos, Alvarion, Apc_aos, AricentISS, AsyncOS, AudioCodes, AudioCodesMP, AxOS, BR6910, Boss, C4CMTS, CNOS, Cambium, Casa, Catos, CiscoNGA, CiscoSMA, CiscoSMB, CiscoVPN3k, ComnetMS, Comtrol, Comware, Coriant8600, CoriantGroove, CoriantTmos, Cumulus, DCNOS, DNOS, DataCom, DellX, Dlink, ECIapollo, EOS, EdgeCOS, EdgeSwitch, Edgeos, Enterasys, FTOS, FabricOS, FastIron, FiberDriver, FireLinuxOS, Firebrick, FirewareOS, FortiOS, FujitsuPY, GaiaOS, GcomBNPS, GrandStream, HPEBladeSystem, HPMSM, Hatteras, Hirschmann, HpeMsa, IBOS, IOS, IOSXR, IPOS, ISAM, Icotera, IronWare, JunOS, LinuxGeneric, MLNXOS, MasterOS, Mtrlrfs, NDMS, NOS, NSXConfig, NSXFirewall, NXOS, NetScaler, Netgear, Netonix, OS10, OneOS, OpenGear, OpenWrt, Openbsd, OpnSense, PanOS, PfSense, Planet, PowerConnect, Procurve, PurityOS, QTECH, QuantaOS, RAISECOM, RouterOS, SAOS, SGOS, SLXOS, SROS, ScreenOS, Siklu, SmartAX, SonicOS, SpeedTouch, StoneOS, TDRE, TELCO, TMOS, TPLink, Trango, UCS, VOLTAIRE, VRP, Viptela, Voss, Vyatta, WEOS, XOS, ZhoneOLT, ZyNOS, ZyNOSCLI, ZyNOSGS
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.
94
95
96
|
# File 'lib/oxidized/model/model.rb', line 94
def procs
@procs
end
|
Instance Attribute Details
Returns the value of attribute input.
108
109
110
|
# File 'lib/oxidized/model/model.rb', line 108
def input
@input
end
|
#node ⇒ Object
Returns the value of attribute node.
108
109
110
|
# File 'lib/oxidized/model/model.rb', line 108
def node
@node
end
|
Class Method Details
.cfg(*methods, **args, &block) ⇒ Object
38
39
40
41
42
|
# File 'lib/oxidized/model/model.rb', line 38
def cfg(*methods, **args, &block)
[methods].flatten.each do |method|
process_args_block(@cfg[method.to_s], args, block)
end
end
|
.cfgs ⇒ Object
44
45
46
|
# File 'lib/oxidized/model/model.rb', line 44
def cfgs
@cfg
end
|
.cmd(cmd_arg = nil, **args, &block) ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/oxidized/model/model.rb', line 48
def cmd(cmd_arg = nil, **args, &block)
if cmd_arg.class == Symbol
process_args_block(@cmd[cmd_arg], args, block)
else
process_args_block(@cmd[:cmd], args, [cmd_arg, block])
end
Oxidized.logger.debug "lib/oxidized/model/model.rb Added #{cmd_arg} to the commands list"
end
|
.cmds ⇒ Object
57
58
59
|
# File 'lib/oxidized/model/model.rb', line 57
def cmds
@cmd
end
|
24
25
26
27
28
29
30
31
32
|
# File 'lib/oxidized/model/model.rb', line 24
def (str = "# ")
@comment = if block_given?
yield
elsif not @comment
str
else
@comment
end
end
|
.expect(regex, **args, &block) ⇒ Object
61
62
63
|
# File 'lib/oxidized/model/model.rb', line 61
def expect(regex, **args, &block)
process_args_block(@expect, args, [regex, block])
end
|
.expects ⇒ Object
65
66
67
|
# File 'lib/oxidized/model/model.rb', line 65
def expects
@expect
end
|
.inherited(klass) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/oxidized/model/model.rb', line 9
def inherited(klass)
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|
klass.instance_variable_set var, instance_variable_get(var)
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
87
88
89
|
# File 'lib/oxidized/model/model.rb', line 87
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
76
77
78
|
# File 'lib/oxidized/model/model.rb', line 76
def pre(**args, &block)
process_args_block(@procs[:pre], args, block)
end
|
.prompt(regex = nil) ⇒ Object
34
35
36
|
# File 'lib/oxidized/model/model.rb', line 34
def prompt(regex = nil)
@prompt = regex || @prompt
end
|
Instance Method Details
#cfg ⇒ Object
140
141
142
|
# File 'lib/oxidized/model/model.rb', line 140
def cfg
self.class.cfgs
end
|
#cmd(string, &block) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/oxidized/model/model.rb', line 110
def cmd(string, &block)
Oxidized.logger.debug "lib/oxidized/model/model.rb 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 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
|
176
177
178
179
180
181
182
|
# File 'lib/oxidized/model/model.rb', line 176
def (str)
data = ''
str.each_line do |line|
data << self.class. << line
end
data
end
|
#expect(regex, &block) ⇒ Object
136
137
138
|
# File 'lib/oxidized/model/model.rb', line 136
def expect(regex, &block)
self.class.expect regex, &block
end
|
#expects(data) ⇒ Object
148
149
150
151
152
153
154
155
|
# File 'lib/oxidized/model/model.rb', line 148
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/oxidized/model/model.rb', line 157
def get
Oxidized.logger.debug 'lib/oxidized/model/model.rb 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
128
129
130
|
# File 'lib/oxidized/model/model.rb', line 128
def output
@input.output
end
|
#prompt ⇒ Object
144
145
146
|
# File 'lib/oxidized/model/model.rb', line 144
def prompt
self.class.prompt
end
|
#screenscrape ⇒ Object
184
185
186
|
# File 'lib/oxidized/model/model.rb', line 184
def screenscrape
@input.class.to_s.match(/Telnet/) || vars(:ssh_no_exec)
end
|
#send(data) ⇒ Object
132
133
134
|
# File 'lib/oxidized/model/model.rb', line 132
def send(data)
@input.send data
end
|