Class: Cisco::RouterOspfVrf
Overview
RouterOspfVrf - node utility class for per-VRF OSPF config management
Constant Summary
collapse
- OSPF_AUTO_COST =
{
mbps: 'Mbps',
gbps: 'Gbps',
}
- OSPF_LOG_ADJACENCY =
{
none: 'none',
log: '',
detail: 'detail',
}
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(router, name, instantiate = true) ⇒ RouterOspfVrf
Returns a new instance of RouterOspfVrf.
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 36
def initialize(router, name, instantiate=true)
fail TypeError if router.nil?
fail TypeError if name.nil?
fail ArgumentError unless router.length > 0
fail ArgumentError unless name.length > 0
@router = router
@name = name
@parent = {}
set_args_keys_default
create if instantiate
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
23
24
25
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 23
def name
@name
end
|
#parent ⇒ Object
Returns the value of attribute parent.
23
24
25
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 23
def parent
@parent
end
|
Class Method Details
.vrfs ⇒ Object
Create a hash of all router ospf vrf instances
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 50
def self.vrfs
hash_final = {}
RouterOspf.routers.each do |instance|
name = instance[0]
vrf_ids = config_get('ospf', 'vrf', name: name)
hash_tmp = {
name => { 'default' => RouterOspfVrf.new(name, 'default', false) }
}
unless vrf_ids.nil?
vrf_ids.each do |vrf|
hash_tmp[name][vrf] = RouterOspfVrf.new(name, vrf, false)
end
end
hash_final.merge!(hash_tmp)
end
hash_final
end
|
Instance Method Details
#auto_cost ⇒ Object
104
105
106
107
108
109
110
111
112
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 104
def auto_cost
match = config_get('ospf', 'auto_cost', @get_args)
return default_auto_cost if match.nil?
if match.last.nil?
[match.first.to_i, OSPF_AUTO_COST[:mbps]]
else
[match.first.to_i, match.last]
end
end
|
#auto_cost_set(cost, type) ⇒ Object
114
115
116
117
118
119
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 114
def auto_cost_set(cost, type)
@set_args[:cost] = cost
@set_args[:type] = OSPF_AUTO_COST[type]
config_set('ospf', 'auto_cost', @set_args)
delete_set_args_keys([:cost, :type])
end
|
#bfd ⇒ Object
125
126
127
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 125
def bfd
config_get('ospf', 'bfd', @get_args)
end
|
#bfd=(state) ⇒ Object
129
130
131
132
133
134
135
136
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 129
def bfd=(state)
return if state == bfd
no_cmd = (state ? '' : 'no')
@set_args[:state] = no_cmd
Feature.bfd_enable
config_set('ospf', 'bfd', @set_args)
delete_set_args_keys([:state])
end
|
#create ⇒ Object
Create one router ospf vrf instance
69
70
71
72
73
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 69
def create
@parent = RouterOspf.new(@router)
config_set('ospf', 'vrf',
name: @router, state: '', vrf: @name) if @name != 'default'
end
|
#default_auto_cost ⇒ Object
121
122
123
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 121
def default_auto_cost
config_get_default('ospf', 'auto_cost')
end
|
#default_bfd ⇒ Object
138
139
140
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 138
def default_bfd
config_get_default('ospf', 'bfd')
end
|
#default_default_metric ⇒ Object
158
159
160
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 158
def default_default_metric
config_get_default('ospf', 'default_metric')
end
|
#default_log_adjacency ⇒ Object
181
182
183
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 181
def default_log_adjacency
config_get_default('ospf', 'log_adjacency')
end
|
#default_metric ⇒ Object
142
143
144
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 142
def default_metric
config_get('ospf', 'default_metric', @get_args)
end
|
#default_metric=(metric) ⇒ Object
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 146
def default_metric=(metric)
if metric == default_default_metric
@set_args[:state] = 'no'
@set_args[:metric] = ''
else
@set_args[:state] = ''
@set_args[:metric] = metric
end
config_set('ospf', 'default_metric', @set_args)
delete_set_args_keys([:state, :metric])
end
|
#default_redistribute ⇒ Object
211
212
213
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 211
def default_redistribute
config_get_default('ospf', 'redistribute')
end
|
#default_router_id ⇒ Object
232
233
234
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 232
def default_router_id
config_get_default('ospf', 'router_id')
end
|
#default_timer_throttle_lsa ⇒ Object
271
272
273
274
275
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 271
def default_timer_throttle_lsa
[default_timer_throttle_lsa_start,
default_timer_throttle_lsa_hold,
default_timer_throttle_lsa_max]
end
|
#default_timer_throttle_lsa_hold ⇒ Object
281
282
283
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 281
def default_timer_throttle_lsa_hold
config_get_default('ospf', 'timer_throttle_lsa_hold')
end
|
#default_timer_throttle_lsa_max ⇒ Object
285
286
287
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 285
def default_timer_throttle_lsa_max
config_get_default('ospf', 'timer_throttle_lsa_max')
end
|
#default_timer_throttle_lsa_start ⇒ Object
277
278
279
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 277
def default_timer_throttle_lsa_start
config_get_default('ospf', 'timer_throttle_lsa_start')
end
|
#default_timer_throttle_spf ⇒ Object
324
325
326
327
328
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 324
def default_timer_throttle_spf
[default_timer_throttle_spf_start,
default_timer_throttle_spf_hold,
default_timer_throttle_spf_max]
end
|
#default_timer_throttle_spf_hold ⇒ Object
334
335
336
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 334
def default_timer_throttle_spf_hold
config_get_default('ospf', 'timer_throttle_spf_hold')
end
|
#default_timer_throttle_spf_max ⇒ Object
338
339
340
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 338
def default_timer_throttle_spf_max
config_get_default('ospf', 'timer_throttle_spf_max')
end
|
#default_timer_throttle_spf_start ⇒ Object
330
331
332
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 330
def default_timer_throttle_spf_start
config_get_default('ospf', 'timer_throttle_spf_start')
end
|
#delete_set_args_keys(list) ⇒ Object
Helper method to delete @set_args hash keys
82
83
84
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 82
def delete_set_args_keys(list)
list.each { |key| @set_args.delete(key) }
end
|
#destroy ⇒ Object
Destroy one router ospf vrf instance
76
77
78
79
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 76
def destroy
fail RuntimeError if @name == 'default'
config_set('ospf', 'vrf', name: @router, state: 'no', vrf: @name)
end
|
#log_adjacency ⇒ Object
162
163
164
165
166
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 162
def log_adjacency
match = config_get('ospf', 'log_adjacency', @get_args)
return default_log_adjacency if match.nil?
match.flatten.last.nil? ? :log : :detail
end
|
#log_adjacency=(type) ⇒ Object
168
169
170
171
172
173
174
175
176
177
178
179
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 168
def log_adjacency=(type)
case type
when :none
@set_args[:state] = 'no'
@set_args[:type] = ''
when :log, :detail
@set_args[:state] = ''
@set_args[:type] = OSPF_LOG_ADJACENCY[type]
end
config_set('ospf', 'log_adjacency', @set_args)
delete_set_args_keys([:state, :type])
end
|
#redistribute ⇒ Object
Build an array of all redistribute commands currently on the device
190
191
192
193
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 190
def redistribute
c = config_get('ospf', 'redistribute', @get_args)
c.nil? ? nil : c.each(&:compact!).sort
end
|
#redistribute=(should) ⇒ Object
redistribute setter. Process a hash of redistribute commands from delta_add_remove().
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 197
def redistribute=(should)
delta_hash = Utils.delta_add_remove(should, redistribute)
return if delta_hash.values.flatten.empty?
[:add, :remove].each do |action|
Cisco::Logger.debug("redistribute delta #{@get_args}\n #{action}: " \
"#{delta_hash[action]}")
delta_hash[action].each do |protocol, route_map|
state = (action == :add) ? '' : 'no'
set_args_keys(state: state, protocol: protocol, route_map: route_map)
config_set('ospf', 'redistribute', @set_args)
end
end
end
|
#router_id ⇒ Object
215
216
217
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 215
def router_id
config_get('ospf', 'router_id', @get_args)
end
|
#router_id=(rid) ⇒ Object
219
220
221
222
223
224
225
226
227
228
229
230
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 219
def router_id=(rid)
if rid == default_router_id
@set_args[:state] = 'no'
@set_args[:router_id] = router_id
else
@set_args[:state] = ''
@set_args[:router_id] = rid
end
config_set('ospf', 'router_id', @set_args)
delete_set_args_keys([:state, :router_id])
end
|
#set_args_keys(hash = {}) ⇒ Object
rubocop:disable Style/AccessorMethodName
95
96
97
98
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 95
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 methods to delete @set_args hash keys
89
90
91
92
93
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 89
def set_args_keys_default
keys = { name: @router }
keys[:vrf] = @name unless @name == 'default'
@get_args = @set_args = keys
end
|
#timer_throttle_lsa ⇒ Object
236
237
238
239
240
241
242
243
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 236
def timer_throttle_lsa
match = config_get('ospf', 'timer_throttle_lsa', @get_args)
if match.nil?
default_timer_throttle_lsa
else
match.collect(&:to_i)
end
end
|
#timer_throttle_lsa_hold ⇒ Object
251
252
253
254
255
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 251
def timer_throttle_lsa_hold
_start, hold, _max = timer_throttle_lsa
return default_timer_throttle_lsa_hold if hold.nil?
hold
end
|
#timer_throttle_lsa_max ⇒ Object
257
258
259
260
261
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 257
def timer_throttle_lsa_max
_start, _hold, max = timer_throttle_lsa
return default_timer_throttle_lsa_max if max.nil?
max
end
|
#timer_throttle_lsa_set(start, hold, max) ⇒ Object
263
264
265
266
267
268
269
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 263
def timer_throttle_lsa_set(start, hold, max)
@set_args[:start] = start
@set_args[:hold] = hold
@set_args[:max] = max
config_set('ospf', 'timer_throttle_lsa', @set_args)
delete_set_args_keys([:start, :hold, :max])
end
|
#timer_throttle_lsa_start ⇒ Object
245
246
247
248
249
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 245
def timer_throttle_lsa_start
start, _hold, _max = timer_throttle_lsa
return default_timer_throttle_lsa_start if start.nil?
start
end
|
#timer_throttle_spf ⇒ Object
289
290
291
292
293
294
295
296
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 289
def timer_throttle_spf
match = config_get('ospf', 'timer_throttle_spf', @get_args)
if match.nil?
default_timer_throttle_spf
else
match.collect(&:to_i)
end
end
|
#timer_throttle_spf_hold ⇒ Object
304
305
306
307
308
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 304
def timer_throttle_spf_hold
_start, hold, _max = timer_throttle_spf
return default_timer_throttle_spf_hold if hold.nil?
hold
end
|
#timer_throttle_spf_max ⇒ Object
310
311
312
313
314
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 310
def timer_throttle_spf_max
_start, _hold, max = timer_throttle_spf
return default_timer_throttle_spf_max if max.nil?
max
end
|
#timer_throttle_spf_set(start, hold, max) ⇒ Object
316
317
318
319
320
321
322
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 316
def timer_throttle_spf_set(start, hold, max)
@set_args[:start] = start
@set_args[:hold] = hold
@set_args[:max] = max
config_set('ospf', 'timer_throttle_spf', @set_args)
delete_set_args_keys([:start, :hold, :max])
end
|
#timer_throttle_spf_start ⇒ Object
298
299
300
301
302
|
# File 'lib/cisco_node_utils/router_ospf_vrf.rb', line 298
def timer_throttle_spf_start
start, _hold, _max = timer_throttle_spf
return default_timer_throttle_spf_start if start.nil?
start
end
|