Class: Cisco::RouterOspfArea
- Inherits:
-
NodeUtil
show all
- Defined in:
- lib/cisco_node_utils/router_ospf_area.rb
Overview
node_utils class for ospf_area
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from NodeUtil
client, #client, config_get, #config_get, #config_get_default, config_get_default, config_set, #config_set, #get, #ios_xr?, #nexus?, #node, node, platform, #platform, supports?, #supports?
Constructor Details
#initialize(ospf_router, vrf_name, area_id, instantiate = true) ⇒ RouterOspfArea
Returns a new instance of RouterOspfArea.
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 30
def initialize(ospf_router, vrf_name, area_id, instantiate=true)
fail TypeError unless ospf_router.is_a?(String)
fail TypeError unless vrf_name.is_a?(String)
fail ArgumentError unless ospf_router.length > 0
fail ArgumentError unless vrf_name.length > 0
@area_id = area_id.to_s
fail ArgumentError if @area_id.empty?
Feature.ospf_enable if instantiate
@router = ospf_router
@vrf = vrf_name
@area_id = IPAddr.new(area_id.to_i, Socket::AF_INET) unless @area_id[/\./]
set_args_keys_default
end
|
Instance Attribute Details
#area_id ⇒ Object
Returns the value of attribute area_id.
28
29
30
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 28
def area_id
@area_id
end
|
#router ⇒ Object
Returns the value of attribute router.
28
29
30
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 28
def router
@router
end
|
#vrf ⇒ Object
Returns the value of attribute vrf.
28
29
30
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 28
def vrf
@vrf
end
|
Class Method Details
.areas ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 48
def self.areas
hash = {}
RouterOspf.routers.each do |name, _obj|
area_ids = config_get('ospf_area', 'areas', name: name)
if area_ids
hash[name] = {}
hash[name]['default'] = {}
area_ids.uniq.each do |area|
hash[name]['default'][area] =
RouterOspfArea.new(name, 'default', area, false)
end
end
vrf_ids = config_get('ospf', 'vrf', name: name)
next if vrf_ids.nil?
vrf_ids.each do |vrf|
area_ids = config_get('ospf_area', 'areas', name: name, vrf: vrf)
next if area_ids.nil?
hash[name] ||= {}
hash[name][vrf] = {}
area_ids.uniq.each do |area|
hash[name][vrf][area] =
RouterOspfArea.new(name, vrf, area, false)
end
end
end
hash
end
|
Instance Method Details
#==(other) ⇒ Object
108
109
110
111
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 108
def ==(other)
(ospf_router == other.ospf_router) &&
(vrf_name == other.vrf_name) && (area_id == other.area_id)
end
|
#authentication ⇒ Object
CLI can be either of the following or none area 1.1.1.1 authentication area 1.1.1.1 authentication message-digest
120
121
122
123
124
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 120
def authentication
auth = config_get('ospf_area', 'authentication', @get_args)
return default_authentication unless auth
auth.include?('message-digest') ? 'md5' : 'cleartext'
end
|
#authentication=(val) ⇒ Object
126
127
128
129
130
131
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 126
def authentication=(val)
state = val ? '' : 'no'
auth = (val.to_s == 'md5') ? 'message-digest' : ''
set_args_keys(state: state, auth: auth)
config_set('ospf_area', 'authentication', @set_args)
end
|
#default_authentication ⇒ Object
133
134
135
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 133
def default_authentication
config_get_default('ospf_area', 'authentication')
end
|
#default_cost ⇒ Object
CLI can be the following or none area 1.1.1.1 default-cost 1000
139
140
141
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 139
def default_cost
config_get('ospf_area', 'default_cost', @get_args)
end
|
#default_cost=(val) ⇒ Object
143
144
145
146
147
148
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 143
def default_cost=(val)
state = val == default_default_cost ? 'no' : ''
cost = val == default_default_cost ? '' : val
set_args_keys(state: state, cost: cost)
config_set('ospf_area', 'default_cost', @set_args)
end
|
#default_default_cost ⇒ Object
150
151
152
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 150
def default_default_cost
config_get_default('ospf_area', 'default_cost')
end
|
#default_filter_list_in ⇒ Object
168
169
170
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 168
def default_filter_list_in
config_get_default('ospf_area', 'filter_list_in')
end
|
#default_filter_list_out ⇒ Object
186
187
188
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 186
def default_filter_list_out
config_get_default('ospf_area', 'filter_list_out')
end
|
#default_nssa ⇒ Object
225
226
227
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 225
def default_nssa
config_get_default('ospf_area', 'nssa')
end
|
#default_nssa_default_originate ⇒ Object
233
234
235
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 233
def default_nssa_default_originate
config_get_default('ospf_area', 'nssa_default_originate')
end
|
#default_nssa_no_redistribution ⇒ Object
241
242
243
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 241
def default_nssa_no_redistribution
config_get_default('ospf_area', 'nssa_no_redistribution')
end
|
#default_nssa_no_summary ⇒ Object
249
250
251
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 249
def default_nssa_no_summary
config_get_default('ospf_area', 'nssa_no_summary')
end
|
#default_nssa_route_map ⇒ Object
257
258
259
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 257
def default_nssa_route_map
config_get_default('ospf_area', 'nssa_route_map')
end
|
#default_nssa_translate_type7 ⇒ Object
306
307
308
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 306
def default_nssa_translate_type7
config_get_default('ospf_area', 'nssa_translate_type7')
end
|
#default_range ⇒ Object
374
375
376
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 374
def default_range
config_get_default('ospf_area', 'range')
end
|
#default_stub ⇒ Object
388
389
390
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 388
def default_stub
config_get_default('ospf_area', 'stub')
end
|
#default_stub_no_summary ⇒ Object
412
413
414
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 412
def default_stub_no_summary
config_get_default('ospf_area', 'stub_no_summary')
end
|
#destroy ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 91
def destroy
return unless Feature.ospf_enabled?
[:authentication,
:default_cost,
:filter_list_in,
:filter_list_out,
:nssa,
:nssa_translate_type7,
:range,
:stub,
].each do |prop|
send("#{prop}=", send("default_#{prop}")) unless
send("#{prop}") == send("default_#{prop}")
end
set_args_keys_default
end
|
#filter_list_in ⇒ Object
CLI can be the following or none area 1.1.1.1 filter-list route-map aaa in
156
157
158
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 156
def filter_list_in
config_get('ospf_area', 'filter_list_in', @get_args)
end
|
#filter_list_in=(val) ⇒ Object
160
161
162
163
164
165
166
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 160
def filter_list_in=(val)
return if filter_list_in == false && val == false
state = val ? '' : 'no'
rm = val ? val : filter_list_in
set_args_keys(state: state, route_map: rm)
config_set('ospf_area', 'filter_list_in', @set_args)
end
|
#filter_list_out ⇒ Object
CLI can be the following or none area 1.1.1.1 filter-list route-map bbb out
174
175
176
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 174
def filter_list_out
config_get('ospf_area', 'filter_list_out', @get_args)
end
|
#filter_list_out=(val) ⇒ Object
178
179
180
181
182
183
184
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 178
def filter_list_out=(val)
return if filter_list_out == false && val == false
state = val ? '' : 'no'
rm = val ? val : filter_list_out
set_args_keys(state: state, route_map: rm)
config_set('ospf_area', 'filter_list_out', @set_args)
end
|
#nssa ⇒ Object
221
222
223
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 221
def nssa
nssa_get[:nssa].nil? ? false : true
end
|
#nssa_default_originate ⇒ Object
229
230
231
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 229
def nssa_default_originate
nssa_get[:def_info_origin].nil? ? false : true
end
|
#nssa_get ⇒ Object
CLI can be the following or none area 1.1.1.1 nssa the above command can be appended with no-summary and/or no-redistribution and/or default-information-originate. route-map <map> can be appended with default-information-originate Basically, every property this CLI configures is optional example manifest: nssa => true, nssa_default_originate => true, nssa_no_redistribution => false, nssa_no_summary => false, nssa_route_map => ‘aaa’,
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 202
def nssa_get
hash = {}
output = config_get('ospf_area', 'nssa_get', @get_args)
return hash if output.nil?
output.each do |line|
next if line.include?('translate')
hash[:nssa] = true
hash[:no_summary] = true if line.include?('no-summary')
hash[:no_redistribution] = true if line.include?('no-redistribution')
hash[:def_info_origin] = true if
line.include?('default-information-originate')
if line.include?('route-map')
params = line.split
hash[:route_map] = params[params.index('route-map') + 1]
end
end
hash
end
|
#nssa_no_redistribution ⇒ Object
237
238
239
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 237
def nssa_no_redistribution
nssa_get[:no_redistribution].nil? ? false : true
end
|
#nssa_no_summary ⇒ Object
245
246
247
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 245
def nssa_no_summary
nssa_get[:no_summary].nil? ? false : true
end
|
#nssa_route_map ⇒ Object
253
254
255
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 253
def nssa_route_map
nssa_get[:route_map].nil? ? '' : nssa_get[:route_map]
end
|
#nssa_set(hash) ⇒ Object
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 261
def nssa_set(hash)
config_set('ospf_area', 'nssa_destroy', @set_args) if nssa
return if hash.empty?
@set_args[:state] = ''
@set_args[:nssa_no_summary] = ''
@set_args[:nssa_no_redistribution] = ''
@set_args[:nssa_default_originate] = ''
@set_args[:nssa_route_map] = ''
hash.keys.each do |k|
hash[k] = 'default-information-originate' if
k == :nssa_default_originate
hash[k] = 'no-summary' if k == :nssa_no_summary
hash[k] = 'no-redistribution' if k == :nssa_no_redistribution
hash[k] = "route-map #{hash[:nssa_route_map]}" if
k == :nssa_route_map
@set_args[k] = hash[k]
end
config_set('ospf_area', 'nssa_set', @set_args)
end
|
#nssa_translate_type7 ⇒ Object
CLI can be the following or none area 1.1.1.1 nssa translate type7 always area 1.1.1.1 nssa translate type7 always supress-fa area 1.1.1.1 nssa translate type7 never area 1.1.1.1 nssa translate type7 supress-fa
290
291
292
293
294
295
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 290
def nssa_translate_type7
str = config_get('ospf_area', 'nssa_translate_type7', @get_args)
str = 'always_supress_fa' if str == 'always supress-fa'
str = 'supress_fa' if str == 'supress-fa'
str
end
|
#nssa_translate_type7=(val) ⇒ Object
297
298
299
300
301
302
303
304
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 297
def nssa_translate_type7=(val)
state = val ? '' : 'no'
value = val ? val : ''
value = 'always supress-fa' if val.to_s == 'always_supress_fa'
value = 'supress-fa' if val.to_s == 'supress_fa'
set_args_keys(state: state, value: value)
config_set('ospf_area', 'nssa_translate_type7', @set_args)
end
|
#range ⇒ Object
range can take multiple values for the same vrf area 1.1.1.1 range 10.3.0.0/32 area 1.1.1.1 range 10.3.0.1/32 area 1.1.1.1 range 10.3.3.0/24 area 1.1.1.1 range 10.3.0.0/16 not-advertise cost 23 sometimes the not-advertise and cost are reversed in the show command for reasons unknown! area 1.1.1.1 range 10.3.0.0/16 cost 23 not-advertise use positional way of getting the values as it is simple and there are only two properties which are optional. ip is mandatory the return list is of the form [ip, not-advertise, cost] ex: [[‘10.3.0.0/16’, ‘not-advertise’, ‘23’],
['10.3.0.0/32', 'not-advertise'],
['10.3.0.1/32'],
['10.3.3.0/24', '450']]
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 326
def range
list = []
ranges = config_get('ospf_area', 'range', @get_args)
ranges.each do |line|
llist = []
params = line.split
llist[0] = params[0]
llist[1] = 'not_advertise' if line.include?('not-advertise')
if line.include?('cost')
arr_index = llist[1].nil? ? 1 : 2
llist[arr_index] = params[params.index('cost') + 1]
end
list << llist
end
list
end
|
#range=(set_list) ⇒ Object
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 343
def range=(set_list)
ip_list = []
set_list.each do |ip, _not_advertise, _cval|
ip_list << ip
end
fail ArgumentError, 'Duplicate ip values for range' unless
ip_list.size == ip_list.uniq.size
cur_list = range
cur_list.each do |ip, _not_advertise, _cval|
set_args_keys(state: 'no', ip: ip, not_advertise: '',
cost: '', value: '')
config_set('ospf_area', 'range', @set_args)
end
set_list.each do |ip, noadv, cval|
na = noadv == 'not_advertise' ? 'not-advertise' : ''
cost = cval ? 'cost' : ''
value = cval ? cval : ''
if noadv && noadv != 'not_advertise'
cost = 'cost'
value = noadv
end
set_args_keys(state: '', ip: ip, not_advertise: na,
cost: cost, value: value)
config_set('ospf_area', 'range', @set_args)
end
end
|
#set_args_keys(hash = {}) ⇒ Object
rubocop:disable Style/AccessorMethodName
86
87
88
89
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 86
def set_args_keys(hash={})
set_args_keys_default
@set_args = @get_args.merge!(hash) unless hash.empty?
end
|
#set_args_keys_default ⇒ Object
Helper method to delete @set_args hash keys
79
80
81
82
83
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 79
def set_args_keys_default
@set_args = { name: @router, area: @area_id }
@set_args[:vrf] = @vrf unless @vrf == 'default'
@get_args = @set_args
end
|
#stub ⇒ Object
378
379
380
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 378
def stub
config_get('ospf_area', 'stub', @get_args)
end
|
#stub=(val) ⇒ Object
382
383
384
385
386
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 382
def stub=(val)
state = val ? '' : 'no'
set_args_keys(state: state)
config_set('ospf_area', 'stub', @set_args)
end
|
#stub_no_summary ⇒ Object
392
393
394
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 392
def stub_no_summary
config_get('ospf_area', 'stub_no_summary', @get_args)
end
|
#stub_no_summary=(val) ⇒ Object
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
# File 'lib/cisco_node_utils/router_ospf_area.rb', line 396
def stub_no_summary=(val)
if val
state = ''
set_args_keys(state: state)
config_set('ospf_area', 'stub_no_summary', @set_args)
else
if stub
set_args_keys(state: 'no')
config_set('ospf_area', 'stub', @set_args)
set_args_keys(state: '')
config_set('ospf_area', 'stub', @set_args)
end
end
end
|