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
#bfd ⇒ Object
97
98
99
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 97
def bfd
config_get('bgp_neighbor', 'bfd', @get_args)
end
|
#bfd=(val) ⇒ Object
91
92
93
94
95
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 91
def bfd=(val)
set_args_keys(state: (val) ? '' : 'no')
Feature.bfd_enable
config_set('bgp_neighbor', 'bfd', @set_args)
end
|
#capability_negotiation ⇒ Object
144
145
146
147
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 144
def capability_negotiation
result = config_get('bgp_neighbor', 'capability_negotiation', @get_args)
result ? false : default_capability_negotiation
end
|
#capability_negotiation=(val) ⇒ Object
137
138
139
140
141
142
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 137
def capability_negotiation=(val)
set_args_keys(state: (val) ? 'no' : '')
config_set('bgp_neighbor', 'capability_negotiation', @set_args)
end
|
#connected_check ⇒ Object
128
129
130
131
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 128
def connected_check
result = config_get('bgp_neighbor', 'connected_check', @get_args)
result ? false : default_connected_check
end
|
#connected_check=(val) ⇒ Object
121
122
123
124
125
126
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 121
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_bfd ⇒ Object
101
102
103
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 101
def default_bfd
config_get_default('bgp_neighbor', 'bfd')
end
|
#default_capability_negotiation ⇒ Object
149
150
151
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 149
def default_capability_negotiation
config_get_default('bgp_neighbor', 'capability_negotiation')
end
|
#default_connected_check ⇒ Object
133
134
135
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 133
def default_connected_check
config_get_default('bgp_neighbor', 'connected_check')
end
|
#default_description ⇒ Object
117
118
119
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 117
def default_description
config_get_default('bgp_neighbor', 'description')
end
|
#default_dynamic_capability ⇒ Object
162
163
164
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 162
def default_dynamic_capability
config_get_default('bgp_neighbor', 'dynamic_capability')
end
|
#default_ebgp_multihop ⇒ Object
177
178
179
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 177
def default_ebgp_multihop
config_get_default('bgp_neighbor', 'ebgp_multihop')
end
|
#default_local_as ⇒ Object
194
195
196
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 194
def default_local_as
config_get_default('bgp_neighbor', 'local_as').to_s
end
|
#default_log_neighbor_changes ⇒ Object
216
217
218
219
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 216
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
231
232
233
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 231
def default_low_memory_exempt
config_get_default('bgp_neighbor', 'low_memory_exempt')
end
|
#default_maximum_peers ⇒ Object
245
246
247
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 245
def default_maximum_peers
config_get_default('bgp_neighbor', 'maximum_peers')
end
|
#default_password ⇒ Object
285
286
287
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 285
def default_password
config_get_default('bgp_neighbor', 'password')
end
|
#default_password_type ⇒ Object
294
295
296
297
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 294
def default_password_type
result = config_get_default('bgp_neighbor', 'password_type')
Encryption.cli_to_symbol(result)
end
|
#default_remote_as ⇒ Object
312
313
314
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 312
def default_remote_as
config_get_default('bgp_neighbor', 'remote_as').to_s
end
|
#default_remove_private_as ⇒ Object
333
334
335
336
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 333
def default_remove_private_as
result = config_get_default('bgp_neighbor', 'remove_private_as')
result.nil? ? nil : result.to_sym
end
|
#default_shutdown ⇒ Object
348
349
350
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 348
def default_shutdown
config_get_default('bgp_neighbor', 'shutdown')
end
|
#default_suppress_4_byte_as ⇒ Object
362
363
364
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 362
def default_suppress_4_byte_as
config_get_default('bgp_neighbor', 'suppress_4_byte_as')
end
|
#default_timers_holdtime ⇒ Object
399
400
401
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 399
def default_timers_holdtime
config_get_default('bgp_neighbor', 'timers_holdtime')
end
|
#default_timers_keepalive ⇒ Object
395
396
397
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 395
def default_timers_keepalive
config_get_default('bgp_neighbor', 'timers_keepalive')
end
|
#default_timers_keepalive_hold ⇒ Object
403
404
405
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 403
def default_timers_keepalive_hold
["#{default_timers_keepalive}", "#{default_timers_holdtime}"]
end
|
#default_transport_passive_mode ⇒ Object
433
434
435
436
437
438
439
440
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 433
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
451
452
453
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 451
def default_transport_passive_only
default_transport_passive_mode == :passive_only
end
|
#default_update_source ⇒ Object
469
470
471
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 469
def default_update_source
config_get_default('bgp_neighbor', 'update_source')
end
|
#description ⇒ Object
113
114
115
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 113
def description
config_get('bgp_neighbor', 'description', @get_args)
end
|
#description=(desc) ⇒ Object
105
106
107
108
109
110
111
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 105
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
158
159
160
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 158
def dynamic_capability
config_get('bgp_neighbor', 'dynamic_capability', @get_args)
end
|
#dynamic_capability=(val) ⇒ Object
153
154
155
156
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 153
def dynamic_capability=(val)
set_args_keys(state: (val) ? '' : 'no')
config_set('bgp_neighbor', 'dynamic_capability', @set_args)
end
|
#ebgp_multihop ⇒ Object
172
173
174
175
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 172
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
166
167
168
169
170
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 166
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
190
191
192
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 190
def local_as
config_get('bgp_neighbor', 'local_as', @get_args).to_s
end
|
#local_as=(val) ⇒ Object
181
182
183
184
185
186
187
188
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 181
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
209
210
211
212
213
214
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 209
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
198
199
200
201
202
203
204
205
206
207
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 198
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
226
227
228
229
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 226
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
221
222
223
224
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 221
def low_memory_exempt=(val)
set_args_keys(state: (val) ? '' : 'no')
config_set('bgp_neighbor', 'low_memory_exempt', @set_args)
end
|
#maximum_peers ⇒ Object
241
242
243
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 241
def maximum_peers
config_get('bgp_neighbor', 'maximum_peers', @get_args)
end
|
#maximum_peers=(val) ⇒ Object
235
236
237
238
239
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 235
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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 489
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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 473
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
281
282
283
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 281
def password
config_get('bgp_neighbor', 'password', @get_args)
end
|
#password_set(val, type = nil) ⇒ Object
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 249
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
289
290
291
292
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 289
def password_type
result = config_get('bgp_neighbor', 'password_type', @get_args)
Encryption.cli_to_symbol(result.to_s)
end
|
#remote_as ⇒ Object
308
309
310
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 308
def remote_as
config_get('bgp_neighbor', 'remote_as', @get_args).to_s
end
|
#remote_as=(val) ⇒ Object
299
300
301
302
303
304
305
306
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 299
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
327
328
329
330
331
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 327
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
316
317
318
319
320
321
322
323
324
325
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 316
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
343
344
345
346
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 343
def shutdown
result = config_get('bgp_neighbor', 'shutdown', @get_args)
result ? true : false
end
|
#shutdown=(val) ⇒ Object
338
339
340
341
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 338
def shutdown=(val)
set_args_keys(state: (val) ? '' : 'no')
config_set('bgp_neighbor', 'shutdown', @set_args)
end
|
#suppress_4_byte_as ⇒ Object
357
358
359
360
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 357
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
352
353
354
355
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 352
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
389
390
391
392
393
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 389
def timers_holdtime
_keepalive, hold = timers_keepalive_hold
return default_timers_holdtime if hold.nil?
hold.to_i
end
|
#timers_keepalive ⇒ Object
383
384
385
386
387
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 383
def timers_keepalive
keepalive, _hold = timers_keepalive_hold
return default_timers_keepalive if keepalive.nil?
keepalive.to_i
end
|
#timers_keepalive_hold ⇒ Object
378
379
380
381
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 378
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
366
367
368
369
370
371
372
373
374
375
376
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 366
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
424
425
426
427
428
429
430
431
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 424
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 407
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
447
448
449
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 447
def transport_passive_only
transport_passive_mode == :passive_only
end
|
#transport_passive_only=(val) ⇒ Object
442
443
444
445
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 442
def transport_passive_only=(val)
self.transport_passive_mode = (val ? :passive_only : :none)
end
|
#update_source ⇒ Object
464
465
466
467
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 464
def update_source
result = config_get('bgp_neighbor', 'update_source', @get_args)
result.downcase.strip
end
|
#update_source=(val) ⇒ Object
455
456
457
458
459
460
461
462
|
# File 'lib/cisco_node_utils/bgp_neighbor.rb', line 455
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
|