cisco_node_utils 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +37 -0
  3. data/lib/cisco_node_utils/bfd_global.rb +4 -0
  4. data/lib/cisco_node_utils/cisco_cmn_utils.rb +25 -0
  5. data/lib/cisco_node_utils/cmd_ref/interface.yaml +18 -18
  6. data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +4 -1
  7. data/lib/cisco_node_utils/cmd_ref/interface_evpn_multisite.yaml +1 -1
  8. data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +17 -15
  9. data/lib/cisco_node_utils/interface.rb +117 -118
  10. data/lib/cisco_node_utils/interface_channel_group.rb +17 -8
  11. data/lib/cisco_node_utils/interface_evpn_multisite.rb +15 -6
  12. data/lib/cisco_node_utils/interface_ospf.rb +126 -102
  13. data/lib/cisco_node_utils/itd_service.rb +8 -0
  14. data/lib/cisco_node_utils/node.rb +0 -1
  15. data/lib/cisco_node_utils/platform.rb +16 -32
  16. data/lib/cisco_node_utils/version.rb +1 -1
  17. data/lib/cisco_node_utils/vlan.rb +1 -2
  18. data/lib/cisco_node_utils/vxlan_vtep.rb +1 -1
  19. data/tests/test_interface.rb +74 -13
  20. data/tests/test_interface_bdi.rb +2 -2
  21. data/tests/test_interface_channel_group.rb +24 -17
  22. data/tests/test_interface_evpn_multisite.rb +35 -0
  23. data/tests/test_interface_ospf.rb +71 -3
  24. data/tests/test_itd_service.rb +16 -4
  25. data/tests/test_node_ext.rb +4 -1
  26. data/tests/test_portchannel_global.rb +3 -0
  27. data/tests/test_router_ospf_vrf.rb +2 -34
  28. data/tests/test_stp_global.rb +4 -0
  29. metadata +3 -6
  30. data/lib/cisco_node_utils/cmd_ref/DEPRECATED.yaml +0 -118
  31. data/lib/cisco_node_utils/interface_DEPRECATED.rb +0 -518
  32. data/lib/cisco_node_utils/vlan_DEPRECATED.rb +0 -108
@@ -1,518 +0,0 @@
1
- # rubocop: disable Style/FileName
2
- #
3
- # Copyright (c) 2016 Cisco and/or its affiliates.
4
- #
5
- # Licensed under the Apache License, Version 2.0 (the "License");
6
- # you may not use this file except in compliance with the License.
7
- # You may obtain a copy of the License at
8
- #
9
- # http://www.apache.org/licenses/LICENSE-2.0
10
- #
11
- # Unless required by applicable law or agreed to in writing, software
12
- # distributed under the License is distributed on an "AS IS" BASIS,
13
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- # See the License for the specific language governing permissions and
15
- # limitations under the License.
16
- ###############################################################################
17
- #
18
- # WARNING! WARNING! WARNING!
19
- #
20
- # This file contains deprecated methods that will be removed with version 2.0.0
21
- #
22
- ###############################################################################
23
-
24
- require_relative 'node_util'
25
- require 'logger'
26
-
27
- # Cisco provider module
28
- module Cisco
29
- # Interface - node utility class for general interface config management
30
- class InterfaceDeprecated < NodeUtil
31
- PVLAN_PROPERTY = {
32
- host_promisc: 'switchport_mode_private_vlan_host_promiscous',
33
- allow_vlan: 'switchport_private_vlan_trunk_allowed_vlan',
34
- trunk_assoc: 'switchport_private_vlan_association_trunk',
35
- mapping_trunk: 'switchport_private_vlan_mapping_trunk',
36
- vlan_mapping: 'private_vlan_mapping',
37
- }
38
-
39
- def deprecation_warning(method, new_prop=nil)
40
- if new_prop.nil?
41
- new_prop = ''
42
- else
43
- new_prop = "The new property name is '#{new_prop}'"
44
- end
45
-
46
- warn "
47
- #########################################################################
48
- WARNING: Method '#{method.to_s.delete('=')}'
49
- is deprecated and should not be used.
50
- #{new_prop}
51
- #########################################################################
52
- "
53
- end
54
-
55
- def switchport_enable_and_mode_private_vlan_host(mode_set)
56
- deprecation_warning(__method__)
57
- switchport_enable unless switchport
58
- if mode_set[/(host|promiscuous)/]
59
- config_set('DEPRECATED', 'switchport_mode_private_vlan_host',
60
- name: @name, state: '', mode: IF_SWITCHPORT_MODE[mode_set])
61
- else
62
- config_set('DEPRECATED', 'switchport_mode_private_vlan_host',
63
- name: @name, state: 'no', mode: IF_SWITCHPORT_MODE[mode_set])
64
- end
65
- end
66
-
67
- def switchport_mode_private_vlan_host
68
- return nil if switchport_mode == :disabled
69
- mode = config_get('DEPRECATED',
70
- 'switchport_mode_private_vlan_host',
71
- name: @name)
72
- unless mode == default_switchport_mode_private_vlan_host
73
- mode = IF_SWITCHPORT_MODE.key(mode)
74
- end
75
- mode
76
- rescue IndexError
77
- # Assume this is an interface that doesn't support switchport.
78
- # Do not raise exception since the providers will prefetch this property
79
- # regardless of interface type.
80
- # TODO: this should probably be nil instead
81
- return default_switchport_mode_private_vlan_host
82
- end
83
-
84
- def switchport_mode_private_vlan_host=(mode_set)
85
- deprecation_warning(__method__, 'switchport_pvlan_host')
86
-
87
- fail ArgumentError unless IF_SWITCHPORT_MODE.keys.include? mode_set
88
- Feature.private_vlan_enable
89
- switchport_enable_and_mode_private_vlan_host(mode_set)
90
- end
91
-
92
- def default_switchport_mode_private_vlan_host
93
- config_get_default('DEPRECATED',
94
- 'switchport_mode_private_vlan_host')
95
- end
96
-
97
- def switchport_mode_private_vlan_host_association
98
- result = config_get('DEPRECATED',
99
- 'switchport_mode_private_vlan_host_association',
100
- name: @name)
101
- unless result == default_switchport_mode_private_vlan_host_association
102
- result = result[0].split(' ')
103
- end
104
- result
105
- end
106
-
107
- def switchport_mode_private_vlan_host_association=(vlans)
108
- deprecation_warning(__method__, 'switchport_pvlan_host_association')
109
- fail TypeError unless vlans.is_a?(Array) || vlans.empty?
110
- switchport_enable unless switchport
111
- Feature.private_vlan_enable
112
- if vlans == default_switchport_mode_private_vlan_host_association
113
- result = config_set('DEPRECATED',
114
- 'switchport_mode_private_vlan_host_association',
115
- name: @name, state: 'no', vlan_pr: '', vlan_sec: '')
116
-
117
- else
118
- result = config_set('DEPRECATED',
119
- 'switchport_mode_private_vlan_host_association',
120
- name: @name, state: '',
121
- vlan_pr: vlans[0], vlan_sec: vlans[1])
122
-
123
- end
124
- cli_error_check(result)
125
- end
126
-
127
- def default_switchport_mode_private_vlan_host_association
128
- config_get_default('DEPRECATED',
129
- 'switchport_mode_private_vlan_host_association')
130
- end
131
-
132
- # This api is used by private vlan to prepare the input to the setter
133
- # method. The input can be in the following formats for vlans:
134
- # 10-12,14. Prepare_array api is transforming this input into a flat array.
135
- # In the example above the returned array will be 10, 11, 12, 13. Prepare
136
- # array is first splitting the input on ',' and the than expanding the vlan
137
- # range element like 10-12 into a flat array. The final result will
138
- # be a flat array.
139
- # This way we can later used the lib utility to check the delta from
140
- # the input vlan value and the vlan configured to apply the right config.
141
- def prepare_array(is_list)
142
- new_list = []
143
- is_list.each do |item|
144
- if item.include?(',')
145
- new_list.push(item.split(','))
146
- else
147
- new_list.push(item)
148
- end
149
- end
150
- new_list.flatten!
151
- new_list.sort!
152
- new_list.each { |item| item.gsub!('-', '..') }
153
- is_list_new = []
154
- new_list.each do |elem|
155
- if elem.include?('..')
156
- elema = elem.split('..').map { |d| Integer(d) }
157
- elema.sort!
158
- tr = elema[0]..elema[1]
159
- tr.to_a.each do |item|
160
- is_list_new.push(item.to_s)
161
- end
162
- else
163
- is_list_new.push(elem)
164
- end
165
- end
166
- is_list_new
167
- end
168
-
169
- def configure_private_vlan_host_property(property, should_list_new,
170
- is_list_new, pr_vlan)
171
- delta_hash = Utils.delta_add_remove(should_list_new, is_list_new)
172
- [:add, :remove].each do |action|
173
- delta_hash[action].each do |vlans|
174
- state = (action == :add) ? '' : 'no'
175
- oper = (action == :add) ? 'add' : 'remove'
176
- if property[/(host_promisc|mapping_trunk)/]
177
-
178
- result = config_set('DEPRECATED', PVLAN_PROPERTY[property],
179
- name: @name, state: state,
180
- vlan_pr: pr_vlan, vlans: vlans)
181
- @match_found = true
182
- end
183
- if property[/allow_vlan/]
184
- result = config_set('DEPRECATED',
185
- PVLAN_PROPERTY[property],
186
- name: @name, state: '',
187
- oper: oper, vlans: vlans)
188
- end
189
- if property[/vlan_mapping/]
190
- result = config_set('DEPRECATED',
191
- PVLAN_PROPERTY[property],
192
- name: @name, state: state,
193
- vlans: vlans)
194
- end
195
- cli_error_check(result)
196
- end
197
- end
198
- end
199
-
200
- def configure_private_vlan_trunk_property(property, should_list_new,
201
- is_list, pr_vlan)
202
- case property
203
- when :trunk_assoc
204
- is_list.each do |vlans|
205
- vlans = vlans.split(' ')
206
- if vlans[0].eql? should_list_new[0]
207
- config_set('DEPRECATED',
208
- 'switchport_private_vlan_association_trunk',
209
- name: @name, state: 'no',
210
- vlan_pr: pr_vlan, vlan: vlans[1])
211
- break
212
- else
213
- next
214
- end
215
- end
216
- result = config_set('DEPRECATED', PVLAN_PROPERTY[property], name: @name,
217
- state: '', vlan_pr: should_list_new[0],
218
- vlan: should_list_new[1])
219
- when :mapping_trunk
220
- @match_found = false
221
- is_list.each do |vlans|
222
- vlans = vlans.split(' ')
223
- interf_vlan_list_delta(:mapping_trunk, vlans,
224
- should_list_new)
225
- if @match_found
226
- break
227
- else
228
- next
229
- end
230
- end
231
- result = config_set('DEPRECATED', PVLAN_PROPERTY[property], name: @name,
232
- state: '', vlan_pr: should_list_new[0],
233
- vlans: should_list_new[1])
234
- end
235
- cli_error_check(result)
236
- end
237
-
238
- # --------------------------
239
- # interf_vlan_list_delta is a helper function for the private_vlan_mapping
240
- # property. It walks the delta hash and adds/removes each target private
241
- # vlan.
242
-
243
- def interf_vlan_list_delta(property, is_list, should_list)
244
- pr_vlan = should_list[0]
245
- if is_list[0].eql? should_list[0]
246
- should_list = should_list[1].split(',')
247
- is_list = is_list[1].split(',')
248
-
249
- should_list_new = prepare_array(should_list)
250
- is_list_new = prepare_array(is_list)
251
- configure_private_vlan_host_property(property, should_list_new,
252
- is_list_new, pr_vlan)
253
- else
254
- case property
255
- when :mapping_trunk
256
- return
257
- end
258
- # If primary vlan are different we can simply replacing the all
259
- # config
260
- if should_list == default_switchport_mode_private_vlan_host_promisc
261
- result = config_set('DEPRECATED',
262
- 'switchport_mode_private_vlan_host_promiscous',
263
- name: @name, state: 'no',
264
- vlan_pr: '', vlans: '')
265
-
266
- else
267
- result = config_set('DEPRECATED',
268
- 'switchport_mode_private_vlan_host_promiscous',
269
- name: @name, state: '',
270
- vlan_pr: pr_vlan, vlans: should_list[1])
271
-
272
- end
273
- cli_error_check(result)
274
- end
275
- end
276
-
277
- def switchport_mode_private_vlan_host_promisc
278
- result = config_get('DEPRECATED',
279
- 'switchport_mode_private_vlan_host_promiscous',
280
- name: @name)
281
- unless result == default_switchport_mode_private_vlan_host_promisc
282
- result = result[0].split(' ')
283
- end
284
- result
285
- end
286
-
287
- def switchport_mode_private_vlan_host_promisc=(vlans)
288
- deprecation_warning(__method__, 'switchport_pvlan_promiscuous')
289
- fail TypeError unless vlans.is_a?(Array)
290
- fail TypeError unless vlans.empty? || vlans.length == 2
291
- switchport_enable unless switchport
292
- Feature.private_vlan_enable
293
- is_list = switchport_mode_private_vlan_host_promisc
294
- interf_vlan_list_delta(:host_promisc, is_list, vlans)
295
- end
296
-
297
- def default_switchport_mode_private_vlan_host_promisc
298
- config_get_default('DEPRECATED',
299
- 'switchport_mode_private_vlan_host_promiscous')
300
- end
301
-
302
- def switchport_mode_private_vlan_trunk_promiscuous
303
- return nil if switchport_mode == :disabled
304
- config_get('DEPRECATED',
305
- 'switchport_mode_private_vlan_trunk_promiscuous',
306
- name: @name)
307
- rescue IndexError
308
- # Assume this is an interface that doesn't support switchport.
309
- # Do not raise exception since the providers will prefetch this property
310
- # regardless of interface type.
311
- # TODO: this should probably be nil instead
312
- return default_switchport_mode_private_vlan_trunk_promiscuous
313
- end
314
-
315
- def switchport_mode_private_vlan_trunk_promiscuous=(state)
316
- deprecation_warning(__method__, 'switchport_pvlan_trunk_promiscuous')
317
- Feature.private_vlan_enable
318
- switchport_enable unless switchport
319
- if state == default_switchport_mode_private_vlan_trunk_promiscuous
320
- config_set('DEPRECATED',
321
- 'switchport_mode_private_vlan_trunk_promiscuous',
322
- name: @name, state: 'no')
323
- else
324
- config_set('DEPRECATED',
325
- 'switchport_mode_private_vlan_trunk_promiscuous',
326
- name: @name, state: '')
327
- end
328
- end
329
-
330
- def default_switchport_mode_private_vlan_trunk_promiscuous
331
- config_get_default('DEPRECATED',
332
- 'switchport_mode_private_vlan_trunk_promiscuous')
333
- end
334
-
335
- def switchport_mode_private_vlan_trunk_secondary
336
- return nil if switchport_mode == :disabled
337
- config_get('DEPRECATED',
338
- 'switchport_mode_private_vlan_trunk_secondary',
339
- name: @name)
340
- rescue IndexError
341
- # Assume this is an interface that doesn't support switchport.
342
- # Do not raise exception since the providers will prefetch this property
343
- # regardless of interface type.
344
- # TODO: this should probably be nil instead
345
- return default_switchport_mode_private_vlan_trunk_secondary
346
- end
347
-
348
- def switchport_mode_private_vlan_trunk_secondary=(state)
349
- deprecation_warning(__method__, 'switchport_pvlan_trunk_secondary')
350
- Feature.private_vlan_enable
351
- switchport_enable unless switchport
352
- if state == default_switchport_mode_private_vlan_trunk_secondary
353
- config_set('DEPRECATED', 'switchport_mode_private_vlan_trunk_secondary',
354
- name: @name, state: 'no')
355
- else
356
- config_set('DEPRECATED', 'switchport_mode_private_vlan_trunk_secondary',
357
- name: @name, state: '')
358
- end
359
- end
360
-
361
- def default_switchport_mode_private_vlan_trunk_secondary
362
- config_get_default('DEPRECATED',
363
- 'switchport_mode_private_vlan_trunk_secondary')
364
- end
365
-
366
- def switchport_private_vlan_trunk_allowed_vlan
367
- return nil if switchport_mode == :disabled
368
- result = config_get('DEPRECATED',
369
- 'switchport_private_vlan_trunk_allowed_vlan',
370
- name: @name)
371
-
372
- unless result == default_switchport_private_vlan_trunk_allowed_vlan
373
- if result[0].eql? 'none'
374
- result = default_switchport_private_vlan_trunk_allowed_vlan
375
- else
376
- result = result[0].split(',')
377
- end
378
- end
379
- result
380
- end
381
-
382
- def switchport_private_vlan_trunk_allowed_vlan=(vlans)
383
- deprecation_warning(__method__, 'switchport_pvlan_trunk_allowed_vlan')
384
- fail TypeError unless vlans.is_a?(Array)
385
- Feature.private_vlan_enable
386
- switchport_enable unless switchport
387
- if vlans == default_switchport_private_vlan_trunk_allowed_vlan
388
- vlans = prepare_array(switchport_private_vlan_trunk_allowed_vlan)
389
- # If there are no vlan presently configured, we can simply return
390
- return if vlans == default_switchport_private_vlan_trunk_allowed_vlan
391
- configure_private_vlan_host_property(:allow_vlan, [],
392
- vlans, '')
393
- else
394
- vlans = prepare_array(vlans)
395
- is_list = prepare_array(switchport_private_vlan_trunk_allowed_vlan)
396
- configure_private_vlan_host_property(:allow_vlan, vlans,
397
- is_list, '')
398
- end
399
- end
400
-
401
- def default_switchport_private_vlan_trunk_allowed_vlan
402
- config_get_default('DEPRECATED',
403
- 'switchport_private_vlan_trunk_allowed_vlan')
404
- end
405
-
406
- def switchport_private_vlan_trunk_native_vlan
407
- return nil if switchport_mode == :disabled
408
- config_get('DEPRECATED',
409
- 'switchport_private_vlan_trunk_native_vlan',
410
- name: @name)
411
- end
412
-
413
- def switchport_private_vlan_trunk_native_vlan=(vlan)
414
- deprecation_warning(__method__, 'switchport_pvlan_trunk_native_vlan')
415
- Feature.private_vlan_enable
416
- switchport_enable unless switchport
417
- if vlan == default_switchport_private_vlan_trunk_native_vlan
418
- config_set('DEPRECATED',
419
- 'switchport_private_vlan_trunk_native_vlan',
420
- name: @name, state: 'no', vlan: '')
421
-
422
- else
423
- config_set('DEPRECATED',
424
- 'switchport_private_vlan_trunk_native_vlan',
425
- name: @name, state: '', vlan: vlan)
426
- end
427
- end
428
-
429
- def default_switchport_private_vlan_trunk_native_vlan
430
- config_get_default('DEPRECATED',
431
- 'switchport_private_vlan_trunk_native_vlan')
432
- end
433
-
434
- def switchport_private_vlan_association_trunk
435
- config_get('DEPRECATED',
436
- 'switchport_private_vlan_association_trunk',
437
- name: @name)
438
- end
439
-
440
- def switchport_private_vlan_association_trunk=(vlans)
441
- deprecation_warning(__method__, 'switchport_pvlan_trunk_association')
442
- fail TypeError unless vlans.is_a?(Array) || vlans.empty?
443
- Feature.private_vlan_enable
444
- switchport_enable unless switchport
445
- if vlans == default_switchport_private_vlan_association_trunk
446
- config_set('DEPRECATED', 'switchport_private_vlan_association_trunk',
447
- name: @name, state: 'no',
448
- vlan_pr: '', vlan: '')
449
- else
450
- is_list = switchport_private_vlan_association_trunk
451
- configure_private_vlan_trunk_property(:trunk_assoc, vlans,
452
- is_list, vlans[0])
453
- end
454
- end
455
-
456
- def default_switchport_private_vlan_association_trunk
457
- config_get_default('DEPRECATED',
458
- 'switchport_private_vlan_association_trunk')
459
- end
460
-
461
- def switchport_private_vlan_mapping_trunk
462
- config_get('DEPRECATED',
463
- 'switchport_private_vlan_mapping_trunk',
464
- name: @name)
465
- end
466
-
467
- def switchport_private_vlan_mapping_trunk=(vlans)
468
- deprecation_warning(__method__, 'switchport_pvlan_mapping_trunk')
469
- fail TypeError unless vlans.is_a?(Array) || vlans.empty?
470
- Feature.private_vlan_enable
471
- switchport_enable unless switchport
472
- if vlans == default_switchport_private_vlan_mapping_trunk
473
- config_set('DEPRECATED', 'switchport_private_vlan_mapping_trunk',
474
- name: @name, state: 'no',
475
- vlan_pr: '', vlans: '')
476
- else
477
- is_list = switchport_private_vlan_mapping_trunk
478
- configure_private_vlan_trunk_property(:mapping_trunk, vlans,
479
- is_list, vlans[0])
480
- end
481
- end
482
-
483
- def default_switchport_private_vlan_mapping_trunk
484
- config_get_default('DEPRECATED',
485
- 'switchport_private_vlan_mapping_trunk')
486
- end
487
-
488
- def private_vlan_mapping
489
- match = config_get('DEPRECATED',
490
- 'private_vlan_mapping',
491
- name: @name)
492
- match[0].delete!(' ') unless match == default_private_vlan_mapping
493
- match
494
- end
495
-
496
- def private_vlan_mapping=(vlans)
497
- deprecation_warning(__method__, 'pvlan_mapping')
498
- fail TypeError unless vlans.is_a?(Array) || vlans.empty?
499
- Feature.private_vlan_enable
500
- feature_vlan_set(true)
501
- if vlans == default_private_vlan_mapping
502
- config_set('DEPRECATED', 'private_vlan_mapping',
503
- name: @name, state: 'no', vlans: '')
504
- else
505
- is_list = private_vlan_mapping
506
- new_is_list = prepare_array(is_list)
507
- new_vlans = prepare_array(vlans)
508
- configure_private_vlan_host_property(:vlan_mapping, new_vlans,
509
- new_is_list, '')
510
- end
511
- end
512
-
513
- def default_private_vlan_mapping
514
- config_get_default('DEPRECATED',
515
- 'private_vlan_mapping')
516
- end
517
- end # Class
518
- end # Module