cisco_node_utils 1.2.0 → 1.3.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 (255) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +13 -0
  5. data/.travis.yml +4 -1
  6. data/CHANGELOG.md +81 -2
  7. data/CONTRIBUTING.md +2 -17
  8. data/Gemfile +5 -0
  9. data/README.md +92 -47
  10. data/Rakefile +23 -1
  11. data/bin/git/hooks/hook_lib +7 -0
  12. data/bin/git/hooks/pre-commit/check_unstaged_changes +18 -0
  13. data/bin/git/hooks/pre-commit/rubocop +7 -2
  14. data/bin/git/hooks/pre-commit/validate-diffs +18 -4
  15. data/bin/git/hooks/pre-commit/validate-yaml +18 -0
  16. data/bin/git/update-hooks +64 -6
  17. data/cisco_node_utils.gemspec +9 -6
  18. data/docs/README-develop-best-practices.md +149 -50
  19. data/docs/README-develop-node-utils-APIs.md +92 -42
  20. data/docs/README-maintainers.md +7 -4
  21. data/docs/README-test-execution.md +57 -0
  22. data/docs/cisco_node_utils.yaml.example +30 -0
  23. data/docs/template-router.rb +4 -0
  24. data/ext/mkrf_conf.rb +63 -0
  25. data/lib/.rubocop.yml +2 -2
  26. data/lib/cisco_node_utils.rb +5 -0
  27. data/lib/cisco_node_utils/aaa_authentication_login.rb +5 -6
  28. data/lib/cisco_node_utils/aaa_authorization_service.rb +1 -1
  29. data/lib/cisco_node_utils/ace.rb +165 -12
  30. data/lib/cisco_node_utils/acl.rb +2 -1
  31. data/lib/cisco_node_utils/bgp.rb +184 -21
  32. data/lib/cisco_node_utils/bgp_af.rb +94 -249
  33. data/lib/cisco_node_utils/bgp_neighbor.rb +94 -14
  34. data/lib/cisco_node_utils/bgp_neighbor_af.rb +75 -8
  35. data/lib/cisco_node_utils/bridge_domain.rb +183 -0
  36. data/lib/cisco_node_utils/bridge_domain_vni.rb +206 -0
  37. data/lib/cisco_node_utils/cisco_cmn_utils.rb +85 -2
  38. data/lib/cisco_node_utils/client.rb +35 -0
  39. data/lib/cisco_node_utils/client/client.rb +234 -0
  40. data/lib/cisco_node_utils/client/grpc.rb +33 -0
  41. data/lib/cisco_node_utils/client/grpc/client.rb +311 -0
  42. data/lib/cisco_node_utils/client/grpc/ems.proto +148 -0
  43. data/lib/cisco_node_utils/client/grpc/ems.rb +111 -0
  44. data/lib/cisco_node_utils/client/grpc/ems_services.rb +49 -0
  45. data/lib/cisco_node_utils/client/nxapi.rb +31 -0
  46. data/lib/cisco_node_utils/client/nxapi/client.rb +305 -0
  47. data/lib/cisco_node_utils/client/utils.rb +164 -0
  48. data/lib/cisco_node_utils/cmd_ref/README_YAML.md +222 -254
  49. data/lib/cisco_node_utils/cmd_ref/aaa_auth_login_service.yaml +11 -8
  50. data/lib/cisco_node_utils/cmd_ref/aaa_authentication_login.yaml +22 -15
  51. data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +11 -8
  52. data/lib/cisco_node_utils/cmd_ref/acl.yaml +21 -16
  53. data/lib/cisco_node_utils/cmd_ref/bgp.yaml +239 -109
  54. data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +114 -55
  55. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +76 -52
  56. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +106 -62
  57. data/lib/cisco_node_utils/cmd_ref/bridge_domain.yaml +71 -0
  58. data/lib/cisco_node_utils/cmd_ref/bridge_domain_vni.yaml +33 -0
  59. data/lib/cisco_node_utils/cmd_ref/dnsclient.yaml +35 -14
  60. data/lib/cisco_node_utils/cmd_ref/encapsulation.yaml +25 -0
  61. data/lib/cisco_node_utils/cmd_ref/evpn_vni.yaml +23 -17
  62. data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +94 -83
  63. data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +22 -17
  64. data/lib/cisco_node_utils/cmd_ref/feature.yaml +76 -26
  65. data/lib/cisco_node_utils/cmd_ref/images.yaml +3 -2
  66. data/lib/cisco_node_utils/cmd_ref/interface.yaml +381 -153
  67. data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +21 -11
  68. data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +21 -21
  69. data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +30 -21
  70. data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +18 -13
  71. data/lib/cisco_node_utils/cmd_ref/inventory.yaml +26 -31
  72. data/lib/cisco_node_utils/cmd_ref/itd_device_group.yaml +83 -0
  73. data/lib/cisco_node_utils/cmd_ref/itd_service.yaml +119 -0
  74. data/lib/cisco_node_utils/cmd_ref/memory.yaml +17 -6
  75. data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +10 -3
  76. data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +17 -5
  77. data/lib/cisco_node_utils/cmd_ref/ospf.yaml +33 -29
  78. data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +12 -10
  79. data/lib/cisco_node_utils/cmd_ref/pim.yaml +16 -19
  80. data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +40 -25
  81. data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +17 -12
  82. data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +71 -35
  83. data/lib/cisco_node_utils/cmd_ref/radius_server_group.yaml +10 -5
  84. data/lib/cisco_node_utils/cmd_ref/show_system.yaml +6 -2
  85. data/lib/cisco_node_utils/cmd_ref/show_version.yaml +47 -43
  86. data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +13 -11
  87. data/lib/cisco_node_utils/cmd_ref/snmp_group.yaml +4 -2
  88. data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +23 -21
  89. data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +26 -22
  90. data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +19 -17
  91. data/lib/cisco_node_utils/cmd_ref/snmpnotification.yaml +18 -6
  92. data/lib/cisco_node_utils/cmd_ref/stp_global.yaml +234 -0
  93. data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +24 -9
  94. data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +5 -3
  95. data/lib/cisco_node_utils/cmd_ref/system.yaml +4 -3
  96. data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +22 -20
  97. data/lib/cisco_node_utils/cmd_ref/tacacs_server_group.yaml +27 -15
  98. data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +45 -16
  99. data/lib/cisco_node_utils/cmd_ref/vdc.yaml +21 -11
  100. data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +3 -2
  101. data/lib/cisco_node_utils/cmd_ref/vlan.yaml +60 -32
  102. data/lib/cisco_node_utils/cmd_ref/vpc.yaml +118 -101
  103. data/lib/cisco_node_utils/cmd_ref/vrf.yaml +54 -58
  104. data/lib/cisco_node_utils/cmd_ref/vrf_af.yaml +118 -0
  105. data/lib/cisco_node_utils/cmd_ref/vtp.yaml +19 -25
  106. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +28 -18
  107. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +34 -17
  108. data/lib/cisco_node_utils/cmd_ref/yum.yaml +6 -4
  109. data/lib/cisco_node_utils/command_reference.rb +261 -142
  110. data/lib/cisco_node_utils/constants.rb +33 -0
  111. data/lib/cisco_node_utils/encapsulation.rb +112 -0
  112. data/lib/cisco_node_utils/environment.rb +102 -0
  113. data/lib/cisco_node_utils/evpn_vni.rb +5 -3
  114. data/lib/cisco_node_utils/exceptions.rb +111 -0
  115. data/lib/cisco_node_utils/fabricpath_global.rb +52 -35
  116. data/lib/cisco_node_utils/fabricpath_topology.rb +44 -57
  117. data/lib/cisco_node_utils/feature.rb +165 -3
  118. data/lib/cisco_node_utils/interface.rb +1051 -260
  119. data/lib/cisco_node_utils/interface_channel_group.rb +11 -10
  120. data/lib/cisco_node_utils/interface_ospf.rb +1 -2
  121. data/lib/cisco_node_utils/interface_portchannel.rb +4 -12
  122. data/lib/cisco_node_utils/interface_service_vni.rb +7 -7
  123. data/lib/cisco_node_utils/itd_device_group.rb +248 -0
  124. data/lib/cisco_node_utils/itd_device_group_node.rb +144 -0
  125. data/lib/cisco_node_utils/itd_service.rb +523 -0
  126. data/lib/cisco_node_utils/logger.rb +75 -0
  127. data/lib/cisco_node_utils/node.rb +62 -192
  128. data/lib/cisco_node_utils/node_util.rb +56 -10
  129. data/lib/cisco_node_utils/overlay_global.rb +2 -2
  130. data/lib/cisco_node_utils/pim.rb +2 -13
  131. data/lib/cisco_node_utils/pim_group_list.rb +1 -1
  132. data/lib/cisco_node_utils/pim_rp_address.rb +1 -1
  133. data/lib/cisco_node_utils/platform.rb +52 -21
  134. data/lib/cisco_node_utils/portchannel_global.rb +89 -19
  135. data/lib/cisco_node_utils/radius_server.rb +168 -37
  136. data/lib/cisco_node_utils/router_ospf.rb +20 -35
  137. data/lib/cisco_node_utils/router_ospf_vrf.rb +4 -4
  138. data/lib/cisco_node_utils/snmpserver.rb +1 -6
  139. data/lib/cisco_node_utils/snmpuser.rb +6 -4
  140. data/lib/cisco_node_utils/stp_global.rb +676 -0
  141. data/lib/cisco_node_utils/syslog_server.rb +77 -18
  142. data/lib/cisco_node_utils/syslog_settings.rb +1 -1
  143. data/lib/cisco_node_utils/tacacs_server_group.rb +8 -4
  144. data/lib/cisco_node_utils/tacacs_server_host.rb +115 -25
  145. data/lib/cisco_node_utils/vdc.rb +12 -0
  146. data/lib/cisco_node_utils/version.rb +1 -1
  147. data/lib/cisco_node_utils/vlan.rb +147 -29
  148. data/lib/cisco_node_utils/vpc.rb +55 -3
  149. data/lib/cisco_node_utils/vrf.rb +72 -11
  150. data/lib/cisco_node_utils/vrf_af.rb +114 -29
  151. data/lib/cisco_node_utils/vtp.rb +34 -52
  152. data/lib/cisco_node_utils/vxlan_vtep.rb +34 -8
  153. data/lib/cisco_node_utils/vxlan_vtep_vni.rb +36 -4
  154. data/lib/minitest/environment_plugin.rb +31 -0
  155. data/lib/minitest/log_level_plugin.rb +41 -0
  156. data/spec/client_spec.rb +7 -0
  157. data/spec/environment_spec.rb +263 -0
  158. data/spec/grpc_client_spec.rb +23 -0
  159. data/spec/isolate/all_clients_spec.rb +9 -0
  160. data/spec/isolate/grpc_only_spec.rb +16 -0
  161. data/spec/isolate/no_clients_spec.rb +26 -0
  162. data/spec/isolate/nxapi_only_spec.rb +16 -0
  163. data/spec/nxapi_client_spec.rb +42 -0
  164. data/spec/schema.yaml +75 -0
  165. data/spec/shared_examples_for_clients.rb +14 -0
  166. data/spec/spec_helper.rb +91 -0
  167. data/spec/whitespace_spec.rb +10 -0
  168. data/spec/yaml_spec.rb +42 -0
  169. data/tests/.rubocop.yml +2 -2
  170. data/tests/CSCuxdublin-1.0.0-7.0.3.I3.1.lib32_n9000.rpm +0 -0
  171. data/tests/basetest.rb +96 -36
  172. data/tests/ciscotest.rb +220 -12
  173. data/tests/cmd_config.yaml +71 -49
  174. data/tests/cmd_config_invalid.yaml +1 -1
  175. data/tests/test_aaa_authentication_login.rb +1 -0
  176. data/tests/test_aaa_authentication_login_service.rb +9 -0
  177. data/tests/test_aaa_authorization_service.rb +173 -367
  178. data/tests/test_ace.rb +171 -100
  179. data/tests/test_acl.rb +10 -1
  180. data/tests/test_bgp_af.rb +395 -728
  181. data/tests/test_bgp_neighbor.rb +274 -115
  182. data/tests/test_bgp_neighbor_af.rb +178 -77
  183. data/tests/test_bridge_domain.rb +191 -0
  184. data/tests/test_bridge_domain_vni.rb +116 -0
  185. data/tests/test_client_utils.rb +111 -0
  186. data/tests/test_command_config.rb +9 -5
  187. data/tests/test_command_reference.rb +380 -102
  188. data/tests/test_dns_domain.rb +13 -3
  189. data/tests/test_domain_name.rb +13 -3
  190. data/tests/test_encapsulation.rb +77 -0
  191. data/tests/test_evpn_vni.rb +25 -7
  192. data/tests/test_fabricpath_global.rb +167 -163
  193. data/tests/test_fabricpath_topology.rb +12 -33
  194. data/tests/test_feature.rb +215 -0
  195. data/tests/test_grpc.rb +166 -0
  196. data/tests/test_interface.rb +585 -344
  197. data/tests/test_interface_bdi.rb +80 -0
  198. data/tests/test_interface_channel_group.rb +6 -3
  199. data/tests/test_interface_ospf.rb +26 -24
  200. data/tests/test_interface_portchannel.rb +1 -0
  201. data/tests/test_interface_private_vlan.rb +724 -0
  202. data/tests/test_interface_service_vni.rb +37 -66
  203. data/tests/test_interface_svi.rb +98 -101
  204. data/tests/test_interface_switchport.rb +419 -549
  205. data/tests/test_itd_device_group.rb +145 -0
  206. data/tests/test_itd_device_group_node.rb +199 -0
  207. data/tests/test_itd_service.rb +298 -0
  208. data/tests/test_logger.rb +43 -0
  209. data/tests/test_name_server.rb +11 -2
  210. data/tests/test_node.rb +16 -75
  211. data/tests/test_node_ext.rb +174 -163
  212. data/tests/test_node_util.rb +119 -0
  213. data/tests/test_ntp_config.rb +5 -1
  214. data/tests/test_ntp_server.rb +2 -2
  215. data/tests/test_nxapi.rb +221 -0
  216. data/tests/test_overlay_global.rb +47 -38
  217. data/tests/test_pim.rb +2 -0
  218. data/tests/test_pim_group_list.rb +2 -0
  219. data/tests/test_pim_rp_address.rb +2 -0
  220. data/tests/test_platform.rb +86 -39
  221. data/tests/test_portchannel_global.rb +211 -135
  222. data/tests/test_radius_global.rb +13 -5
  223. data/tests/test_radius_server.rb +256 -104
  224. data/tests/test_radius_server_group.rb +2 -0
  225. data/tests/test_router_bgp.rb +781 -485
  226. data/tests/test_router_ospf.rb +26 -103
  227. data/tests/test_router_ospf_vrf.rb +52 -57
  228. data/tests/test_snmp_notification_receiver.rb +2 -0
  229. data/tests/test_snmpcommunity.rb +2 -0
  230. data/tests/test_snmpgroup.rb +2 -0
  231. data/tests/test_snmpnotification.rb +40 -21
  232. data/tests/test_snmpserver.rb +2 -0
  233. data/tests/test_snmpuser.rb +2 -0
  234. data/tests/test_stp_global.rb +563 -0
  235. data/tests/test_syslog_server.rb +32 -8
  236. data/tests/test_syslog_settings.rb +22 -9
  237. data/tests/test_tacacs_server.rb +32 -27
  238. data/tests/test_tacacs_server_group.rb +100 -45
  239. data/tests/test_tacacs_server_host.rb +135 -43
  240. data/tests/test_vdc.rb +2 -16
  241. data/tests/test_vlan.rb +106 -54
  242. data/tests/test_vlan_mt_full.rb +11 -21
  243. data/tests/test_vlan_private.rb +669 -0
  244. data/tests/test_vpc.rb +312 -159
  245. data/tests/test_vrf.rb +122 -113
  246. data/tests/test_vrf_af.rb +238 -0
  247. data/tests/test_vtp.rb +58 -102
  248. data/tests/test_vxlan_vtep.rb +38 -17
  249. data/tests/test_vxlan_vtep_vni.rb +61 -9
  250. data/tests/test_yum.rb +49 -25
  251. metadata +122 -36
  252. data/lib/cisco_node_utils/cmd_ref/fex.yaml +0 -9
  253. data/lib/cisco_node_utils/cmd_ref/vni.yaml +0 -76
  254. data/lib/cisco_node_utils/vni.rb +0 -227
  255. data/tests/test_vni.rb +0 -106
@@ -1,4 +1,7 @@
1
- # David Chuck, November 2015
1
+ #
2
+ # NXAPI implementation of vpc domain class
3
+ #
4
+ # November 2015, Deepak Cherian
2
5
  #
3
6
  # Copyright (c) 2014-2016 Cisco and/or its affiliates.
4
7
  #
@@ -16,6 +19,7 @@
16
19
 
17
20
  require_relative 'node_util'
18
21
  require_relative 'interface'
22
+ require_relative 'fabricpath_global'
19
23
 
20
24
  # Add vpc-specific constants to Cisco namespace
21
25
  module Cisco
@@ -25,7 +29,6 @@ module Cisco
25
29
  # Constructor for Vpc
26
30
  def initialize(domain_id, instantiate=true)
27
31
  @domain = domain_id
28
- @set_params = {}
29
32
 
30
33
  create if instantiate
31
34
  end
@@ -146,6 +149,38 @@ module Cisco
146
149
  'dual_active_exclude_interface_vlan_bridge_domain')
147
150
  end
148
151
 
152
+ def fabricpath_emulated_switch_id
153
+ config_get('vpc', 'fabricpath_emulated_switch_id')
154
+ end
155
+
156
+ def fabricpath_emulated_switch_id=(switch_id)
157
+ FabricpathGlobal.fabricpath_enable
158
+ set_args_keys(state: switch_id ? '' : 'no',
159
+ swid: switch_id ? switch_id : '')
160
+ config_set('vpc', 'fabricpath_emulated_switch_id', @set_args)
161
+ end
162
+
163
+ def default_fabricpath_emulated_switch_id
164
+ config_get_default('vpc', 'fabricpath_emulated_switch_id')
165
+ end
166
+
167
+ # Note: fabricpath_multicast_load_balance also requires
168
+ # fabricpath_emulated_switch_id before it will be functional but it
169
+ # will config & nvgen independently.
170
+ def fabricpath_multicast_load_balance
171
+ config_get('vpc', 'fabricpath_multicast_load_balance')
172
+ end
173
+
174
+ def fabricpath_multicast_load_balance=(state)
175
+ FabricpathGlobal.fabricpath_enable
176
+ set_args_keys(state: state ? '' : 'no')
177
+ config_set('vpc', 'fabricpath_multicast_load_balance', @set_args)
178
+ end
179
+
180
+ def default_fabricpath_multicast_load_balance
181
+ config_get_default('vpc', 'fabricpath_multicast_load_balance')
182
+ end
183
+
149
184
  def graceful_consistency_check
150
185
  val = config_get('vpc', 'graceful_consistency_check')
151
186
  val.nil? ? false : val
@@ -290,6 +325,23 @@ module Cisco
290
325
  config_get_default('vpc', 'peer_gateway_exclude_vlan')
291
326
  end
292
327
 
328
+ def port_channel_limit
329
+ val = config_get('vpc', 'port_channel_limit')
330
+ val.nil? ? false : val
331
+ end
332
+
333
+ def port_channel_limit=(val)
334
+ set_args_keys(state: val ? '' : 'no')
335
+ # This requires fabricpath_emulated_switch_id to be set first
336
+ fail 'fabricpath_switch_id configuration is required in the vPC domain' if
337
+ !fabricpath_emulated_switch_id && !val
338
+ config_set('vpc', 'port_channel_limit', @set_args)
339
+ end
340
+
341
+ def default_port_channel_limit
342
+ config_get_default('vpc', 'port_channel_limit')
343
+ end
344
+
293
345
  def role_priority
294
346
  config_get('vpc', 'role_priority')
295
347
  end
@@ -362,7 +414,7 @@ module Cisco
362
414
 
363
415
  def track=(val)
364
416
  unless val.nil?
365
- fail ArgumentError, 'retransmit_count must be an Integer' unless
417
+ fail ArgumentError, 'track must be an Integer' unless
366
418
  val.is_a?(Integer)
367
419
  end
368
420
 
@@ -30,6 +30,10 @@ module Cisco
30
30
  create if instantiate
31
31
  end
32
32
 
33
+ def to_s
34
+ "VRF #{@name}"
35
+ end
36
+
33
37
  def self.vrfs
34
38
  hash = {}
35
39
  vrf_list = config_get('vrf', 'all_vrfs')
@@ -63,14 +67,57 @@ module Cisco
63
67
  desc.strip!
64
68
  no_cmd = desc.empty? ? 'no' : ''
65
69
  config_set('vrf', 'description', vrf: @name, state: no_cmd, desc: desc)
66
- rescue Cisco::CliError => e
67
- raise "[#{@name}] '#{e.command}' : #{e.clierror}"
68
70
  end
69
71
 
70
72
  def default_description
71
73
  config_get_default('vrf', 'description')
72
74
  end
73
75
 
76
+ def mhost_ipv4_default_interface
77
+ config_get('vrf', 'mhost_default_interface', vrf: @name, afi: 'ipv4')
78
+ end
79
+
80
+ def mhost_ipv4_default_interface=(val)
81
+ mhost_default_interface_setter_helper('ipv4', val)
82
+ end
83
+
84
+ def default_mhost_ipv4_default_interface
85
+ config_get_default('vrf', 'mhost_default_interface')
86
+ end
87
+
88
+ def mhost_ipv6_default_interface
89
+ config_get('vrf', 'mhost_default_interface', vrf: @name, afi: 'ipv6')
90
+ end
91
+
92
+ def mhost_ipv6_default_interface=(val)
93
+ mhost_default_interface_setter_helper('ipv6', val)
94
+ end
95
+
96
+ def default_mhost_ipv6_default_interface
97
+ config_get_default('vrf', 'mhost_default_interface')
98
+ end
99
+
100
+ def mhost_default_interface_setter_helper(afi, val)
101
+ val.strip!
102
+ no_cmd = val.empty? ? 'no' : ''
103
+ config_set('vrf', 'mhost_default_interface', vrf: @name,
104
+ state: no_cmd, afi: afi, intf: val)
105
+ end
106
+
107
+ def remote_route_filtering
108
+ config_get('vrf', 'remote_route_filtering', vrf: @name)
109
+ end
110
+
111
+ def remote_route_filtering=(val)
112
+ no_cmd = val ? 'no' : ''
113
+ config_set('vrf', 'remote_route_filtering', vrf: @name,
114
+ state: no_cmd, remote_route_filtering: val)
115
+ end
116
+
117
+ def default_remote_route_filtering
118
+ config_get_default('vrf', 'remote_route_filtering')
119
+ end
120
+
74
121
  def shutdown
75
122
  config_get('vrf', 'shutdown', vrf: @name)
76
123
  end
@@ -78,8 +125,6 @@ module Cisco
78
125
  def shutdown=(val)
79
126
  no_cmd = (val) ? '' : 'no'
80
127
  config_set('vrf', 'shutdown', vrf: @name, state: no_cmd)
81
- rescue Cisco::CliError => e
82
- raise "[vrf #{@name}] '#{e.command}' : #{e.clierror}"
83
128
  end
84
129
 
85
130
  def default_shutdown
@@ -94,12 +139,16 @@ module Cisco
94
139
 
95
140
  def route_distinguisher=(rd)
96
141
  # feature bgp and nv overlay required for rd cli in NXOS
97
- Feature.bgp_enable
98
- Feature.nv_overlay_enable
99
- Feature.nv_overlay_evpn_enable
142
+ if platform == :nexus
143
+ Feature.bgp_enable
144
+ Feature.nv_overlay_enable if Feature.nv_overlay_supported?
145
+ Feature.nv_overlay_evpn_enable if Feature.nv_overlay_evpn_supported?
146
+ end
100
147
  if rd == default_route_distinguisher
101
148
  state = 'no'
102
- rd = ''
149
+ # I2 images require an rd for removal
150
+ rd = route_distinguisher
151
+ return if rd.to_s.empty?
103
152
  else
104
153
  state = ''
105
154
  end
@@ -116,16 +165,28 @@ module Cisco
116
165
  end
117
166
 
118
167
  def vni=(id)
119
- Feature.vn_segment_vlan_based_enable
168
+ Feature.vn_segment_vlan_based_enable if platform == :nexus
120
169
  no_cmd = (id) ? '' : 'no'
121
170
  id = (id) ? id : vni
122
171
  config_set('vrf', 'vni', vrf: @name, state: no_cmd, id: id)
123
- rescue Cisco::CliError => e
124
- raise "[vrf #{@name}] '#{e.command}' : #{e.clierror}"
125
172
  end
126
173
 
127
174
  def default_vni
128
175
  config_get_default('vrf', 'vni')
129
176
  end
177
+
178
+ def vpn_id
179
+ config_get('vrf', 'vpn_id', vrf: @name)
180
+ end
181
+
182
+ def vpn_id=(val)
183
+ val.strip!
184
+ no_cmd = val.empty? ? 'no' : ''
185
+ config_set('vrf', 'vpn_id', vrf: @name, state: no_cmd, vpnid: val)
186
+ end
187
+
188
+ def default_vpn_id
189
+ config_get_default('vrf', 'vpn_id')
190
+ end
130
191
  end # class
131
192
  end # module
@@ -23,19 +23,21 @@ require_relative 'feature'
23
23
  module Cisco
24
24
  # VrfAF - node utility class for VRF Address-Family configuration
25
25
  class VrfAF < NodeUtil
26
- attr_reader :name
27
-
28
26
  def initialize(vrf, af, instantiate=true)
29
27
  validate_args(vrf, af)
30
28
  create if instantiate
31
29
  end
32
30
 
31
+ def to_s
32
+ "VRF #{@vrf} afi #{@afi} safi #{@safi}"
33
+ end
34
+
33
35
  def self.afs
34
36
  hash = {}
35
37
  vrfs = config_get('vrf', 'all_vrfs')
36
38
  vrfs.each do |vrf|
37
39
  hash[vrf] = {}
38
- afs = config_get('vrf', 'all_vrf_afs', vrf: vrf)
40
+ afs = config_get('vrf_af', 'all_afs', vrf: vrf)
39
41
 
40
42
  next if afs.nil?
41
43
  afs.each do |af|
@@ -73,92 +75,160 @@ module Cisco
73
75
  @set_args = @get_args.merge!(hash) unless hash.empty?
74
76
  end
75
77
 
76
- def route_target_feature_enable
78
+ def route_target_feature_enable(require_nv_overlay=nil)
79
+ return unless platform == :nexus
80
+
81
+ # All NX route-target properties require feature bgp
77
82
  Feature.bgp_enable
78
- Feature.nv_overlay_enable
79
- Feature.nv_overlay_evpn_enable
83
+
84
+ # Some platforms/versions also require nv overlay for some properties
85
+ return unless require_nv_overlay
86
+ Feature.nv_overlay_enable if Feature.nv_overlay_supported?
87
+ Feature.nv_overlay_evpn_enable if Feature.nv_overlay_evpn_supported?
80
88
  end
81
89
 
82
90
  ########################################################
83
91
  # PROPERTIES #
84
92
  ########################################################
85
93
 
94
+ def route_policy_export
95
+ config_get('vrf_af', 'route_policy_export', @get_args)
96
+ end
97
+
98
+ def route_policy_export=(name)
99
+ Feature.bgp_enable if platform == :nexus
100
+ # Nexus requires passing in <policy_name> in "no export map" command.
101
+ if name
102
+ set_args_keys(state: '', policy_name: name)
103
+ else
104
+ remove_name = config_get('vrf_af', 'route_policy_export', @get_args)
105
+ return nil if remove_name.nil?
106
+ set_args_keys(state: 'no', policy_name: remove_name)
107
+ end
108
+ config_set('vrf_af', 'route_policy_export', @set_args)
109
+ end
110
+
111
+ def default_route_policy_export
112
+ config_get_default('vrf_af', 'route_policy_export')
113
+ end
114
+
115
+ def route_policy_import
116
+ config_get('vrf_af', 'route_policy_import', @get_args)
117
+ end
118
+
119
+ def route_policy_import=(name)
120
+ Feature.bgp_enable if platform == :nexus
121
+ # Nexus requires passing in <policy_name> in "no import map" command.
122
+ if name
123
+ set_args_keys(state: '', policy_name: name)
124
+ else
125
+ remove_name = config_get('vrf_af', 'route_policy_import', @get_args)
126
+ return nil if remove_name.nil?
127
+ set_args_keys(state: 'no', policy_name: remove_name)
128
+ end
129
+ config_set('vrf_af', 'route_policy_import', @set_args)
130
+ end
131
+
132
+ def default_route_policy_import
133
+ config_get_default('vrf_af', 'route_policy_import')
134
+ end
135
+
136
+ # --------------------------
86
137
  def route_target_both_auto
87
- config_get('vrf', 'route_target_both_auto', @get_args)
138
+ config_get('vrf_af', 'route_target_both_auto', @get_args)
88
139
  end
89
140
 
90
141
  def route_target_both_auto=(state)
91
- route_target_feature_enable
142
+ route_target_feature_enable(:require_nv_overlay)
92
143
  set_args_keys(state: (state ? '' : 'no'))
93
- config_set('vrf', 'route_target_both_auto', @set_args)
144
+ config_set('vrf_af', 'route_target_both_auto', @set_args)
94
145
  end
95
146
 
96
147
  def default_route_target_both_auto
97
- config_get_default('vrf', 'route_target_both_auto')
148
+ config_get_default('vrf_af', 'route_target_both_auto')
98
149
  end
99
150
 
100
151
  # --------------------------
101
152
  def route_target_both_auto_evpn
102
- config_get('vrf', 'route_target_both_auto_evpn', @get_args)
153
+ config_get('vrf_af', 'route_target_both_auto_evpn', @get_args)
103
154
  end
104
155
 
105
156
  def route_target_both_auto_evpn=(state)
106
- route_target_feature_enable
157
+ route_target_feature_enable(:require_nv_overlay)
107
158
  set_args_keys(state: (state ? '' : 'no'))
108
- config_set('vrf', 'route_target_both_auto_evpn', @set_args)
159
+ config_set('vrf_af', 'route_target_both_auto_evpn', @set_args)
109
160
  end
110
161
 
111
162
  def default_route_target_both_auto_evpn
112
- config_get_default('vrf', 'route_target_both_auto_evpn')
163
+ config_get_default('vrf_af', 'route_target_both_auto_evpn')
113
164
  end
114
165
 
115
166
  # --------------------------
116
167
  def route_target_export
117
- cmds = config_get('vrf', 'route_target_export', @get_args)
118
- cmds.sort
168
+ cmds = config_get('vrf_af', 'route_target_export', @get_args)
169
+ cmds.nil? ? nil : cmds.sort
119
170
  end
120
171
 
121
172
  def route_target_export=(should)
173
+ route_target_feature_enable
122
174
  route_target_delta(should, route_target_export, 'route_target_export')
123
175
  end
124
176
 
125
177
  def default_route_target_export
126
- config_get_default('vrf', 'route_target_export')
178
+ config_get_default('vrf_af', 'route_target_export')
127
179
  end
128
180
 
129
181
  # --------------------------
130
182
  def route_target_export_evpn
131
- cmds = config_get('vrf', 'route_target_export_evpn', @get_args)
132
- cmds.sort
183
+ cmds = config_get('vrf_af', 'route_target_export_evpn', @get_args)
184
+ cmds.nil? ? nil : cmds.sort
133
185
  end
134
186
 
135
187
  def route_target_export_evpn=(should)
188
+ route_target_feature_enable(:require_nv_overlay)
136
189
  route_target_delta(should, route_target_export_evpn,
137
190
  'route_target_export_evpn')
138
191
  end
139
192
 
140
193
  def default_route_target_export_evpn
141
- config_get_default('vrf', 'route_target_export_evpn')
194
+ config_get_default('vrf_af', 'route_target_export_evpn')
195
+ end
196
+
197
+ # --------------------------
198
+ def route_target_export_stitching
199
+ cmds = config_get('vrf_af', 'route_target_export_stitching', @get_args)
200
+ cmds.nil? ? nil : cmds.sort
201
+ end
202
+
203
+ def route_target_export_stitching=(should)
204
+ route_target_delta(should, route_target_export_stitching,
205
+ 'route_target_export_stitching')
206
+ end
207
+
208
+ def default_route_target_export_stitching
209
+ config_get_default('vrf_af', 'route_target_export_stitching')
142
210
  end
143
211
 
144
212
  # --------------------------
145
213
  def route_target_import
146
- cmds = config_get('vrf', 'route_target_import', @get_args)
147
- cmds.sort
214
+ cmds = config_get('vrf_af', 'route_target_import', @get_args)
215
+ cmds.nil? ? nil : cmds.sort
148
216
  end
149
217
 
150
218
  def route_target_import=(should)
219
+ route_target_feature_enable
151
220
  route_target_delta(should, route_target_import, 'route_target_import')
152
221
  end
153
222
 
154
223
  def default_route_target_import
155
- config_get_default('vrf', 'route_target_import')
224
+ config_get_default('vrf_af', 'route_target_import')
156
225
  end
157
226
 
158
227
  # --------------------------
159
228
  def route_target_import_evpn
160
- cmds = config_get('vrf', 'route_target_import_evpn', @get_args)
161
- cmds.sort
229
+ route_target_feature_enable(:require_nv_overlay)
230
+ cmds = config_get('vrf_af', 'route_target_import_evpn', @get_args)
231
+ cmds.nil? ? nil : cmds.sort
162
232
  end
163
233
 
164
234
  def route_target_import_evpn=(should)
@@ -167,23 +237,38 @@ module Cisco
167
237
  end
168
238
 
169
239
  def default_route_target_import_evpn
170
- config_get_default('vrf', 'route_target_import_evpn')
240
+ config_get_default('vrf_af', 'route_target_import_evpn')
241
+ end
242
+
243
+ # --------------------------
244
+ def route_target_import_stitching
245
+ cmds = config_get('vrf_af', 'route_target_import_stitching', @get_args)
246
+ cmds.nil? ? nil : cmds.sort
247
+ end
248
+
249
+ def route_target_import_stitching=(should)
250
+ route_target_delta(should, route_target_import_stitching,
251
+ 'route_target_import_stitching')
252
+ end
253
+
254
+ def default_route_target_import_stitching
255
+ config_get_default('vrf_af', 'route_target_import_stitching')
171
256
  end
172
257
 
173
258
  # --------------------------
174
259
  # route_target_delta is a common helper function for the route_target
175
260
  # properties. It walks the delta hash and adds/removes each target cli.
176
261
  def route_target_delta(should, is, prop)
177
- route_target_feature_enable
262
+ fail Cisco::UnsupportedError.new('vrf_af', prop) if is.nil?
178
263
  delta_hash = Utils.delta_add_remove(should, is)
179
264
  return if delta_hash.values.flatten.empty?
180
265
  [:add, :remove].each do |action|
181
- CiscoLogger.debug("#{prop}" \
266
+ Cisco::Logger.debug("#{prop}" \
182
267
  "#{@get_args}\n #{action}: #{delta_hash[action]}")
183
268
  delta_hash[action].each do |community|
184
269
  state = (action == :add) ? '' : 'no'
185
270
  set_args_keys(state: state, community: community)
186
- config_set('vrf', prop, @set_args)
271
+ config_set('vrf_af', prop, @set_args)
187
272
  end
188
273
  end
189
274
  end