cisco_node_utils 1.1.0 → 1.2.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 (202) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/CHANGELOG.md +126 -1
  4. data/README.md +19 -12
  5. data/Rakefile +1 -0
  6. data/bin/git/hooks/commit-msg/enforce_style +8 -0
  7. data/cisco_node_utils.gemspec +4 -3
  8. data/docs/README-develop-best-practices.md +127 -109
  9. data/docs/README-develop-node-utils-APIs.md +47 -39
  10. data/docs/template-router.rb +3 -7
  11. data/lib/.rubocop.yml +4 -4
  12. data/lib/cisco_node_utils.rb +1 -1
  13. data/lib/cisco_node_utils/aaa_authentication_login.rb +96 -0
  14. data/lib/cisco_node_utils/aaa_authentication_login_service.rb +133 -0
  15. data/lib/cisco_node_utils/aaa_authorization_service.rb +150 -0
  16. data/lib/cisco_node_utils/ace.rb +196 -0
  17. data/lib/cisco_node_utils/acl.rb +100 -0
  18. data/lib/cisco_node_utils/bgp.rb +301 -163
  19. data/lib/cisco_node_utils/bgp_af.rb +187 -19
  20. data/lib/cisco_node_utils/bgp_neighbor.rb +18 -33
  21. data/lib/cisco_node_utils/bgp_neighbor_af.rb +25 -48
  22. data/lib/cisco_node_utils/cisco_cmn_utils.rb +23 -4
  23. data/lib/cisco_node_utils/cmd_ref/README_YAML.md +593 -0
  24. data/lib/cisco_node_utils/cmd_ref/aaa_auth_login_service.yaml +22 -0
  25. data/lib/cisco_node_utils/cmd_ref/aaa_authentication_login.yaml +31 -0
  26. data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +22 -0
  27. data/lib/cisco_node_utils/cmd_ref/acl.yaml +43 -0
  28. data/lib/cisco_node_utils/cmd_ref/bgp.yaml +242 -0
  29. data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +164 -0
  30. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +131 -0
  31. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +179 -0
  32. data/lib/cisco_node_utils/cmd_ref/dnsclient.yaml +34 -0
  33. data/lib/cisco_node_utils/cmd_ref/evpn_vni.yaml +42 -0
  34. data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +172 -0
  35. data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +35 -0
  36. data/lib/cisco_node_utils/cmd_ref/feature.yaml +42 -0
  37. data/lib/cisco_node_utils/cmd_ref/fex.yaml +9 -0
  38. data/lib/cisco_node_utils/cmd_ref/images.yaml +7 -0
  39. data/lib/cisco_node_utils/cmd_ref/interface.yaml +339 -0
  40. data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +28 -0
  41. data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +61 -0
  42. data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +54 -0
  43. data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +32 -0
  44. data/lib/cisco_node_utils/cmd_ref/inventory.yaml +45 -0
  45. data/lib/cisco_node_utils/cmd_ref/memory.yaml +13 -0
  46. data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +7 -0
  47. data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +14 -0
  48. data/lib/cisco_node_utils/cmd_ref/ospf.yaml +74 -0
  49. data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +33 -0
  50. data/lib/cisco_node_utils/cmd_ref/pim.yaml +40 -0
  51. data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +69 -0
  52. data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +25 -0
  53. data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +64 -0
  54. data/lib/cisco_node_utils/cmd_ref/radius_server_group.yaml +14 -0
  55. data/lib/cisco_node_utils/cmd_ref/show_system.yaml +5 -0
  56. data/lib/cisco_node_utils/cmd_ref/show_version.yaml +72 -0
  57. data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +23 -0
  58. data/lib/cisco_node_utils/cmd_ref/snmp_group.yaml +7 -0
  59. data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +50 -0
  60. data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +51 -0
  61. data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +55 -0
  62. data/lib/cisco_node_utils/cmd_ref/snmpnotification.yaml +11 -0
  63. data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +18 -0
  64. data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +7 -0
  65. data/lib/cisco_node_utils/cmd_ref/system.yaml +6 -0
  66. data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +49 -0
  67. data/lib/cisco_node_utils/cmd_ref/tacacs_server_group.yaml +33 -0
  68. data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +35 -0
  69. data/lib/cisco_node_utils/cmd_ref/vdc.yaml +38 -0
  70. data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +6 -0
  71. data/lib/cisco_node_utils/cmd_ref/vlan.yaml +56 -0
  72. data/lib/cisco_node_utils/cmd_ref/vni.yaml +76 -0
  73. data/lib/cisco_node_utils/cmd_ref/vpc.yaml +197 -0
  74. data/lib/cisco_node_utils/cmd_ref/vrf.yaml +88 -0
  75. data/lib/cisco_node_utils/cmd_ref/vtp.yaml +38 -0
  76. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +60 -0
  77. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +39 -0
  78. data/lib/cisco_node_utils/cmd_ref/yum.yaml +13 -0
  79. data/lib/cisco_node_utils/command_reference.rb +359 -187
  80. data/lib/cisco_node_utils/configparser_lib.rb +1 -1
  81. data/lib/cisco_node_utils/dns_domain.rb +19 -5
  82. data/lib/cisco_node_utils/domain_name.rb +4 -8
  83. data/lib/cisco_node_utils/evpn_vni.rb +157 -0
  84. data/lib/cisco_node_utils/fabricpath_global.rb +388 -0
  85. data/lib/cisco_node_utils/fabricpath_topology.rb +150 -0
  86. data/lib/cisco_node_utils/feature.rb +111 -0
  87. data/lib/cisco_node_utils/interface.rb +390 -97
  88. data/lib/cisco_node_utils/interface_channel_group.rb +124 -0
  89. data/lib/cisco_node_utils/interface_ospf.rb +11 -34
  90. data/lib/cisco_node_utils/interface_portchannel.rb +157 -0
  91. data/lib/cisco_node_utils/interface_service_vni.rb +132 -0
  92. data/lib/cisco_node_utils/name_server.rb +1 -1
  93. data/lib/cisco_node_utils/node.rb +55 -249
  94. data/lib/cisco_node_utils/node_util.rb +5 -1
  95. data/lib/cisco_node_utils/ntp_config.rb +2 -2
  96. data/lib/cisco_node_utils/ntp_server.rb +14 -5
  97. data/lib/cisco_node_utils/overlay_global.rb +153 -0
  98. data/lib/cisco_node_utils/pim.rb +124 -0
  99. data/lib/cisco_node_utils/pim_group_list.rb +108 -0
  100. data/lib/cisco_node_utils/pim_rp_address.rb +102 -0
  101. data/lib/cisco_node_utils/platform.rb +8 -9
  102. data/lib/cisco_node_utils/portchannel_global.rb +277 -0
  103. data/lib/cisco_node_utils/radius_global.rb +9 -19
  104. data/lib/cisco_node_utils/radius_server.rb +31 -41
  105. data/lib/cisco_node_utils/radius_server_group.rb +117 -0
  106. data/lib/cisco_node_utils/router_ospf.rb +1 -1
  107. data/lib/cisco_node_utils/router_ospf_vrf.rb +14 -19
  108. data/lib/cisco_node_utils/snmp_notification_receiver.rb +158 -0
  109. data/lib/cisco_node_utils/snmpcommunity.rb +3 -5
  110. data/lib/cisco_node_utils/snmpgroup.rb +1 -1
  111. data/lib/cisco_node_utils/snmpnotification.rb +57 -0
  112. data/lib/cisco_node_utils/snmpserver.rb +8 -17
  113. data/lib/cisco_node_utils/snmpuser.rb +67 -28
  114. data/lib/cisco_node_utils/syslog_server.rb +3 -9
  115. data/lib/cisco_node_utils/syslog_settings.rb +2 -10
  116. data/lib/cisco_node_utils/tacacs_server.rb +9 -14
  117. data/lib/cisco_node_utils/tacacs_server_group.rb +145 -0
  118. data/lib/cisco_node_utils/tacacs_server_host.rb +5 -9
  119. data/lib/cisco_node_utils/vdc.rb +88 -0
  120. data/lib/cisco_node_utils/version.rb +5 -2
  121. data/lib/cisco_node_utils/vlan.rb +71 -8
  122. data/lib/cisco_node_utils/vni.rb +227 -0
  123. data/lib/cisco_node_utils/vpc.rb +377 -0
  124. data/lib/cisco_node_utils/vrf.rb +60 -9
  125. data/lib/cisco_node_utils/vrf_af.rb +191 -0
  126. data/lib/cisco_node_utils/vtp.rb +8 -6
  127. data/lib/cisco_node_utils/vxlan_vtep.rb +151 -0
  128. data/lib/cisco_node_utils/vxlan_vtep_vni.rb +234 -0
  129. data/lib/cisco_node_utils/yum.rb +1 -1
  130. data/tests/.rubocop.yml +1 -1
  131. data/tests/basetest.rb +16 -7
  132. data/tests/ciscotest.rb +55 -13
  133. data/tests/cmd_config.yaml +2 -2
  134. data/tests/platform_info.rb +3 -2
  135. data/tests/test_aaa_authentication_login.rb +219 -0
  136. data/tests/test_aaa_authentication_login_service.rb +759 -0
  137. data/tests/test_aaa_authorization_service.rb +1041 -0
  138. data/tests/test_ace.rb +160 -0
  139. data/tests/test_acl.rb +176 -0
  140. data/tests/test_bgp_af.rb +269 -13
  141. data/tests/test_bgp_neighbor.rb +38 -40
  142. data/tests/test_bgp_neighbor_af.rb +92 -32
  143. data/tests/test_command_config.rb +5 -5
  144. data/tests/test_command_reference.rb +284 -101
  145. data/tests/test_dns_domain.rb +1 -1
  146. data/tests/test_domain_name.rb +1 -1
  147. data/tests/test_evpn_vni.rb +106 -0
  148. data/tests/test_fabricpath_global.rb +243 -0
  149. data/tests/test_fabricpath_topology.rb +98 -0
  150. data/tests/test_interface.rb +292 -74
  151. data/tests/test_interface_channel_group.rb +74 -0
  152. data/tests/test_interface_ospf.rb +9 -4
  153. data/tests/test_interface_portchannel.rb +105 -0
  154. data/tests/test_interface_service_vni.rb +232 -0
  155. data/tests/test_interface_svi.rb +77 -62
  156. data/tests/test_interface_switchport.rb +17 -5
  157. data/tests/test_name_server.rb +1 -1
  158. data/tests/test_node.rb +1 -1
  159. data/tests/test_node_ext.rb +10 -20
  160. data/tests/test_ntp_config.rb +1 -1
  161. data/tests/test_ntp_server.rb +18 -6
  162. data/tests/test_overlay_global.rb +102 -0
  163. data/tests/test_pim.rb +177 -0
  164. data/tests/test_pim_group_list.rb +181 -0
  165. data/tests/test_pim_rp_address.rb +153 -0
  166. data/tests/test_platform.rb +3 -3
  167. data/tests/test_portchannel_global.rb +202 -0
  168. data/tests/test_radius_global.rb +1 -1
  169. data/tests/test_radius_server.rb +92 -57
  170. data/tests/test_radius_server_group.rb +149 -0
  171. data/tests/test_router_bgp.rb +283 -112
  172. data/tests/test_router_ospf.rb +2 -2
  173. data/tests/test_router_ospf_vrf.rb +4 -4
  174. data/tests/test_snmp_notification_receiver.rb +167 -0
  175. data/tests/test_snmpcommunity.rb +1 -1
  176. data/tests/test_snmpgroup.rb +1 -1
  177. data/tests/test_snmpnotification.rb +72 -0
  178. data/tests/test_snmpserver.rb +29 -105
  179. data/tests/test_snmpuser.rb +32 -30
  180. data/tests/test_syslog_server.rb +36 -10
  181. data/tests/test_syslog_settings.rb +1 -1
  182. data/tests/test_tacacs_server.rb +1 -1
  183. data/tests/test_tacacs_server_group.rb +405 -0
  184. data/tests/test_tacacs_server_host.rb +1 -1
  185. data/tests/test_vdc.rb +78 -0
  186. data/tests/test_vlan.rb +74 -19
  187. data/tests/test_vlan_mt_full.rb +95 -0
  188. data/tests/test_vni.rb +106 -0
  189. data/tests/test_vpc.rb +361 -0
  190. data/tests/test_vrf.rb +172 -29
  191. data/tests/test_vtp.rb +1 -1
  192. data/tests/test_vxlan_vtep.rb +214 -0
  193. data/tests/test_vxlan_vtep_vni.rb +201 -0
  194. data/tests/test_yum.rb +1 -1
  195. metadata +120 -11
  196. data/lib/cisco_node_utils/README_YAML.md +0 -325
  197. data/lib/cisco_node_utils/command_reference_common.yaml +0 -1051
  198. data/lib/cisco_node_utils/command_reference_common_bgp.yaml +0 -535
  199. data/lib/cisco_node_utils/command_reference_n3064.yaml +0 -13
  200. data/lib/cisco_node_utils/command_reference_n7k.yaml +0 -52
  201. data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -26
  202. data/tests/platform_info.yaml +0 -10
@@ -1,6 +1,6 @@
1
1
  # Alex Hunsberger, March 2015
2
2
  #
3
- # Copyright (c) 2015 Cisco and/or its affiliates.
3
+ # Copyright (c) 2015-2016 Cisco and/or its affiliates.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -53,9 +53,7 @@ module Cisco
53
53
  end
54
54
 
55
55
  def port
56
- p = config_get('tacacs_server_host', 'port', @name)
57
- fail "unable to retrieve port information for #{@name}" if p.nil?
58
- p.first.to_i
56
+ config_get('tacacs_server_host', 'port', @name)
59
57
  end
60
58
 
61
59
  def port=(n)
@@ -68,7 +66,7 @@ module Cisco
68
66
 
69
67
  def encryption_type
70
68
  type = config_get('tacacs_server_host', 'encryption_type', @name)
71
- type.nil? ? TACACS_SERVER_ENC_UNKNOWN : type.first.to_i
69
+ type.nil? ? TACACS_SERVER_ENC_UNKNOWN : type.to_i
72
70
  end
73
71
 
74
72
  def self.default_encryption_type
@@ -76,8 +74,7 @@ module Cisco
76
74
  end
77
75
 
78
76
  def encryption_password
79
- pass = config_get('tacacs_server_host', 'encryption_password', @name)
80
- pass.nil? ? TacacsServerHost.default_encryption_password : pass.first
77
+ config_get('tacacs_server_host', 'encryption_password', @name)
81
78
  end
82
79
 
83
80
  def self.default_encryption_password
@@ -107,8 +104,7 @@ module Cisco
107
104
  end
108
105
 
109
106
  def timeout
110
- t = config_get('tacacs_server_host', 'timeout', @name)
111
- t.nil? ? TacacsServerHost.default_timeout : t.first.to_i
107
+ config_get('tacacs_server_host', 'timeout', @name)
112
108
  end
113
109
 
114
110
  def timeout=(t)
@@ -0,0 +1,88 @@
1
+ #
2
+ # NXAPI implementation of VDC class
3
+ #
4
+ # December 2015, Chris Van Heuveln
5
+ #
6
+ # Copyright (c) 2015-2016 Cisco and/or its affiliates.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+ require_relative 'node_util'
21
+
22
+ module Cisco
23
+ # node_utils class for vdc
24
+ class Vdc < NodeUtil
25
+ attr_reader :name
26
+
27
+ def initialize(name, instantiate=true)
28
+ @vdc = (name == 'default') ? Vdc.default_vdc_name : name
29
+ create if instantiate
30
+ end
31
+
32
+ def self.vdcs
33
+ hash = {}
34
+ vdc_list = config_get('vdc', 'all_vdcs')
35
+ return hash if vdc_list.nil?
36
+
37
+ vdc_list.each do |vdc_name|
38
+ hash[vdc_name] = Vdc.new(vdc_name, false)
39
+ end
40
+ hash
41
+ end
42
+
43
+ def self.vdc_support
44
+ config_get('vdc', 'vdc_support')
45
+ end
46
+
47
+ def self.default_vdc_name
48
+ vdc = config_get('vdc', 'default_vdc_name')
49
+ fail RuntimeError if vdc.nil?
50
+ vdc
51
+ end
52
+
53
+ def create
54
+ fail ArgumentError,
55
+ 'There is currently no support for non-default VDCs' unless
56
+ @vdc == Vdc.default_vdc_name
57
+ # noop for 'default' vdc
58
+ end
59
+
60
+ def ==(other)
61
+ name == other.name
62
+ end
63
+
64
+ ########################################################
65
+ # PROPERTIES #
66
+ ########################################################
67
+
68
+ def limit_resource_module_type
69
+ str = config_get('vdc', 'limit_resource_module_type', vdc: @vdc)
70
+ str.strip! unless str.nil?
71
+ end
72
+
73
+ def limit_resource_module_type=(mods)
74
+ 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)
82
+ end
83
+
84
+ def default_limit_resource_module_type
85
+ config_get_default('vdc', 'limit_resource_module_type')
86
+ end
87
+ end # Class
88
+ end # Module
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2015 Cisco and/or its affiliates.
1
+ # Copyright (c) 2015-2016 Cisco and/or its affiliates.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -14,5 +14,8 @@
14
14
 
15
15
  # Container module for version number only.
16
16
  module CiscoNodeUtils
17
- VERSION = '1.1.0'
17
+ VERSION = '1.2.0'
18
+ gem_version = Gem::Version.new(Gem::VERSION)
19
+ min_gem_version = Gem::Version.new('2.1.0')
20
+ fail 'Required rubygems version >= 2.1.0' if gem_version < min_gem_version
18
21
  end
@@ -1,6 +1,6 @@
1
1
  # Jie Yang, November 2014
2
2
  #
3
- # Copyright (c) 2014-2015 Cisco and/or its affiliates.
3
+ # Copyright (c) 2014-2016 Cisco and/or its affiliates.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
6
6
  # you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
16
16
 
17
17
  require_relative 'node_util'
18
18
  require_relative 'interface'
19
+ require_relative 'fabricpath_global'
19
20
 
20
21
  # Add some Vlan-specific constants to the Cisco namespace
21
22
  module Cisco
@@ -57,13 +58,58 @@ module Cisco
57
58
  # instead just displays a STDOUT error message; thus NXAPI does not detect
58
59
  # the failure and we must catch it by inspecting the "body" hash entry
59
60
  # returned by NXAPI. This vlan cli behavior is unlikely to change.
60
- fail result[2]['body'] unless result[2]['body'].empty?
61
+ fail result[2]['body'] if
62
+ result[2].is_a?(Hash) &&
63
+ /(ERROR:|Warning:)/.match(result[2]['body'].to_s)
64
+
65
+ # Some test environments get result[2] as a string instead of a hash
66
+ fail result[2] if
67
+ result[2].is_a?(String) &&
68
+ /(ERROR:|Warning:)/.match(result[2])
69
+ end
70
+
71
+ def fabricpath_feature
72
+ FabricpathGlobal.fabricpath_feature
73
+ end
74
+
75
+ def fabricpath_feature_set(fabricpath_set)
76
+ FabricpathGlobal.fabricpath_feature_set(fabricpath_set)
77
+ end
78
+
79
+ def mode
80
+ result = config_get('vlan', 'mode', @vlan_id)
81
+ return default_mode if result.nil?
82
+ case result
83
+ when /fabricpath/i
84
+ return 'fabricpath'
85
+ when /ce/i
86
+ return 'ce'
87
+ end
88
+ end
89
+
90
+ def mode=(str)
91
+ str = str.to_s
92
+ if str.empty?
93
+ result = config_set('vlan', 'mode', @vlan_id, 'no', '')
94
+ else
95
+ if 'fabricpath' == str
96
+ fabricpath_feature_set(:enabled) unless
97
+ :enabled == fabricpath_feature
98
+ end
99
+ result = config_set('vlan', 'mode', @vlan_id, '', str)
100
+ end
101
+ cli_error_check(result)
102
+ rescue CliError => e
103
+ raise "[vlan #{@vlan_id}] '#{e.command}' : #{e.clierror}"
104
+ end
105
+
106
+ def default_mode
107
+ config_get_default('vlan', 'mode')
61
108
  end
62
109
 
63
110
  def vlan_name
64
111
  result = config_get('vlan', 'name', @vlan_id)
65
- return default_vlan_name if result.nil?
66
- result.shift
112
+ result.nil? ? default_vlan_name : result
67
113
  end
68
114
 
69
115
  def vlan_name=(str)
@@ -84,8 +130,7 @@ module Cisco
84
130
 
85
131
  def state
86
132
  result = config_get('vlan', 'state', @vlan_id)
87
- return default_state if result.nil?
88
- case result.first
133
+ case result
89
134
  when /act/
90
135
  return 'active'
91
136
  when /sus/
@@ -111,9 +156,8 @@ module Cisco
111
156
 
112
157
  def shutdown
113
158
  result = config_get('vlan', 'shutdown', @vlan_id)
114
- return default_shutdown if result.nil?
115
159
  # Valid result is either: "active"(aka no shutdown) or "shutdown"
116
- result.first[/shut/] ? true : false
160
+ result[/shut/] ? true : false
117
161
  end
118
162
 
119
163
  def shutdown=(val)
@@ -146,5 +190,24 @@ module Cisco
146
190
  end
147
191
  interfaces
148
192
  end
193
+
194
+ def mapped_vni
195
+ config_get('vlan', 'mapped_vni', vlan: @vlan_id)
196
+ end
197
+
198
+ def mapped_vni=(vni)
199
+ Feature.vn_segment_vlan_based_enable
200
+ # Remove the existing mapping first as cli doesn't support overwriting.
201
+ config_set('vlan', 'mapped_vni', vlan: @vlan_id,
202
+ state: 'no', vni: vni)
203
+ # Configure the new mapping
204
+ state = vni == default_mapped_vni ? 'no' : ''
205
+ config_set('vlan', 'mapped_vni', vlan: @vlan_id,
206
+ state: state, vni: vni)
207
+ end
208
+
209
+ def default_mapped_vni
210
+ config_get_default('vlan', 'mapped_vni')
211
+ end
149
212
  end # class
150
213
  end # module
@@ -0,0 +1,227 @@
1
+ # VNI provider class
2
+ #
3
+ # Deepak Cherian, September 2015
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
+ # ----
20
+ # This provider supports both MT-full (N7K) and MT-lite (N3K/N9K),
21
+ # each of which have their own feature requirements and clis.
22
+ #
23
+ # MT-full cli: MT-lite cli:
24
+ # feature nv overlay feature nv overlay
25
+ # feature nvi feature vn-segment-vlan-based
26
+ # system bridge-domain 100-113
27
+ # bridge-domain 100
28
+ # member vni 100
29
+ # vni 10001 vlan 100
30
+ # shutdown vn-segment 10001
31
+ #
32
+ require_relative 'node_util'
33
+ require_relative 'feature'
34
+
35
+ module Cisco
36
+ # node_utils class for Vni
37
+ class Vni < NodeUtil
38
+ attr_reader :name, :vni_id
39
+
40
+ def initialize(vni_id, instantiate=true)
41
+ @vni_id = vni_id.to_s
42
+ fail ArgumentError,
43
+ 'Invalid value(non-numeric VNI id)' unless @vni_id[/^\d+$/]
44
+ create if instantiate
45
+ end
46
+
47
+ def self.vnis
48
+ hash = {}
49
+ vni_list = config_get('vni', 'all_vnis')
50
+ return hash if vni_list.nil?
51
+
52
+ vni_list.each do |id|
53
+ hash[id] = Vni.new(id, false)
54
+ end
55
+ hash
56
+ end
57
+
58
+ # feature vni
59
+ def self.feature_vni_enabled
60
+ config_get('vni', 'feature')
61
+ rescue Cisco::CliError => e
62
+ # cmd will syntax reject when feature is not enabled
63
+ raise unless e.clierror =~ /Syntax error/
64
+ return false
65
+ end
66
+
67
+ def self.feature_vni_enable # TBD: move this to feature.rb
68
+ Feature.nv_overlay_enable
69
+ config_set('vni', 'feature')
70
+ end
71
+
72
+ def self.mt_full_support
73
+ config_get('vni', 'mt_full_support')
74
+ end
75
+
76
+ def self.mt_lite_support
77
+ config_get('vni', 'mt_lite_support')
78
+ end
79
+
80
+ def create
81
+ Vni.feature_vni_enable unless Vni.feature_vni_enabled
82
+ config_set('vni', 'create', vni: @vni_id) if Vni.mt_full_support
83
+ end
84
+
85
+ def destroy
86
+ config_set('vni', 'destroy', vni: @vni_id)
87
+ end
88
+
89
+ def cli_error_check(result)
90
+ # The NXOS vni cli does not raise an exception in some conditions and
91
+ # instead just displays a STDOUT error message; thus NXAPI does not detect
92
+ # the failure and we must catch it by inspecting the "body" hash entry
93
+ # returned by NXAPI. This cli behavior is unlikely to change.
94
+ fail result[2]['body'] if /ERROR:/.match(result[2]['body'].to_s)
95
+ end
96
+
97
+ # TODO: This method will be refactored as part of US52662
98
+ # def encap_dot1q
99
+ # final_hash = {}
100
+ # show = show("sh encapsulation profile | inc 'vni [0-9,]*' p 1")
101
+ # debug("show class is #{show.class} and show op is #{show}")
102
+ # return final_hash if show == {}
103
+ # match_pat = /vni (\S+).*dot1q\s+([ 0-9,\-]+)vni ([ 0-9,\-]+)/m
104
+ # split_pat = /encapsulation profile /
105
+ # pair_arr = show.split(split_pat)
106
+ # pair_arr.each do |pair|
107
+ # match_arr = match_pat.match(pair)
108
+ # next if match_arr.nil?
109
+ # debug "match arr 1 : #{match_arr[1]} 2: #{match_arr[2]} " \
110
+ # "3: #{match_arr[3]}"
111
+ # key_arr = (match_arr[3].split(/,/)).map do |x|
112
+ # x.strip!
113
+ # if /-/.match(x)
114
+ # x.gsub!('-', '..')
115
+ # else
116
+ # x
117
+ # end
118
+ # end
119
+ # val_arr = (match_arr[2].split(/,/)).map do |x|
120
+ # x.strip!
121
+ # if /-/.match(x)
122
+ # x.gsub!('-', '..')
123
+ # else
124
+ # x
125
+ # end
126
+ # end
127
+ #
128
+ # debug "key_arr = #{key_arr} val_arr = #{val_arr}"
129
+ #
130
+ # index = 0
131
+ # value = nil
132
+ # key_arr.each do |key|
133
+ # # puts "checking |#{key}| against |#{@vni_id}|"
134
+ # # puts "checking #{key.class} against #{my_vni.class}"
135
+ # if /\.\./.match(key)
136
+ # range = eval(key) ###################### *MUSTFIX* REMOVE eval
137
+ # if range.include?(@vni_id.to_i)
138
+ # val_range = eval(val_arr[index]) ##### *MUSTFIX* REMOVE eval
139
+ # position = @vni_id.to_i - range.begin
140
+ # value = val_range.begin + position
141
+ # value = value.to_s
142
+ # debug "matched #{@vni_id} value is #{value}"
143
+ # break
144
+ # end
145
+ # elsif key == @vni_id
146
+ # value = val_arr[index]
147
+ # debug "matched #{key} value is #{value}"
148
+ # end
149
+ # index += 1
150
+ # end
151
+ # unless value.nil?
152
+ # # final_hash[match_arr[1]] = value.to_i
153
+ # final_hash[match_arr[1]] = value
154
+ # end
155
+ # end # pair.each
156
+ # final_hash
157
+ # end # end of encap_dot1q
158
+
159
+ def encap_dot1q=(val, prev_val=nil) # TBD REFACTOR
160
+ debug "val is of class #{val.class} and is #{val} prev is #{prev_val}"
161
+ # When prev_val is nil, HashDiff doesn't do a `+' on each element, so this
162
+ if prev_val.nil?
163
+ val.each do |fresh_profile, fresh_dot1q|
164
+ config_set('vni', 'encap_dot1q', fresh_profile, '',
165
+ fresh_dot1q, @vni_id)
166
+ end
167
+ return
168
+ end
169
+ require 'hashdiff'
170
+ hash_diff = HashDiff.diff(prev_val, val)
171
+ debug "hsh diff ; #{hash_diff}"
172
+ return if hash_diff == []
173
+ hash_diff.each do |diff|
174
+ result =
175
+ case diff[0]
176
+ when /\+/
177
+ config_set('vni', 'encap_dot1q', diff[1], '', diff[2], @vni_id)
178
+ when /\-/
179
+ config_set('vni', 'encap_dot1q', diff[1], 'no', diff[2], @vni_id)
180
+ when /~/
181
+ config_set('vni', 'encap_dot1q', diff[1], 'no', diff[2], @vni_id)
182
+ config_set('vni', 'encap_dot1q', diff[1], '', diff[3], @vni_id)
183
+ end
184
+ cli_error_check(result)
185
+ end
186
+ rescue CliError => e
187
+ raise "[vni #{@vni_id}] '#{e.command}' : #{e.clierror}"
188
+ end
189
+
190
+ def default_encap_dot1q
191
+ config_get_default('vni', 'encap_dot1q')
192
+ end
193
+
194
+ def bridge_domain
195
+ bd_arr = config_get('vni', 'bridge_domain', vni: @vni_id)
196
+ bd_arr.first.to_i
197
+ end
198
+
199
+ def bridge_domain=(domain)
200
+ # TBD: ACTIVATE SHOULD BE SEPARATE SETTER AND POSSIBLY RENAMED
201
+ state = (domain) ? '' : 'no'
202
+ config_set('vni', 'bridge_domain_activate', state: state, domain: domain)
203
+ config_set('vni', 'bridge_domain', state: state, domain: domain,
204
+ vni: @vni_id)
205
+ end
206
+
207
+ def default_bridge_domain
208
+ config_get_default('vni', 'bridge_domain')
209
+ end
210
+
211
+ def shutdown
212
+ config_get('vni', 'shutdown', vni: @vni_id)
213
+ end
214
+
215
+ def shutdown=(state)
216
+ state = (state) ? '' : 'no'
217
+ result = config_set('vni', 'shutdown', state: state, vni: @vni_id)
218
+ cli_error_check(result)
219
+ rescue CliError => e
220
+ raise "[vni #{@vni_id}] '#{e.command}' : #{e.clierror}"
221
+ end
222
+
223
+ def default_shutdown
224
+ config_get_default('vni', 'shutdown')
225
+ end
226
+ end # class
227
+ end # module