cisco_node_utils 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +66 -0
  4. data/Gemfile +1 -0
  5. data/README.md +44 -43
  6. data/bin/.rubocop.yml +18 -0
  7. data/bin/show_running_yang.rb +233 -0
  8. data/cisco_node_utils.gemspec +1 -1
  9. data/docs/README-maintainers.md +1 -0
  10. data/docs/README-utilities.md +14 -0
  11. data/lib/.rubocop.yml +1 -1
  12. data/lib/cisco_node_utils/aaa_authentication_login_service.rb +8 -3
  13. data/lib/cisco_node_utils/aaa_authorization_service.rb +6 -0
  14. data/lib/cisco_node_utils/bfd_global.rb +300 -0
  15. data/lib/cisco_node_utils/bgp.rb +6 -4
  16. data/lib/cisco_node_utils/bgp_af.rb +2 -0
  17. data/lib/cisco_node_utils/bgp_neighbor.rb +14 -0
  18. data/lib/cisco_node_utils/bgp_neighbor_af.rb +4 -1
  19. data/lib/cisco_node_utils/cisco_cmn_utils.rb +126 -0
  20. data/lib/cisco_node_utils/client/client.rb +6 -2
  21. data/lib/cisco_node_utils/client/grpc/client.rb +120 -36
  22. data/lib/cisco_node_utils/client/nxapi/client.rb +6 -2
  23. data/lib/cisco_node_utils/cmd_ref/DEPRECATED.yaml +118 -0
  24. data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +14 -0
  25. data/lib/cisco_node_utils/cmd_ref/bfd_global.yaml +117 -0
  26. data/lib/cisco_node_utils/cmd_ref/bgp.yaml +7 -7
  27. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +7 -0
  28. data/lib/cisco_node_utils/cmd_ref/dhcp_relay_global.yaml +125 -0
  29. data/lib/cisco_node_utils/cmd_ref/feature.yaml +10 -0
  30. data/lib/cisco_node_utils/cmd_ref/interface.yaml +141 -49
  31. data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +44 -0
  32. data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +6 -0
  33. data/lib/cisco_node_utils/cmd_ref/ospf.yaml +6 -0
  34. data/lib/cisco_node_utils/cmd_ref/ospf_area.yaml +91 -0
  35. data/lib/cisco_node_utils/cmd_ref/ospf_area_vlink.yaml +88 -0
  36. data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +0 -3
  37. data/lib/cisco_node_utils/cmd_ref/show_version.yaml +3 -3
  38. data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +39 -15
  39. data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +43 -21
  40. data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +48 -19
  41. data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +0 -0
  42. data/lib/cisco_node_utils/cmd_ref/tacacs_global.yaml +30 -0
  43. data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +18 -6
  44. data/lib/cisco_node_utils/cmd_ref/vdc.yaml +4 -0
  45. data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +1 -0
  46. data/lib/cisco_node_utils/cmd_ref/vlan.yaml +23 -10
  47. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +8 -2
  48. data/lib/cisco_node_utils/cmd_ref/yang.yaml +7 -0
  49. data/lib/cisco_node_utils/cmd_ref/yum.yaml +10 -1
  50. data/lib/cisco_node_utils/constants.rb +8 -1
  51. data/lib/cisco_node_utils/dhcp_relay_global.rb +302 -0
  52. data/lib/cisco_node_utils/exceptions.rb +29 -0
  53. data/lib/cisco_node_utils/feature.rb +28 -0
  54. data/lib/cisco_node_utils/interface.rb +493 -402
  55. data/lib/cisco_node_utils/interface_DEPRECATED.rb +513 -0
  56. data/lib/cisco_node_utils/interface_ospf.rb +126 -0
  57. data/lib/cisco_node_utils/interface_portchannel.rb +16 -0
  58. data/lib/cisco_node_utils/logger.rb +3 -0
  59. data/lib/cisco_node_utils/node.rb +29 -1
  60. data/lib/cisco_node_utils/overlay_global.rb +1 -12
  61. data/lib/cisco_node_utils/pim.rb +1 -0
  62. data/lib/cisco_node_utils/pim_group_list.rb +1 -0
  63. data/lib/cisco_node_utils/pim_rp_address.rb +1 -0
  64. data/lib/cisco_node_utils/platform.rb +9 -2
  65. data/lib/cisco_node_utils/router_ospf.rb +1 -1
  66. data/lib/cisco_node_utils/router_ospf_area.rb +416 -0
  67. data/lib/cisco_node_utils/router_ospf_area_vlink.rb +313 -0
  68. data/lib/cisco_node_utils/router_ospf_vrf.rb +17 -0
  69. data/lib/cisco_node_utils/snmp_notification_receiver.rb +27 -9
  70. data/lib/cisco_node_utils/snmpcommunity.rb +34 -8
  71. data/lib/cisco_node_utils/snmpserver.rb +4 -4
  72. data/lib/cisco_node_utils/snmpuser.rb +0 -0
  73. data/lib/cisco_node_utils/tacacs_global.rb +102 -0
  74. data/lib/cisco_node_utils/tacacs_server.rb +8 -7
  75. data/lib/cisco_node_utils/vdc.rb +25 -7
  76. data/lib/cisco_node_utils/version.rb +1 -1
  77. data/lib/cisco_node_utils/vlan.rb +30 -56
  78. data/lib/cisco_node_utils/vlan_DEPRECATED.rb +108 -0
  79. data/lib/cisco_node_utils/yang.rb +160 -0
  80. data/lib/cisco_node_utils/yum.rb +25 -32
  81. data/tests/.rubocop.yml +3 -0
  82. data/tests/ciscotest.rb +136 -19
  83. data/tests/cmd_config_invalid.yaml +1 -1
  84. data/tests/noop.rb +7 -0
  85. data/tests/tacacs_server.yaml.example +6 -0
  86. data/tests/test_aaa_authentication_login.rb +24 -1
  87. data/tests/test_aaa_authentication_login_service.rb +9 -16
  88. data/tests/test_aaa_authorization_service.rb +111 -84
  89. data/tests/test_bfd_global.rb +278 -0
  90. data/tests/test_bgp_neighbor.rb +20 -0
  91. data/tests/test_bridge_domain_vni.rb +2 -9
  92. data/tests/test_cmn_utils.rb +76 -0
  93. data/tests/test_dhcp_relay_global.rb +284 -0
  94. data/tests/test_dns_domain.rb +4 -4
  95. data/tests/test_domain_name.rb +2 -2
  96. data/tests/test_encapsulation.rb +2 -4
  97. data/tests/test_evpn_vni.rb +14 -7
  98. data/tests/test_fabricpath_global.rb +12 -13
  99. data/tests/test_feature.rb +35 -17
  100. data/tests/test_interface.rb +352 -127
  101. data/tests/test_interface_bdi.rb +2 -2
  102. data/tests/test_interface_channel_group.rb +1 -1
  103. data/tests/test_interface_ospf.rb +153 -23
  104. data/tests/test_interface_portchannel.rb +15 -6
  105. data/tests/test_interface_private_vlan.rb +200 -576
  106. data/tests/test_interface_svi.rb +5 -52
  107. data/tests/test_interface_switchport.rb +80 -240
  108. data/tests/test_itd_device_group.rb +2 -2
  109. data/tests/test_itd_device_group_node.rb +2 -2
  110. data/tests/test_itd_service.rb +1 -1
  111. data/tests/test_name_server.rb +3 -3
  112. data/tests/test_node_ext.rb +15 -17
  113. data/tests/test_ntp_config.rb +1 -1
  114. data/tests/test_ntp_server.rb +3 -3
  115. data/tests/test_nxapi.rb +1 -0
  116. data/tests/test_overlay_global.rb +15 -19
  117. data/tests/test_pim.rb +5 -5
  118. data/tests/test_pim_group_list.rb +1 -37
  119. data/tests/test_pim_rp_address.rb +1 -1
  120. data/tests/test_platform.rb +9 -11
  121. data/tests/test_portchannel_global.rb +43 -3
  122. data/tests/test_radius_server.rb +1 -1
  123. data/tests/test_radius_server_group.rb +1 -1
  124. data/tests/test_router_bgp.rb +17 -30
  125. data/tests/test_router_ospf_area.rb +433 -0
  126. data/tests/test_router_ospf_area_vlink.rb +298 -0
  127. data/tests/test_router_ospf_vrf.rb +17 -0
  128. data/tests/test_snmp_notification_receiver.rb +11 -11
  129. data/tests/test_snmpcommunity.rb +177 -69
  130. data/tests/test_snmpgroup.rb +7 -7
  131. data/tests/test_snmpserver.rb +164 -253
  132. data/tests/test_snmpuser.rb +73 -69
  133. data/tests/test_stp_global.rb +15 -15
  134. data/tests/test_syslog_settings.rb +1 -1
  135. data/tests/test_tacacs_global.rb +80 -0
  136. data/tests/test_tacacs_server.rb +129 -51
  137. data/tests/test_tacacs_server_group.rb +3 -29
  138. data/tests/test_tacacs_server_host.rb +24 -27
  139. data/tests/test_vlan.rb +57 -59
  140. data/tests/test_vlan_private.rb +271 -284
  141. data/tests/test_vpc.rb +10 -4
  142. data/tests/test_vrf.rb +2 -0
  143. data/tests/test_vrf_af.rb +2 -5
  144. data/tests/test_vtp.rb +5 -2
  145. data/tests/test_vxlan_vtep.rb +20 -44
  146. data/tests/test_vxlan_vtep_vni.rb +23 -16
  147. data/tests/test_yang.rb +369 -0
  148. data/tests/test_yum.rb +34 -42
  149. data/tests/yum_package.yaml +35 -0
  150. metadata +31 -4
  151. data/tests/test_vlan_mt_full.rb +0 -85
@@ -39,9 +39,9 @@ module Cisco
39
39
  def location=(location)
40
40
  fail TypeError unless location.is_a?(String)
41
41
  if location.empty?
42
- config_set('snmp_server', 'location', 'no', '')
42
+ config_set('snmp_server', 'location', state: 'no', location: '')
43
43
  else
44
- config_set('snmp_server', 'location', '', location)
44
+ config_set('snmp_server', 'location', state: '', location: location)
45
45
  end
46
46
  end
47
47
 
@@ -57,9 +57,9 @@ module Cisco
57
57
  def contact=(contact)
58
58
  fail TypeError unless contact.is_a?(String)
59
59
  if contact.empty?
60
- config_set('snmp_server', 'contact', 'no', '')
60
+ config_set('snmp_server', 'contact', state: 'no', contact: '')
61
61
  else
62
- config_set('snmp_server', 'contact', '', contact)
62
+ config_set('snmp_server', 'contact', state: '', contact: contact)
63
63
  end
64
64
  end
65
65
 
File without changes
@@ -0,0 +1,102 @@
1
+ # Tacacs Global provider class
2
+
3
+ # TP HONEY et al., June 2014-2016
4
+
5
+ # Copyright (c) 2014-2016 Cisco and/or its affiliates.
6
+
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require_relative 'node_util'
20
+
21
+ # Tacacs Global configuration management
22
+ module Cisco
23
+ TACACS_GLOVAL_ENC_NONE = 0
24
+ TACACS_GLOBAL_ENC_CISCO_TYPE_7 = 7
25
+ TACACS_GLOBAL_ENC_UNKNOWN = 8
26
+
27
+ # TacacsGlobal - node utility class for
28
+ class TacacsGlobal < NodeUtil
29
+ attr_reader :name
30
+
31
+ def initialize(name)
32
+ fail TypeError unless name.is_a?(String)
33
+ fail ArgumentError,
34
+ "This provider only accepts an id of 'default'" \
35
+ unless name.eql?('default')
36
+ Feature.tacacs_enable unless Feature.tacacs_enabled?
37
+ @name = name
38
+ end
39
+
40
+ def self.tacacs_global
41
+ hash = {}
42
+ hash['default'] = TacacsGlobal.new('default')
43
+ hash
44
+ end
45
+
46
+ def ==(other)
47
+ name == other.name
48
+ end
49
+
50
+ def timeout
51
+ config_get('tacacs_global', 'timeout')
52
+ end
53
+
54
+ def default_timeout
55
+ config_get_default('tacacs_global', 'timeout')
56
+ end
57
+
58
+ def timeout=(val)
59
+ unless val.nil?
60
+ fail ArgumentError, 'timeout must be an Integer' \
61
+ unless val.is_a?(Integer)
62
+ end
63
+
64
+ if val.nil?
65
+ config_set('tacacs_global',
66
+ 'timeout',
67
+ state: 'no',
68
+ timeout: timeout)
69
+ else
70
+ config_set('tacacs_global',
71
+ 'timeout',
72
+ state: '',
73
+ timeout: val)
74
+ end
75
+ end
76
+
77
+ def key_format
78
+ match = config_get('tacacs_global', 'key_format')
79
+ match.nil? ? TACACS_GLOBAL_ENC_UNKNOWN : match[0].to_i
80
+ end
81
+
82
+ def key
83
+ match = config_get('tacacs_global', 'key')
84
+ match.empty? ? TacacsGlobal.default_key : match[1]
85
+ end
86
+
87
+ # Get default encryption password
88
+ def self.default_key
89
+ config_get_default('tacacs_global', 'key')
90
+ end
91
+
92
+ def encryption_key_set(key_format, key)
93
+ if key_format == TACACS_GLOBAL_ENC_UNKNOWN
94
+ config_set('tacacs_server', 'encryption', state: 'no',
95
+ option: key_format, key: key)
96
+ else
97
+ config_set('tacacs_server', 'encryption', state: '', option: key_format,
98
+ key: key)
99
+ end
100
+ end
101
+ end # class
102
+ end # module
@@ -39,12 +39,12 @@ module Cisco
39
39
 
40
40
  # Enable tacacs_server feature
41
41
  def enable
42
- config_set('tacacs_server', 'feature', '')
42
+ config_set('tacacs_server', 'feature', '') unless platform == :ios_xr
43
43
  end
44
44
 
45
45
  # Disable tacacs_server feature
46
46
  def destroy
47
- config_set('tacacs_server', 'feature', 'no')
47
+ config_set('tacacs_server', 'feature', 'no') unless platform == :ios_xr
48
48
  end
49
49
 
50
50
  # --------------------
@@ -55,7 +55,7 @@ module Cisco
55
55
  def timeout=(timeout)
56
56
  # 'no tacacs timeout' will fail.
57
57
  # Just set it to the requested timeout value.
58
- config_set('tacacs_server', 'timeout', '', timeout)
58
+ config_set('tacacs_server', 'timeout', state: '', timeout: timeout)
59
59
  end
60
60
 
61
61
  # Get timeout
@@ -162,12 +162,13 @@ module Cisco
162
162
  # need to unset it. Otherwise the box is not configured with key, we
163
163
  # don't need to do anything
164
164
  if encryption_type != TACACS_SERVER_ENC_UNKNOWN
165
- config_set('tacacs_server', 'encryption', 'no',
166
- encryption_type,
167
- encryption_password)
165
+ config_set('tacacs_server', 'encryption', state: 'no',
166
+ option: encryption_type,
167
+ key: encryption_password)
168
168
  end
169
169
  else
170
- config_set('tacacs_server', 'encryption', '', enctype, password)
170
+ config_set('tacacs_server', 'encryption', state: '', option: enctype,
171
+ key: password)
171
172
  end
172
173
  end
173
174
  end
@@ -65,6 +65,12 @@ module Cisco
65
65
  # PROPERTIES #
66
66
  ########################################################
67
67
 
68
+ def allocate_interface
69
+ # TBD: This property is only partially implemented because it is currently
70
+ # only used for minitest & beaker.
71
+ config_get('vdc', 'allocate_interface', vdc: @vdc)
72
+ end
73
+
68
74
  def limit_resource_module_type
69
75
  str = config_get('vdc', 'limit_resource_module_type', vdc: @vdc)
70
76
  str.strip! unless str.nil?
@@ -72,13 +78,25 @@ module Cisco
72
78
 
73
79
  def limit_resource_module_type=(mods)
74
80
  state = mods.empty? ? 'no' : ''
75
- config_set('vdc', 'limit_resource_module_type',
76
- state: state, vdc: @vdc, mods: mods)
77
-
78
- # TBD: No interfaces are allocated after changing the module-type
79
- # so 'allocate' is needed to make this useful. Consider moving
80
- # this into it's own property.
81
- config_set('vdc', 'allocate_interface_unallocated', vdc: @vdc)
81
+ begin
82
+ # limit-resource commands are time-consuming and process in the
83
+ # background. Back-to-back LR commands may fail if processed too
84
+ # quickly.
85
+ config_set('vdc', 'limit_resource_module_type',
86
+ state: state, vdc: @vdc, mods: mods)
87
+
88
+ # TBD: No interfaces are allocated after changing the module-type
89
+ # so 'allocate' is needed to make this useful. Consider moving
90
+ # this into it's own property.
91
+ config_set('vdc', 'allocate_interface_unallocated', vdc: @vdc)
92
+
93
+ rescue CliError => e
94
+ count ||= 1
95
+ if e.message[/VDC is not in active state/] && (count += 1) < 10
96
+ retry
97
+ end
98
+ raise
99
+ end
82
100
  end
83
101
 
84
102
  def default_limit_resource_module_type
@@ -14,7 +14,7 @@
14
14
 
15
15
  # Container module for version number only.
16
16
  module CiscoNodeUtils
17
- VERSION = '1.3.0'
17
+ VERSION = '1.4.0'
18
18
  gem_version = Gem::Version.new(Gem::VERSION)
19
19
  min_gem_version = Gem::Version.new('2.1.0')
20
20
  fail 'Required rubygems version >= 2.1.0' if gem_version < min_gem_version
@@ -19,13 +19,14 @@ require_relative 'node_util'
19
19
  require_relative 'interface'
20
20
  require_relative 'fabricpath_global'
21
21
  require_relative 'feature'
22
+ require_relative 'vlan_DEPRECATED'
22
23
 
23
24
  # Add some Vlan-specific constants to the Cisco namespace
24
25
  module Cisco
25
26
  VLAN_NAME_SIZE = 33
26
27
 
27
28
  # Vlan - node utility class for VLAN configuration management
28
- class Vlan < NodeUtil
29
+ class Vlan < Cisco::VlanDeprecated
29
30
  attr_reader :vlan_id
30
31
 
31
32
  def initialize(vlan_id, instantiate=true)
@@ -221,7 +222,13 @@ module Cisco
221
222
  config_get('vlan', 'mapped_vni', vlan: @vlan_id)
222
223
  end
223
224
 
225
+ def requires_nv_overlay?
226
+ config_get('vlan', 'mapped_vni_requires_nv_overlay')
227
+ end
228
+
224
229
  def mapped_vni=(vni)
230
+ # Some platforms require feature nv_overlay to be enabled first.
231
+ Feature.nv_overlay_enable if requires_nv_overlay?
225
232
  Feature.vn_segment_vlan_based_enable
226
233
  # Remove the existing mapping first as cli doesn't support overwriting.
227
234
  config_set('vlan', 'mapped_vni', vlan: @vlan_id,
@@ -236,93 +243,60 @@ module Cisco
236
243
  config_get_default('vlan', 'mapped_vni')
237
244
  end
238
245
 
239
- def private_vlan_type
246
+ def pvlan_type
240
247
  return nil unless Feature.private_vlan_enabled?
241
- config_get('vlan', 'private_vlan_type', id: @vlan_id)
248
+ config_get('vlan', 'pvlan_type', id: @vlan_id)
242
249
  end
243
250
 
244
- def private_vlan_type=(type)
251
+ def pvlan_type=(type)
245
252
  Feature.private_vlan_enable
246
253
  fail TypeError unless type && type.is_a?(String)
247
254
 
248
- if type == default_private_vlan_type
249
- return if private_vlan_type.empty?
250
- set_args_keys(state: 'no', type: private_vlan_type)
255
+ if type == default_pvlan_type
256
+ return if pvlan_type.empty?
257
+ set_args_keys(state: 'no', type: pvlan_type)
251
258
  ignore_msg = 'Warning: Private-VLAN CLI removed'
252
259
  else
253
260
  set_args_keys(state: '', type: type)
254
261
  ignore_msg = 'Warning: Private-VLAN CLI entered'
255
262
  end
256
- result = config_set('vlan', 'private_vlan_type', @set_args)
263
+ result = config_set('vlan', 'pvlan_type', @set_args)
257
264
  cli_error_check(result, ignore_msg)
258
265
  end
259
266
 
260
- def default_private_vlan_type
261
- config_get_default('vlan', 'private_vlan_type')
267
+ def default_pvlan_type
268
+ config_get_default('vlan', 'pvlan_type')
262
269
  end
263
270
 
264
- def private_vlan_association
271
+ def pvlan_association
265
272
  return nil unless Feature.private_vlan_enabled?
266
- config_get('vlan', 'private_vlan_association', id: @vlan_id)
273
+ range = config_get('vlan', 'pvlan_association', id: @vlan_id)
274
+ Utils.normalize_range_array(range)
267
275
  end
268
276
 
269
- def private_vlan_association=(vlan_list)
277
+ def pvlan_association=(range)
270
278
  Feature.private_vlan_enable
271
- vlan_list_delta(private_vlan_association, vlan_list)
279
+ is = Utils.dash_range_to_elements(pvlan_association)
280
+ should = Utils.dash_range_to_elements(range)
281
+ association_delta(is, should)
272
282
  end
273
283
 
274
284
  def default_private_vlan_association
275
- config_get_default('vlan', 'private_vlan_association')
285
+ config_get_default('vlan', 'pvlan_association')
276
286
  end
277
287
 
278
288
  # --------------------------
279
- # vlan_list_delta is a helper function for the private_vlan_association
289
+ # association_delta is a helper function for the pvlan_association
280
290
  # property. It walks the delta hash and adds/removes each target private
281
291
  # vlan.
282
- # This api is used by private vlan to prepare the input to the setter
283
- # method. The input can be in the following formats for vlans:
284
- # 10-12,14. Prepare_array api is transforming this input into a flat array.
285
- # In the example above the returned array will be 10, 11, 12, 14. Prepare
286
- # array is first splitting the input on ',' and the than expanding the vlan
287
- # range element like 10-12 into a flat array. The final result will
288
- # be a flat array.
289
- # This way we can later used the lib utility to check the delta from
290
- # the input vlan value and the vlan configured to apply the right config.
291
-
292
- def vlan_list_delta(is_list, should_list)
293
- new_list = []
294
- should_list.each do |item|
295
- if item.include?(',')
296
- new_list.push(item.split(','))
297
- else
298
- new_list.push(item)
299
- end
300
- end
301
- new_list.flatten!
302
- new_list.sort!
303
-
304
- new_list.each { |item| item.gsub!('-', '..') }
305
-
306
- should_list_new = []
307
- new_list.each do |elem|
308
- if elem.include?('..')
309
- elema = elem.split('..').map { |d| Integer(d) }
310
- elema.sort!
311
- tr = elema[0]..elema[1]
312
- tr.to_a.each do |item|
313
- should_list_new.push(item.to_s)
314
- end
315
- else
316
- should_list_new.push(elem)
317
- end
318
- end
319
-
320
- delta_hash = Utils.delta_add_remove(should_list_new, is_list)
292
+ def association_delta(is, should)
293
+ delta_hash = Utils.delta_add_remove(should, is)
294
+ Cisco::Logger.debug("association_delta: #{@vlan_id}: #{delta_hash}")
321
295
  [:add, :remove].each do |action|
322
296
  delta_hash[action].each do |vlans|
323
297
  state = (action == :add) ? '' : 'no'
324
298
  set_args_keys(state: state, vlans: vlans)
325
- result = config_set('vlan', 'private_vlan_association', @set_args)
299
+ result = config_set('vlan', 'pvlan_association', @set_args)
326
300
  cli_error_check(result)
327
301
  end
328
302
  end
@@ -0,0 +1,108 @@
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
+ module Cisco
28
+ # Vlan - node utility class for VLAN configuration management
29
+ class VlanDeprecated < NodeUtil
30
+ def deprecation_warning(method, new_prop=nil)
31
+ if new_prop.nil?
32
+ new_prop = ''
33
+ else
34
+ new_prop = "The new property name is '#{new_prop}'"
35
+ end
36
+
37
+ warn "
38
+ #########################################################################
39
+ WARNING: Method '#{method.to_s.delete('=')}'
40
+ is deprecated and should not be used.
41
+ #{new_prop}
42
+ #########################################################################
43
+ "
44
+ end
45
+
46
+ def private_vlan_type
47
+ return nil unless Feature.private_vlan_enabled?
48
+ config_get('DEPRECATED', 'private_vlan_type', id: @vlan_id)
49
+ end
50
+
51
+ def private_vlan_type=(type)
52
+ deprecation_warning(__method__, 'pvlan_type')
53
+ Feature.private_vlan_enable
54
+ fail TypeError unless type && type.is_a?(String)
55
+
56
+ if type == default_private_vlan_type
57
+ return if private_vlan_type.empty?
58
+ set_args_keys(state: 'no', type: private_vlan_type)
59
+ ignore_msg = 'Warning: Private-VLAN CLI removed'
60
+ else
61
+ set_args_keys(state: '', type: type)
62
+ ignore_msg = 'Warning: Private-VLAN CLI entered'
63
+ end
64
+ result = config_set('DEPRECATED', 'private_vlan_type', @set_args)
65
+ cli_error_check(result, ignore_msg)
66
+ end
67
+
68
+ def default_private_vlan_type
69
+ config_get_default('DEPRECATED', 'private_vlan_type')
70
+ end
71
+
72
+ def private_vlan_association
73
+ return nil unless Feature.private_vlan_enabled?
74
+ range = config_get('DEPRECATED', 'private_vlan_association', id: @vlan_id)
75
+ Utils.normalize_range_array(range)
76
+ end
77
+
78
+ def private_vlan_association=(range)
79
+ deprecation_warning(__method__, 'pvlan_association')
80
+ Feature.private_vlan_enable
81
+ is = Utils.dash_range_to_elements(private_vlan_association)
82
+ should = Utils.dash_range_to_elements(range)
83
+ association_delta(is, should)
84
+ end
85
+
86
+ def default_private_vlan_association
87
+ config_get_default('DEPRECATED', 'private_vlan_association')
88
+ end
89
+
90
+ # --------------------------
91
+ # association_delta is a helper function for the private_vlan_association
92
+ # property. It walks the delta hash and adds/removes each target private
93
+ # vlan.
94
+ def association_delta(is, should)
95
+ delta_hash = Utils.delta_add_remove(should, is)
96
+ Cisco::Logger.debug("association_delta: #{@vlan_id}: #{delta_hash}")
97
+ [:add, :remove].each do |action|
98
+ delta_hash[action].each do |vlans|
99
+ state = (action == :add) ? '' : 'no'
100
+ set_args_keys(state: state, vlans: vlans)
101
+ result = config_set('DEPRECATED',
102
+ 'private_vlan_association', @set_args)
103
+ cli_error_check(result)
104
+ end
105
+ end
106
+ end
107
+ end # Class
108
+ end # Module