Class: Cisco::RouterBgpNeighbor
Overview
RouterBgpNeighbor - node utility class for BGP neighbor configs
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(asn, vrf, nbr, instantiate = true) ⇒ RouterBgpNeighbor
Returns a new instance of RouterBgpNeighbor.
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 30
def initialize(asn, vrf, nbr, instantiate=true)
fail TypeError unless nbr.is_a?(String)
@nbr = Utils.process_network_mask(nbr)
@asn = RouterBgp.validate_asnum(asn)
@vrf = vrf
@get_args = @set_args = { asnum: @asn, nbr: @nbr }
@get_args[:vrf] = @set_args[:vrf] = vrf if vrf != 'default'
create if instantiate
end
|
Instance Attribute Details
#asn ⇒ Object
Returns the value of attribute asn.
28
29
30
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 28
def asn
@asn
end
|
#nbr ⇒ Object
Returns the value of attribute nbr.
28
29
30
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 28
def nbr
@nbr
end
|
#vrf ⇒ Object
Returns the value of attribute vrf.
28
29
30
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 28
def vrf
@vrf
end
|
Class Method Details
.neighbors ⇒ Object
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 44
def self.neighbors
hash = {}
RouterBgp.routers.each do |asn, vrf|
hash[asn] = {}
vrf.each_key do |vrf_id|
get_args = { asnum: asn }
get_args[:vrf] = vrf_id unless vrf_id == 'default'
neighbor_list = config_get('bgp_neighbor', 'all_neighbors', get_args)
next if neighbor_list.nil?
hash[asn][vrf_id] = {}
neighbor_list.each do |nbr|
hash[asn][vrf_id][nbr] = RouterBgpNeighbor.new(asn, vrf_id,
nbr, false)
end
end
end
hash
rescue Cisco::CliError => e
raise unless e.clierror =~ /Syntax error/
return {}
end
|
Instance Method Details
#capability_negotiation ⇒ Object
130
131
132
133
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 130
def capability_negotiation
result = config_get('bgp_neighbor', 'capability_negotiation', @get_args)
result ? false : default_capability_negotiation
end
|
#capability_negotiation=(val) ⇒ Object
123
124
125
126
127
128
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 123
def capability_negotiation=(val)
set_args_keys(state: (val) ? 'no' : '')
config_set('bgp_neighbor', 'capability_negotiation', @set_args)
end
|
#connected_check ⇒ Object
114
115
116
117
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 114
def connected_check
result = config_get('bgp_neighbor', 'connected_check', @get_args)
result ? false : default_connected_check
end
|
#connected_check=(val) ⇒ Object
107
108
109
110
111
112
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 107
def connected_check=(val)
set_args_keys(state: (val) ? 'no' : '')
config_set('bgp_neighbor', 'connected_check', @set_args)
end
|
#create ⇒ Object
69
70
71
72
73
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 69
def create
Feature.bgp_enable if platform == :nexus
set_args_keys(state: '')
config_set('bgp', 'create_destroy_neighbor', @set_args)
end
|
#default_capability_negotiation ⇒ Object
135
136
137
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 135
def default_capability_negotiation
config_get_default('bgp_neighbor', 'capability_negotiation')
end
|
#default_connected_check ⇒ Object
119
120
121
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 119
def default_connected_check
config_get_default('bgp_neighbor', 'connected_check')
end
|
#default_description ⇒ Object
103
104
105
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 103
def default_description
config_get_default('bgp_neighbor', 'description')
end
|
#default_dynamic_capability ⇒ Object
148
149
150
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 148
def default_dynamic_capability
config_get_default('bgp_neighbor', 'dynamic_capability')
end
|
#default_ebgp_multihop ⇒ Object
163
164
165
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 163
def default_ebgp_multihop
config_get_default('bgp_neighbor', 'ebgp_multihop')
end
|
#default_local_as ⇒ Object
180
181
182
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 180
def default_local_as
config_get_default('bgp_neighbor', 'local_as').to_s
end
|
#default_log_neighbor_changes ⇒ Object
202
203
204
205
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 202
def default_log_neighbor_changes
result = config_get_default('bgp_neighbor', 'log_neighbor_changes')
result.to_sym unless result.nil?
end
|
#default_low_memory_exempt ⇒ Object
217
218
219
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 217
def default_low_memory_exempt
config_get_default('bgp_neighbor', 'low_memory_exempt')
end
|
#default_maximum_peers ⇒ Object
231
232
233
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 231
def default_maximum_peers
config_get_default('bgp_neighbor', 'maximum_peers')
end
|
#default_password ⇒ Object
271
272
273
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 271
def default_password
config_get_default('bgp_neighbor', 'password')
end
|
#default_password_type ⇒ Object
280
281
282
283
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 280
def default_password_type
result = config_get_default('bgp_neighbor', 'password_type')
Encryption.cli_to_symbol(result)
end
|
#default_remote_as ⇒ Object
298
299
300
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 298
def default_remote_as
config_get_default('bgp_neighbor', 'remote_as').to_s
end
|
#default_remove_private_as ⇒ Object
319
320
321
322
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 319
def default_remove_private_as
result = config_get_default('bgp_neighbor', 'remove_private_as')
result.nil? ? nil : result.to_sym
end
|
#default_shutdown ⇒ Object
334
335
336
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 334
def default_shutdown
config_get_default('bgp_neighbor', 'shutdown')
end
|
#default_suppress_4_byte_as ⇒ Object
348
349
350
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 348
def default_suppress_4_byte_as
config_get_default('bgp_neighbor', 'suppress_4_byte_as')
end
|
#default_timers_holdtime ⇒ Object
385
386
387
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 385
def default_timers_holdtime
config_get_default('bgp_neighbor', 'timers_holdtime')
end
|
#default_timers_keepalive ⇒ Object
381
382
383
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 381
def default_timers_keepalive
config_get_default('bgp_neighbor', 'timers_keepalive')
end
|
#default_timers_keepalive_hold ⇒ Object
389
390
391
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 389
def default_timers_keepalive_hold
["#{default_timers_keepalive}", "#{default_timers_holdtime}"]
end
|
#default_transport_passive_mode ⇒ Object
419
420
421
422
423
424
425
426
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 419
def default_transport_passive_mode
result = config_get_default('bgp_neighbor', 'transport_passive_mode')
if platform == :nexus
result ? :passive_only : :none
else
mode_cli_to_symbol(result)
end
end
|
#default_transport_passive_only ⇒ Object
437
438
439
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 437
def default_transport_passive_only
default_transport_passive_mode == :passive_only
end
|
#default_update_source ⇒ Object
455
456
457
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 455
def default_update_source
config_get_default('bgp_neighbor', 'update_source')
end
|
#description ⇒ Object
99
100
101
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 99
def description
config_get('bgp_neighbor', 'description', @get_args)
end
|
#description=(desc) ⇒ Object
91
92
93
94
95
96
97
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 91
def description=(desc)
fail TypeError unless desc.is_a?(String)
desc.strip!
set_args_keys(state: desc.empty? ? 'no' : '',
desc: desc)
config_set('bgp_neighbor', 'description', @set_args)
end
|
#destroy ⇒ Object
75
76
77
78
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 75
def destroy
set_args_keys(state: 'no')
config_set('bgp', 'create_destroy_neighbor', @set_args)
end
|
#dynamic_capability ⇒ Object
144
145
146
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 144
def dynamic_capability
config_get('bgp_neighbor', 'dynamic_capability', @get_args)
end
|
#dynamic_capability=(val) ⇒ Object
139
140
141
142
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 139
def dynamic_capability=(val)
set_args_keys(state: (val) ? '' : 'no')
config_set('bgp_neighbor', 'dynamic_capability', @set_args)
end
|
#ebgp_multihop ⇒ Object
158
159
160
161
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 158
def ebgp_multihop
result = config_get('bgp_neighbor', 'ebgp_multihop', @get_args)
result.nil? ? default_ebgp_multihop : result.to_i
end
|
#ebgp_multihop=(ttl) ⇒ Object
152
153
154
155
156
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 152
def ebgp_multihop=(ttl)
set_args_keys(state: (ttl == default_ebgp_multihop) ? 'no' : '',
ttl: (ttl == default_ebgp_multihop) ? '' : ttl)
config_set('bgp_neighbor', 'ebgp_multihop', @set_args)
end
|
#local_as ⇒ Object
176
177
178
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 176
def local_as
config_get('bgp_neighbor', 'local_as', @get_args).to_s
end
|
#local_as=(val) ⇒ Object
167
168
169
170
171
172
173
174
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 167
def local_as=(val)
if val == default_local_as
set_args_keys(state: 'no', local_as: '')
else
set_args_keys(state: '', local_as: val)
end
config_set('bgp_neighbor', 'local_as', @set_args)
end
|
#log_neighbor_changes ⇒ Object
195
196
197
198
199
200
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 195
def log_neighbor_changes
result = config_get('bgp_neighbor', 'log_neighbor_changes', @get_args)
return default_log_neighbor_changes if result.nil?
return :disable if /disable/.match(result.first)
:enable
end
|
#log_neighbor_changes=(val) ⇒ Object
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 184
def log_neighbor_changes=(val)
val = val.to_sym
if val == default_log_neighbor_changes
set_args_keys(state: 'no', disable: '')
else
set_args_keys(state: '',
disable: (val == :enable) ? '' : 'disable')
end
config_set('bgp_neighbor', 'log_neighbor_changes', @set_args)
end
|
#low_memory_exempt ⇒ Object
212
213
214
215
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 212
def low_memory_exempt
result = config_get('bgp_neighbor', 'low_memory_exempt', @get_args)
result ? true : default_low_memory_exempt
end
|
#low_memory_exempt=(val) ⇒ Object
207
208
209
210
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 207
def low_memory_exempt=(val)
set_args_keys(state: (val) ? '' : 'no')
config_set('bgp_neighbor', 'low_memory_exempt', @set_args)
end
|
#maximum_peers ⇒ Object
227
228
229
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 227
def maximum_peers
config_get('bgp_neighbor', 'maximum_peers', @get_args)
end
|
#maximum_peers=(val) ⇒ Object
221
222
223
224
225
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 221
def maximum_peers=(val)
set_args_keys(state: (val == default_maximum_peers) ? 'no' : '',
num: (val == default_maximum_peers) ? '' : val)
config_set('bgp_neighbor', 'maximum_peers', @set_args)
end
|
#mode_cli_to_symbol(cli) ⇒ Object
475
476
477
478
479
480
481
482
483
484
485
486
487
488
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 475
def mode_cli_to_symbol(cli)
case cli
when 'active-only'
:active_only
when 'passive-only'
:passive_only
when 'both'
:both
when ''
:none
else
fail KeyError
end
end
|
#mode_symbol_to_cli(symbol) ⇒ Object
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 459
def mode_symbol_to_cli(symbol)
symbol = symbol.downcase if symbol.is_a? String
case symbol
when :active_only
'active-only'
when :passive_only
'passive-only'
when :both
'both'
when :none
''
else
fail KeyError
end
end
|
#password ⇒ Object
267
268
269
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 267
def password
config_get('bgp_neighbor', 'password', @get_args)
end
|
#password_set(val, type = nil) ⇒ Object
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 235
def password_set(val, type=nil)
val = val.to_s
if val.strip.empty?
set_args_keys(state: 'no', type: '', passwd: '')
elsif type.nil?
set_args_keys(state: '',
type: Encryption.symbol_to_cli(default_password_type),
passwd: val.to_s)
else
cli_type = nil
if platform == :ios_xr
case type
when :cleartext
cli_type = 'clear'
when :md5
cli_type = 'encrypted'
else
fail Cisco::UnsupportedError.new(
'RouterBgpNeighbor', 'password',
nil, "type '#{type}'")
end
else
cli_type = Encryption.symbol_to_cli(type)
end
set_args_keys(state: '',
type: cli_type,
passwd: val.to_s)
end
config_set('bgp_neighbor', 'password', @set_args)
end
|
#password_type ⇒ Object
275
276
277
278
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 275
def password_type
result = config_get('bgp_neighbor', 'password_type', @get_args)
Encryption.cli_to_symbol(result.to_s)
end
|
#remote_as ⇒ Object
294
295
296
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 294
def remote_as
config_get('bgp_neighbor', 'remote_as', @get_args).to_s
end
|
#remote_as=(val) ⇒ Object
285
286
287
288
289
290
291
292
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 285
def remote_as=(val)
if val == default_remote_as
set_args_keys(state: 'no', remote_as: '')
else
set_args_keys(state: '', remote_as: val)
end
config_set('bgp_neighbor', 'remote_as', @set_args)
end
|
#remove_private_as ⇒ Object
313
314
315
316
317
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 313
def remove_private_as
result = config_get('bgp_neighbor', 'remove_private_as', @get_args)
return default_remove_private_as if result.nil?
result.first.nil? ? :enable : result.first.to_sym
end
|
#remove_private_as=(val) ⇒ Object
302
303
304
305
306
307
308
309
310
311
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 302
def remove_private_as=(val)
val = val.to_sym
if val == default_remove_private_as
set_args_keys(state: 'no', option: '')
else
set_args_keys(state: '',
option: (val == :enable) ? '' : val.to_s)
end
config_set('bgp_neighbor', 'remove_private_as', @set_args)
end
|
#set_args_keys(hash = {}) ⇒ Object
rubocop:disable Style/AccessorMethodName
86
87
88
89
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 86
def set_args_keys(hash={}) set_args_keys_default
@set_args = @set_args.merge!(hash) unless hash.empty?
end
|
#set_args_keys_default ⇒ Object
80
81
82
83
84
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 80
def set_args_keys_default
keys = { asnum: @asn, nbr: @nbr }
keys[:vrf] = @vrf unless @vrf == 'default'
@set_args = keys
end
|
#shutdown ⇒ Object
329
330
331
332
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 329
def shutdown
result = config_get('bgp_neighbor', 'shutdown', @get_args)
result ? true : false
end
|
#shutdown=(val) ⇒ Object
324
325
326
327
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 324
def shutdown=(val)
set_args_keys(state: (val) ? '' : 'no')
config_set('bgp_neighbor', 'shutdown', @set_args)
end
|
#suppress_4_byte_as ⇒ Object
343
344
345
346
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 343
def suppress_4_byte_as
result = config_get('bgp_neighbor', 'suppress_4_byte_as', @get_args)
result ? true : false
end
|
#suppress_4_byte_as=(val) ⇒ Object
338
339
340
341
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 338
def suppress_4_byte_as=(val)
set_args_keys(state: (val) ? '' : 'no')
config_set('bgp_neighbor', 'suppress_4_byte_as', @set_args)
end
|
#timers_holdtime ⇒ Object
375
376
377
378
379
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 375
def timers_holdtime
_keepalive, hold = timers_keepalive_hold
return default_timers_holdtime if hold.nil?
hold.to_i
end
|
#timers_keepalive ⇒ Object
369
370
371
372
373
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 369
def timers_keepalive
keepalive, _hold = timers_keepalive_hold
return default_timers_keepalive if keepalive.nil?
keepalive.to_i
end
|
#timers_keepalive_hold ⇒ Object
364
365
366
367
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 364
def timers_keepalive_hold
match = config_get('bgp_neighbor', 'timers_keepalive_hold', @get_args)
match.nil? ? default_timers_keepalive_hold : match
end
|
#timers_set(keepalive, hold) ⇒ Object
352
353
354
355
356
357
358
359
360
361
362
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 352
def timers_set(keepalive, hold)
if keepalive == default_timers_keepalive &&
hold == default_timers_holdtime
set_args_keys(state: 'no', keepalive: timers_keepalive,
hold: timers_holdtime)
else
set_args_keys(state: '', keepalive: keepalive,
hold: hold)
end
config_set('bgp_neighbor', 'timers_keepalive_hold', @set_args)
end
|
#transport_passive_mode ⇒ Object
410
411
412
413
414
415
416
417
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 410
def transport_passive_mode
result = config_get('bgp_neighbor', 'transport_passive_mode', @get_args)
if platform == :nexus
result ? :passive_only : :none
else
mode_cli_to_symbol(result)
end
end
|
#transport_passive_mode=(val) ⇒ Object
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 393
def transport_passive_mode=(val)
if platform == :nexus
if val == :active_only
fail Cisco::UnsupportedError.new(
'RouterBgpNeighbor', 'transport_passive_mode',
nil, "value '#{val}'")
else
set_args_keys(state: (val == :passive_only) ? '' : 'no')
config_set('bgp_neighbor', 'transport_passive_mode', @set_args)
end
else
set_args_keys(mode: mode_symbol_to_cli(val),
state: (val == :none) ? 'no' : '')
config_set('bgp_neighbor', 'transport_passive_mode', @set_args)
end
end
|
#transport_passive_only ⇒ Object
433
434
435
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 433
def transport_passive_only
transport_passive_mode == :passive_only
end
|
#transport_passive_only=(val) ⇒ Object
428
429
430
431
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 428
def transport_passive_only=(val)
self.transport_passive_mode = (val ? :passive_only : :none)
end
|
#update_source ⇒ Object
450
451
452
453
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 450
def update_source
result = config_get('bgp_neighbor', 'update_source', @get_args)
result.downcase.strip
end
|
#update_source=(val) ⇒ Object
441
442
443
444
445
446
447
448
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 441
def update_source=(val)
if val.strip == default_update_source
set_args_keys(state: 'no', interface: update_source)
else
set_args_keys(state: '', interface: val)
end
config_set('bgp_neighbor', 'update_source', @set_args)
end
|