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, Aireos, Airos, Alvarion, Apc_aos, AricentISS, AsyncOS, AudioCodes, BR6910, Boss, C4CMTS, Cambium, Casa, Catos, CiscoNGA, CiscoSMA, CiscoSMB, ComnetMS, Comware, Coriant8600, CoriantGroove, CoriantTmos, Cumulus, DCNOS, DNOS, DataCom, Dlink, EOS, EdgeCOS, EdgeSwitch, Edgeos, Enterasys, FTOS, FabricOS, FiberDriver, FirewareOS, FortiOS, FujitsuPY, GaiaOS, GcomBNPS, HPEBladeSystem, Hatteras, Hirschmann, HpeMsa, IOS, IOSXR, IPOS, ISAM, IronWare, JunOS, MLNXOS, MasterOS, Mtrlrfs, NDMS, NOS, NXOS, NetScaler, Netgear, Netonix, OneOS, OpenGear, OpenWrt, Openbsd, OpnSense, PanOS, PfSense, Planet, PowerConnect, Procurve, QuantaOS, RouterOS, SAOS, SGOS, SLXOS, SROS, ScreenOS, Siklu, StoneOS, TMOS, TPLink, Trango, UCS, VOLTAIRE, VRP, Voss, Vyatta, WEOS, XOS, ZhoneOLT, ZyNOS, ZyNOSCLI
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.
88
89
90
|
# File 'lib/oxidized/model/model.rb', line 88
def input
@input
end
|
#node ⇒ Object
Returns the value of attribute node.
88
89
90
|
# File 'lib/oxidized/model/model.rb', line 88
def node
@node
end
|
Class Method Details
.cfg(*methods, &block) ⇒ Object
27
28
29
30
31
|
# File 'lib/oxidized/model/model.rb', line 27
def cfg *methods, &block
[methods].flatten.each do |method|
@cfg[method.to_s] << block
end
end
|
.cfgs ⇒ Object
33
34
35
|
# File 'lib/oxidized/model/model.rb', line 33
def cfgs
@cfg
end
|
.cmd(_cmd = nil, &block) ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/oxidized/model/model.rb', line 37
def cmd _cmd = nil, &block
if _cmd.class == Symbol
@cmd[_cmd] << block
else
@cmd[:cmd] << [_cmd, block]
end
Oxidized.logger.debug "lib/oxidized/model/model.rb Added #{_cmd} to the commands list"
end
|
.cmds ⇒ Object
46
47
48
|
# File 'lib/oxidized/model/model.rb', line 46
def cmds
@cmd
end
|
18
19
20
21
|
# File 'lib/oxidized/model/model.rb', line 18
def = '# '
return @comment if @comment
@comment = block_given? ? yield :
end
|
.expect(re, &block) ⇒ Object
50
51
52
|
# File 'lib/oxidized/model/model.rb', line 50
def expect re, &block
@expect << [re, block]
end
|
.expects ⇒ Object
54
55
56
|
# File 'lib/oxidized/model/model.rb', line 54
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
76
77
78
|
# File 'lib/oxidized/model/model.rb', line 76
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
65
66
67
|
# File 'lib/oxidized/model/model.rb', line 65
def pre &block
@procs[:pre] << block
end
|
.procs ⇒ Hash
Returns hash proc procs :pre+:post to be prepended/postfixed to output.
83
84
85
|
# File 'lib/oxidized/model/model.rb', line 83
def procs
@procs
end
|
.prompt(_prompt = nil) ⇒ Object
23
24
25
|
# File 'lib/oxidized/model/model.rb', line 23
def prompt _prompt = nil
@prompt or @prompt = _prompt
end
|
Instance Method Details
#cfg ⇒ Object
119
120
121
|
# File 'lib/oxidized/model/model.rb', line 119
def cfg
self.class.cfgs
end
|
#cmd(string, &block) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/oxidized/model/model.rb', line 90
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
|
158
159
160
161
162
163
164
|
# File 'lib/oxidized/model/model.rb', line 158
def
data = ''
.each_line do |line|
data << self.class. << line
end
data
end
|
#expect(re, &block) ⇒ Object
115
116
117
|
# File 'lib/oxidized/model/model.rb', line 115
def expect re, &block
self.class.expect re, &block
end
|
#expects(data) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'lib/oxidized/model/model.rb', line 127
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/oxidized/model/model.rb', line 140
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
107
108
109
|
# File 'lib/oxidized/model/model.rb', line 107
def output
@input.output
end
|
#prompt ⇒ Object
123
124
125
|
# File 'lib/oxidized/model/model.rb', line 123
def prompt
self.class.prompt
end
|
#screenscrape ⇒ Object
166
167
168
|
# File 'lib/oxidized/model/model.rb', line 166
def screenscrape
@input.class.to_s.match(/Telnet/) || vars(:ssh_no_exec)
end
|
#send(data) ⇒ Object
111
112
113
|
# File 'lib/oxidized/model/model.rb', line 111
def send data
@input.send data
end
|