junos-ez-stdlib 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +26 -0
- data/README.md +181 -0
- data/docs/Config_Utils.md +3 -0
- data/docs/Facts.md +106 -0
- data/docs/Filesys_Utils.md +3 -0
- data/docs/IPports.md +3 -0
- data/docs/L1ports.md +3 -0
- data/docs/L2ports.md +3 -0
- data/docs/Providers_Resources.md +304 -0
- data/docs/RE_utils.md +3 -0
- data/docs/StaticHosts.md +3 -0
- data/docs/StaticRoutes.md +3 -0
- data/docs/Vlans.md +3 -0
- data/examples/config/config_file.rb +72 -0
- data/examples/config/config_template_object.rb +81 -0
- data/examples/config/config_template_simple.rb +76 -0
- data/examples/config/multi_config.rb +60 -0
- data/examples/fs_utils.rb +31 -0
- data/examples/re_upgrade.rb +90 -0
- data/examples/re_utils.rb +30 -0
- data/examples/simple.rb +47 -0
- data/examples/st_hosts.rb +33 -0
- data/examples/vlans.rb +25 -0
- data/junos-ez-stdlib.gemspec +15 -0
- data/lib/junos-ez/facts/chassis.rb +45 -0
- data/lib/junos-ez/facts/ifd_style.rb +14 -0
- data/lib/junos-ez/facts/personality.rb +22 -0
- data/lib/junos-ez/facts/switch_style.rb +22 -0
- data/lib/junos-ez/facts/version.rb +32 -0
- data/lib/junos-ez/facts.rb +85 -0
- data/lib/junos-ez/ip_ports/classic.rb +149 -0
- data/lib/junos-ez/ip_ports.rb +28 -0
- data/lib/junos-ez/l1_ports/classic.rb +87 -0
- data/lib/junos-ez/l1_ports/switch.rb +134 -0
- data/lib/junos-ez/l1_ports.rb +81 -0
- data/lib/junos-ez/l2_ports/bridge_domain.rb +0 -0
- data/lib/junos-ez/l2_ports/vlan.rb +317 -0
- data/lib/junos-ez/l2_ports/vlan_l2ng.rb +0 -0
- data/lib/junos-ez/l2_ports.rb +57 -0
- data/lib/junos-ez/provider.rb +608 -0
- data/lib/junos-ez/stdlib.rb +16 -0
- data/lib/junos-ez/system/st_hosts.rb +74 -0
- data/lib/junos-ez/system/st_routes.rb +135 -0
- data/lib/junos-ez/system/syscfg.rb +103 -0
- data/lib/junos-ez/system.rb +98 -0
- data/lib/junos-ez/utils/config.rb +205 -0
- data/lib/junos-ez/utils/fs.rb +376 -0
- data/lib/junos-ez/utils/re.rb +371 -0
- data/lib/junos-ez/vlans/bridge_domain.rb +85 -0
- data/lib/junos-ez/vlans/vlan.rb +112 -0
- data/lib/junos-ez/vlans.rb +31 -0
- metadata +111 -0
@@ -0,0 +1,371 @@
|
|
1
|
+
=begin
|
2
|
+
---------------------------------------------------------------------
|
3
|
+
|
4
|
+
This file contains routing-engine utility methods. These are
|
5
|
+
a misc. collection of methods that perform basic automation tasks
|
6
|
+
like upgrading software or getting process information. The
|
7
|
+
following lists the methods and the equivalent Junos CLI commands
|
8
|
+
|
9
|
+
- status: show chassis routing-engine
|
10
|
+
- uptime: show system uptime
|
11
|
+
- system_alarms: show system alarms
|
12
|
+
- chassis_alarms: show chassis alarms
|
13
|
+
- memory: show system memeory
|
14
|
+
- users: show system users
|
15
|
+
- validate_software?: request system software validate
|
16
|
+
- install_software!: request system software add
|
17
|
+
- rollback_software!: request system software rollback
|
18
|
+
- reboot!: request system reboot (no confirm!!)
|
19
|
+
- shutdown!: request system power-off (no confirm!!)
|
20
|
+
|
21
|
+
---------------------------------------------------------------------
|
22
|
+
=end
|
23
|
+
|
24
|
+
module Junos::Ez::RE
|
25
|
+
def self.Utils( ndev, varsym )
|
26
|
+
newbie = Junos::Ez::RE::Provider.new( ndev )
|
27
|
+
Junos::Ez::Provider.attach_instance_variable( ndev, varsym, newbie )
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
### -----------------------------------------------------------------
|
32
|
+
### PUBLIC METHODS
|
33
|
+
### -----------------------------------------------------------------
|
34
|
+
### class containing filesystem public utility functions
|
35
|
+
### these are not in alphabetical order, but I should do that, yo!
|
36
|
+
### -----------------------------------------------------------------
|
37
|
+
|
38
|
+
class Junos::Ez::RE::Provider < Junos::Ez::Provider::Parent
|
39
|
+
|
40
|
+
### ---------------------------------------------------------------
|
41
|
+
### status - show chassis routing-engine information
|
42
|
+
### ---------------------------------------------------------------
|
43
|
+
|
44
|
+
def status( opts = {} )
|
45
|
+
got = @ndev.rpc.get_route_engine_information
|
46
|
+
status_h = {}
|
47
|
+
got.xpath('//route-engine').each do |re|
|
48
|
+
re_h = {}
|
49
|
+
slot_id = re.xpath('slot').text.to_i
|
50
|
+
status_h[slot_id] = re_h
|
51
|
+
|
52
|
+
re_h[:model] = re.xpath('model').text.strip
|
53
|
+
re_h[:serialnumber] = re.xpath('serial-number').text.strip
|
54
|
+
|
55
|
+
xml_when_item(re.xpath('mastership-state')){|i| re_h[:mastership] = i.text.strip}
|
56
|
+
|
57
|
+
re_h[:temperature] = {
|
58
|
+
:system => re.xpath('temperature').text.strip,
|
59
|
+
:cpu => re.xpath('cpu-temperature').text.strip
|
60
|
+
}
|
61
|
+
re_h[:memory] = {
|
62
|
+
:total_size => re.xpath('memory-dram-size').text.to_i,
|
63
|
+
:buffer_util => re.xpath('memory-buffer-itilization').text.to_i
|
64
|
+
}
|
65
|
+
re_h[:cpu_util] = {
|
66
|
+
:user => re.xpath('cpu-user').text.to_i,
|
67
|
+
:background => re.xpath('cpu-background').text.to_i,
|
68
|
+
:system => re.xpath('cpu-system').text.to_i,
|
69
|
+
:interrupt => re.xpath('cpu-interrupt').text.to_i,
|
70
|
+
:idle => re.xpath('cpu-idle').text.to_i,
|
71
|
+
}
|
72
|
+
re_h[:uptime] = {
|
73
|
+
:at => re.xpath('start-time').text.strip,
|
74
|
+
:ago => re.xpath('up-time').text.strip,
|
75
|
+
:reboot_reason => re.xpath('last-reboot-reason').text.strip
|
76
|
+
}
|
77
|
+
re_h[:load_avg] = [
|
78
|
+
re.xpath('load-average-one').text.to_f,
|
79
|
+
re.xpath('load-average-five').text.to_f,
|
80
|
+
re.xpath('load-average-fifteen').text.to_f
|
81
|
+
]
|
82
|
+
end
|
83
|
+
status_h
|
84
|
+
end
|
85
|
+
|
86
|
+
### ---------------------------------------------------------------
|
87
|
+
### uptime - show system uptime information
|
88
|
+
### ---------------------------------------------------------------
|
89
|
+
|
90
|
+
def uptime
|
91
|
+
up_h = {}
|
92
|
+
got = @ndev.rpc.get_system_uptime_information
|
93
|
+
unless (n_re = got.xpath('multi-routing-engine-item')).empty?
|
94
|
+
n_re.each do |this_re|
|
95
|
+
as_xml = this_re.xpath('system-uptime-information')
|
96
|
+
re_name = this_re.xpath('re-name').text.strip
|
97
|
+
up_h[re_name] = {}
|
98
|
+
_uptime_to_h( as_xml, up_h[re_name] )
|
99
|
+
end
|
100
|
+
else
|
101
|
+
up_h['re0'] = {}
|
102
|
+
_uptime_to_h( got, up_h['re0'] )
|
103
|
+
end
|
104
|
+
up_h
|
105
|
+
end
|
106
|
+
|
107
|
+
### ---------------------------------------------------------------
|
108
|
+
### system_alarms - show system alarms
|
109
|
+
### ---------------------------------------------------------------
|
110
|
+
|
111
|
+
def system_alarms
|
112
|
+
got = @ndev.rpc.get_system_alarm_information
|
113
|
+
alarms_a = []
|
114
|
+
got.xpath('alarm-detail').each do |alarm|
|
115
|
+
alarm_h = {}
|
116
|
+
_alarm_info_to_h( alarm, alarm_h )
|
117
|
+
alarms_a << alarm_h
|
118
|
+
end
|
119
|
+
return nil if alarms_a.empty?
|
120
|
+
alarms_a
|
121
|
+
end
|
122
|
+
|
123
|
+
### ---------------------------------------------------------------
|
124
|
+
### chassis_alarms - show chassis alarms
|
125
|
+
### ---------------------------------------------------------------
|
126
|
+
|
127
|
+
def chassis_alarms
|
128
|
+
got = @ndev.rpc.get_alarm_information
|
129
|
+
alarms_a = []
|
130
|
+
got.xpath('alarm-detail').each do |alarm|
|
131
|
+
alarm_h = {}
|
132
|
+
_alarm_info_to_h( alarm, alarm_h )
|
133
|
+
alarms_a << alarm_h
|
134
|
+
end
|
135
|
+
return nil if alarms_a.empty?
|
136
|
+
alarms_a
|
137
|
+
end
|
138
|
+
|
139
|
+
### ---------------------------------------------------------------
|
140
|
+
### memory - show system memory
|
141
|
+
### ---------------------------------------------------------------
|
142
|
+
|
143
|
+
def memory
|
144
|
+
got = @ndev.rpc.get_system_memory_information
|
145
|
+
ret_h = {}
|
146
|
+
unless (n_re = got.xpath('multi-routing-engine-item')).empty?
|
147
|
+
n_re.each do |this_re|
|
148
|
+
as_xml = this_re.xpath('system-memory-information')[0]
|
149
|
+
re_name = this_re.xpath('re-name').text.strip
|
150
|
+
ret_h[re_name] = {}
|
151
|
+
_system_memory_to_h( as_xml, ret_h[re_name] )
|
152
|
+
end
|
153
|
+
else
|
154
|
+
ret_h['re0'] = {}
|
155
|
+
_system_memory_to_h( got, ret_h['re0'] )
|
156
|
+
end
|
157
|
+
ret_h
|
158
|
+
end
|
159
|
+
|
160
|
+
### ---------------------------------------------------------------
|
161
|
+
### users - show system users
|
162
|
+
### ---------------------------------------------------------------
|
163
|
+
|
164
|
+
def users
|
165
|
+
got = @ndev.rpc.get_system_users_information
|
166
|
+
users_h = {}
|
167
|
+
got.xpath('uptime-information/user-table/user-entry').each do |user|
|
168
|
+
user_h = {}
|
169
|
+
user_name = user.xpath('user').text.strip
|
170
|
+
user_h[:tty] = user.xpath('tty').text.strip
|
171
|
+
user_h[:from] = user.xpath('from').text.strip
|
172
|
+
user_h[:login_time] = user.xpath('login-time').text.strip
|
173
|
+
user_h[:idle_time] = user.xpath('idel-time').text.strip
|
174
|
+
user_h[:command] = user.xpath('command').text.strip
|
175
|
+
users_h[user_name] = user_h
|
176
|
+
end
|
177
|
+
users_h
|
178
|
+
end
|
179
|
+
|
180
|
+
### ---------------------------------------------------------------
|
181
|
+
### validate_software? - request system software validate ...
|
182
|
+
### ---------------------------------------------------------------
|
183
|
+
|
184
|
+
def validate_software?( package )
|
185
|
+
got = @ndev.rpc.request_package_validate(:package_name => package).parent
|
186
|
+
errcode = got.xpath('package-result').text.to_i
|
187
|
+
return true if errcode == 0
|
188
|
+
|
189
|
+
# otherwise return the output error message
|
190
|
+
got.xpath('output').text.strip
|
191
|
+
end
|
192
|
+
|
193
|
+
### ---------------------------------------------------------------
|
194
|
+
### install_software! - request system software add ...
|
195
|
+
### ---------------------------------------------------------------
|
196
|
+
|
197
|
+
def install_software!( opts = {} )
|
198
|
+
raise ArgumentError "missing :package" unless opts[:package]
|
199
|
+
|
200
|
+
args = { :package_name => opts[:package] }
|
201
|
+
args[:no_validate] = true if opts[:no_validate]
|
202
|
+
args[:unlink] = true if opts[:unlink]
|
203
|
+
|
204
|
+
got = @ndev.rpc.request_package_add( args ).parent
|
205
|
+
errcode = got.xpath('package-result').text.to_i
|
206
|
+
return true if errcode == 0
|
207
|
+
|
208
|
+
# otherwise return the output error message
|
209
|
+
got.xpath('output').text.strip
|
210
|
+
end
|
211
|
+
|
212
|
+
### ---------------------------------------------------------------
|
213
|
+
### rollback_software! - request system software rollback
|
214
|
+
### ---------------------------------------------------------------
|
215
|
+
|
216
|
+
def rollback_software!
|
217
|
+
got = @ndev.rpc.request_package_rollback
|
218
|
+
got.text.strip
|
219
|
+
end
|
220
|
+
|
221
|
+
### ---------------------------------------------------------------
|
222
|
+
### reboot! - request system reboot (no confirm!!)
|
223
|
+
### ---------------------------------------------------------------
|
224
|
+
|
225
|
+
def reboot!( opts = {} )
|
226
|
+
got = @ndev.rpc.request_reboot
|
227
|
+
got.xpath('request-reboot-status').text.strip
|
228
|
+
end
|
229
|
+
|
230
|
+
### ---------------------------------------------------------------
|
231
|
+
### shutdown! - request system power-off (no confirm!!)
|
232
|
+
### ---------------------------------------------------------------
|
233
|
+
|
234
|
+
def shutdown!( opts = {} )
|
235
|
+
## some Junos devices will throw an RPC error exception which is really
|
236
|
+
## a warning, and some do not. So we need to trap that here.
|
237
|
+
begin
|
238
|
+
got = @ndev.rpc.request_power_off
|
239
|
+
rescue => e
|
240
|
+
retmsg = e.rsp.xpath('//error-message').text.strip + "\n"
|
241
|
+
return retmsg + e.rsp.xpath('//request-reboot-status').text.strip
|
242
|
+
end
|
243
|
+
got.xpath('//request-reboot-status').text.strip
|
244
|
+
end
|
245
|
+
|
246
|
+
def ping( opts = {} )
|
247
|
+
arg_options = [
|
248
|
+
:host,
|
249
|
+
:do_not_fragment, :inet, :inet6, :strict,
|
250
|
+
:count, :interface, :interval, :mac_address,
|
251
|
+
:routing_instance, :size, :source, :tos, :ttl, :wait
|
252
|
+
]
|
253
|
+
|
254
|
+
args = {}
|
255
|
+
opts.each do |k,v|
|
256
|
+
if arg_options.include? k
|
257
|
+
args[k] = v
|
258
|
+
else
|
259
|
+
raise ArgumentError, "unrecognized option #{k}"
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
args[:count] ||= 1
|
264
|
+
|
265
|
+
got = @ndev.rpc.ping( args )
|
266
|
+
return true if got.xpath('ping-success')[0]
|
267
|
+
|
268
|
+
# if the caller privded a 'failure block' then call that now,
|
269
|
+
# otherwise, just return false
|
270
|
+
|
271
|
+
return (block_given?) ? yield(got) : false
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
### -----------------------------------------------------------------
|
276
|
+
### PRIVATE METHODS
|
277
|
+
### -----------------------------------------------------------------
|
278
|
+
|
279
|
+
class Junos::Ez::RE::Provider
|
280
|
+
private
|
281
|
+
|
282
|
+
def _uptime_to_h( as_xml, up_h )
|
283
|
+
up_h[:time_now] = as_xml.xpath('current-time/date-time').text.strip
|
284
|
+
|
285
|
+
data = as_xml.xpath('uptime-information')[0]
|
286
|
+
up_h[:active_users] = data.xpath('active-user-count').text.to_i
|
287
|
+
up_h[:load_avg] = [
|
288
|
+
data.xpath('load-average-1').text.to_f,
|
289
|
+
data.xpath('load-average-5').text.to_f,
|
290
|
+
data.xpath('load-average-15').text.to_f,
|
291
|
+
]
|
292
|
+
up_h[:uptime] = {
|
293
|
+
:at => data.xpath('date-time').text.strip,
|
294
|
+
:ago => data.xpath('up-time').text.strip,
|
295
|
+
}
|
296
|
+
|
297
|
+
data = as_xml.xpath('system-booted-time')[0]
|
298
|
+
up_h[:time_boot] = {
|
299
|
+
:at => data.xpath('date-time').text.strip,
|
300
|
+
:ago => data.xpath('time-length').text.strip
|
301
|
+
}
|
302
|
+
|
303
|
+
data = as_xml.xpath('protocols-started-time')[0]
|
304
|
+
up_h[:protocols_started] = {
|
305
|
+
:at => data.xpath('date-time').text.strip,
|
306
|
+
:ago => data.xpath('time-length').text.strip
|
307
|
+
}
|
308
|
+
|
309
|
+
data = as_xml.xpath('last-configured-time')[0]
|
310
|
+
up_h[:last_config] = {
|
311
|
+
:at => data.xpath('date-time').text.strip,
|
312
|
+
:ago => data.xpath('time-length').text.strip,
|
313
|
+
:by => data.xpath('user').text.strip
|
314
|
+
}
|
315
|
+
end
|
316
|
+
|
317
|
+
def _system_memory_to_h( as_xml, as_h )
|
318
|
+
|
319
|
+
summary = as_xml.xpath('system-memory-summary-information')[0]
|
320
|
+
as_h[:memory_summary] = {
|
321
|
+
:total => {
|
322
|
+
:size => summary.xpath('system-memory-total').text.to_i,
|
323
|
+
:percentage => summary.xpath('system-memory-total-percent').text.to_i
|
324
|
+
},
|
325
|
+
:reserved => {
|
326
|
+
:size => summary.xpath('system-memory-reserved').text.to_i,
|
327
|
+
:percentage => summary.xpath('system-memory-reserved-percent').text.to_i
|
328
|
+
},
|
329
|
+
:wired => {
|
330
|
+
:size => summary.xpath('system-memory-wired').text.to_i,
|
331
|
+
:percentage => summary.xpath('system-memory-wired-percent').text.to_i
|
332
|
+
},
|
333
|
+
:active => {
|
334
|
+
:size => summary.xpath('system-memory-active').text.to_i,
|
335
|
+
:percentage => summary.xpath('system-memory-active-percent').text.to_i
|
336
|
+
},
|
337
|
+
:inactive => {
|
338
|
+
:size => summary.xpath('system-memory-inactive').text.to_i,
|
339
|
+
:percentage => summary.xpath('system-memory-inactive-percent').text.to_i
|
340
|
+
},
|
341
|
+
:cache => {
|
342
|
+
:size => summary.xpath('system-memory-cache').text.to_i,
|
343
|
+
:percentage => summary.xpath('system-memory-cache-percent').text.to_i
|
344
|
+
},
|
345
|
+
:free => {
|
346
|
+
:size => summary.xpath('system-memory-free').text.to_i,
|
347
|
+
:percentage => summary.xpath('system-memory-free-percent').text.to_i
|
348
|
+
}
|
349
|
+
}
|
350
|
+
|
351
|
+
as_h[:procs] = {}
|
352
|
+
as_xml.xpath('pmap-terse-information/pmap-terse-summary').each do |proc|
|
353
|
+
proc_h = {}
|
354
|
+
proc_name = proc.xpath('map-name | process-name').text.strip
|
355
|
+
as_h[:procs][proc_name] = proc_h
|
356
|
+
|
357
|
+
proc_h[:pid] = proc.xpath('pid').text.to_i
|
358
|
+
proc_h[:size] = proc.xpath('size').text.to_i
|
359
|
+
proc_h[:size_pct] = proc.xpath('size-percent').text.to_f
|
360
|
+
proc_h[:resident] = proc.xpath('resident').text.to_i
|
361
|
+
proc_h[:resident_pct] = proc.xpath('resident-percent').text.to_f
|
362
|
+
end
|
363
|
+
end
|
364
|
+
|
365
|
+
def _alarm_info_to_h( alarm, alarm_h )
|
366
|
+
alarm_h[:at] = alarm.xpath('alarm-time').text.strip
|
367
|
+
alarm_h[:class] = alarm.xpath('alarm-class').text.strip
|
368
|
+
alarm_h[:description] = alarm.xpath('alarm-description').text.strip
|
369
|
+
alarm_h[:type] = alarm.xpath('alarm-type').text.strip
|
370
|
+
end
|
371
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
class Junos::Ez::Vlans::Provider::BRIDGE_DOMAIN < Junos::Ez::Vlans::Provider
|
2
|
+
|
3
|
+
### ---------------------------------------------------------------
|
4
|
+
### XML top placement
|
5
|
+
### ---------------------------------------------------------------
|
6
|
+
|
7
|
+
def xml_at_top
|
8
|
+
Nokogiri::XML::Builder.new{|x| x.configuration{
|
9
|
+
x.send( :'bridge-domains' ) { x.domain { x.name @name
|
10
|
+
return x
|
11
|
+
}}
|
12
|
+
}}
|
13
|
+
end
|
14
|
+
|
15
|
+
### ---------------------------------------------------------------
|
16
|
+
### XML readers
|
17
|
+
### ---------------------------------------------------------------
|
18
|
+
|
19
|
+
def xml_read!
|
20
|
+
cfg_xml = @ndev.rpc.get_configuration( xml_at_top )
|
21
|
+
return nil unless (@has_xml = cfg_xml.xpath('//domain')[0])
|
22
|
+
xml_read_parser( @has_xml, @has )
|
23
|
+
end
|
24
|
+
|
25
|
+
def xml_read_parser( as_xml, as_hash )
|
26
|
+
status_from_junos( as_xml, as_hash )
|
27
|
+
as_hash[:vlan_id] = as_xml.xpath('vlan-id').text.to_i
|
28
|
+
as_hash[:description] = as_xml.xpath('description').text
|
29
|
+
as_hash[:no_mac_learning] = as_xml.xpath('bridge-options/no-mac-learning').empty? ? false : true
|
30
|
+
return true
|
31
|
+
end
|
32
|
+
|
33
|
+
### ---------------------------------------------------------------
|
34
|
+
### XML writers
|
35
|
+
### ---------------------------------------------------------------
|
36
|
+
|
37
|
+
def xml_on_create( xml )
|
38
|
+
xml.send( :'domain-type', 'bridge' )
|
39
|
+
end
|
40
|
+
|
41
|
+
def xml_change_no_mac_learning( xml )
|
42
|
+
no_ml = @should[:no_mac_learning]
|
43
|
+
return unless ( exists? and no_ml )
|
44
|
+
xml.send(:'bridge-options') {
|
45
|
+
xml.send(:'no-mac-learning', no_ml ? nil : Netconf::JunosConfig::DELETE )
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def xml_change_vlan_id( xml )
|
50
|
+
xml.send( :'vlan-id', @should[:vlan_id] )
|
51
|
+
end
|
52
|
+
|
53
|
+
def xml_change_description( xml )
|
54
|
+
xml.description @should[:description]
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
##### ---------------------------------------------------------------
|
61
|
+
##### Provider collection methods
|
62
|
+
##### ---------------------------------------------------------------
|
63
|
+
|
64
|
+
class Junos::Ez::Vlans::Provider::BRIDGE_DOMAIN
|
65
|
+
|
66
|
+
def build_list
|
67
|
+
bd_cfgs = @ndev.rpc.get_configuration{ |x| x.send :'bridge-domains' }
|
68
|
+
bd_cfgs.xpath('bridge-domains/domain').collect do |domain|
|
69
|
+
domain.xpath('name').text
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def build_catalog
|
74
|
+
@catalog = {}
|
75
|
+
bd_cfgs = @ndev.rpc.get_configuration{ |x| x.send :'bridge-domains' }
|
76
|
+
bd_cfgs.xpath('bridge-domains/domain').collect do |domain|
|
77
|
+
name = domain.xpath('name').text
|
78
|
+
@catalog[name] = {}
|
79
|
+
xml_read_parser( domain, @catalog[name] )
|
80
|
+
end
|
81
|
+
return @catalog
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
@@ -0,0 +1,112 @@
|
|
1
|
+
class Junos::Ez::Vlans::Provider::VLAN < Junos::Ez::Vlans::Provider
|
2
|
+
|
3
|
+
### ---------------------------------------------------------------
|
4
|
+
### XML top placement
|
5
|
+
### ---------------------------------------------------------------
|
6
|
+
|
7
|
+
def xml_at_top
|
8
|
+
Nokogiri::XML::Builder.new{|x| x.configuration{
|
9
|
+
x.vlans { x.vlan { x.name @name
|
10
|
+
return x
|
11
|
+
}}
|
12
|
+
}}
|
13
|
+
end
|
14
|
+
|
15
|
+
### ---------------------------------------------------------------
|
16
|
+
### XML readers
|
17
|
+
### ---------------------------------------------------------------
|
18
|
+
|
19
|
+
def xml_get_has_xml( xml )
|
20
|
+
xml.xpath('//vlan')[0]
|
21
|
+
end
|
22
|
+
|
23
|
+
def xml_read_parser( as_xml, as_hash )
|
24
|
+
set_has_status( as_xml, as_hash )
|
25
|
+
as_hash[:vlan_id] = as_xml.xpath('vlan-id').text.to_i
|
26
|
+
xml_when_item(as_xml.xpath('description')){ |i| as_hash[:description] = i.text }
|
27
|
+
xml_when_item(as_xml.xpath('no-mac-learning')){ as_hash[:no_mac_learning] = true }
|
28
|
+
return true
|
29
|
+
end
|
30
|
+
|
31
|
+
### ---------------------------------------------------------------
|
32
|
+
### XML writers
|
33
|
+
### ---------------------------------------------------------------
|
34
|
+
|
35
|
+
def xml_change_no_mac_learning( xml )
|
36
|
+
no_ml = @should[:no_mac_learning]
|
37
|
+
return unless exists? and no_ml
|
38
|
+
xml.send(:'no-mac-learning', no_ml ? nil : Netconf::JunosConfig::DELETE )
|
39
|
+
end
|
40
|
+
|
41
|
+
def xml_change_vlan_id( xml )
|
42
|
+
xml.send(:'vlan-id', @should[:vlan_id] )
|
43
|
+
end
|
44
|
+
|
45
|
+
def xml_change_description( xml )
|
46
|
+
value = @should[:description]
|
47
|
+
xml.description value ? value : Netconf::JunosConfig::DELETE
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
##### ---------------------------------------------------------------
|
53
|
+
##### Provider collection methods
|
54
|
+
##### ---------------------------------------------------------------
|
55
|
+
|
56
|
+
class Junos::Ez::Vlans::Provider::VLAN
|
57
|
+
|
58
|
+
def build_list
|
59
|
+
xml_cfgs = @ndev.rpc.get_configuration{ |x| x.send :'vlans' }
|
60
|
+
xml_cfgs.xpath('vlans/vlan').collect do |vlan|
|
61
|
+
vlan.xpath('name').text
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def build_catalog
|
66
|
+
@catalog = {}
|
67
|
+
xml_cfgs = @ndev.rpc.get_configuration{ |x| x.send :'vlans' }
|
68
|
+
xml_cfgs.xpath('vlans/vlan').collect do |vlan|
|
69
|
+
name = vlan.xpath('name').text
|
70
|
+
@catalog[name] = {}
|
71
|
+
xml_read_parser( vlan, @catalog[name] )
|
72
|
+
end
|
73
|
+
return @catalog
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
##### ---------------------------------------------------------------
|
79
|
+
##### Provider operational methods
|
80
|
+
##### ---------------------------------------------------------------
|
81
|
+
|
82
|
+
class Junos::Ez::Vlans::Provider::VLAN
|
83
|
+
|
84
|
+
### ---------------------------------------------------------------
|
85
|
+
### interfaces - returns a Hash of each interface in the VLAN
|
86
|
+
### each interface (key) will identify:
|
87
|
+
### :mode = [ :access | :trunk ]
|
88
|
+
### :native = true if (:mode == :trunk) and this VLAN is the
|
89
|
+
### native vlan-id (untagged packets)
|
90
|
+
### ---------------------------------------------------------------
|
91
|
+
|
92
|
+
def interfaces( opts = {} )
|
93
|
+
raise ArgumentError, "not a resource" if is_provider?
|
94
|
+
|
95
|
+
args = {}
|
96
|
+
args[:vlan_name] = @name
|
97
|
+
args[:extensive] = true
|
98
|
+
got = @ndev.rpc.get_vlan_information( args )
|
99
|
+
|
100
|
+
members = got.xpath('vlan/vlan-detail/vlan-member-list/vlan-member')
|
101
|
+
ifs_h = {}
|
102
|
+
members.each do |port|
|
103
|
+
port_name = port.xpath('vlan-member-interface').text.split('.')[0]
|
104
|
+
port_h = {}
|
105
|
+
port_h[:mode] = port.xpath('vlan-member-port-mode').text.to_sym
|
106
|
+
native = (port.xpath('vlan-member-tagness').text == 'untagged')
|
107
|
+
port_h[:native] = true if( native and port_h[:mode] == :trunk)
|
108
|
+
ifs_h[port_name] = port_h
|
109
|
+
end
|
110
|
+
ifs_h
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "junos-ez/provider"
|
2
|
+
|
3
|
+
module Junos::Ez::Vlans
|
4
|
+
|
5
|
+
PROPERTIES = [
|
6
|
+
:vlan_id,
|
7
|
+
:description,
|
8
|
+
:no_mac_learning
|
9
|
+
]
|
10
|
+
|
11
|
+
def self.Provider( ndev, varsym )
|
12
|
+
newbie = case ndev.fact :switch_style
|
13
|
+
when :VLAN, :VLAN_NG
|
14
|
+
Junos::Ez::Vlans::Provider::VLAN.new( ndev )
|
15
|
+
when :BRIDGE_DOMAIN
|
16
|
+
Junos::Ez::Vlans::Provider::BRIDGE_DOMAIN.new( ndev )
|
17
|
+
end
|
18
|
+
newbie.properties = Junos::Ez::Provider::PROPERTIES + PROPERTIES
|
19
|
+
Junos::Ez::Provider.attach_instance_variable( ndev, varsym, newbie )
|
20
|
+
end
|
21
|
+
|
22
|
+
class Provider < Junos::Ez::Provider::Parent
|
23
|
+
# common parenting goes here ...
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'junos-ez/vlans/vlan'
|
29
|
+
require 'junos-ez/vlans/bridge_domain'
|
30
|
+
|
31
|
+
|