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
@@ -67,7 +67,7 @@ module Cisco
67
67
  end
68
68
 
69
69
  def create
70
- Feature.bgp_enable
70
+ Feature.bgp_enable if platform == :nexus
71
71
  set_args_keys(state: '')
72
72
  config_set('bgp', 'create_destroy_neighbor', @set_args)
73
73
  end
@@ -113,7 +113,7 @@ module Cisco
113
113
 
114
114
  def connected_check
115
115
  result = config_get('bgp_neighbor', 'connected_check', @get_args)
116
- result ? false : true
116
+ result ? false : default_connected_check
117
117
  end
118
118
 
119
119
  def default_connected_check
@@ -129,7 +129,7 @@ module Cisco
129
129
 
130
130
  def capability_negotiation
131
131
  result = config_get('bgp_neighbor', 'capability_negotiation', @get_args)
132
- result ? false : true
132
+ result ? false : default_capability_negotiation
133
133
  end
134
134
 
135
135
  def default_capability_negotiation
@@ -142,8 +142,7 @@ module Cisco
142
142
  end
143
143
 
144
144
  def dynamic_capability
145
- result = config_get('bgp_neighbor', 'dynamic_capability', @get_args)
146
- result ? true : false
145
+ config_get('bgp_neighbor', 'dynamic_capability', @get_args)
147
146
  end
148
147
 
149
148
  def default_dynamic_capability
@@ -212,7 +211,7 @@ module Cisco
212
211
 
213
212
  def low_memory_exempt
214
213
  result = config_get('bgp_neighbor', 'low_memory_exempt', @get_args)
215
- result ? true : false
214
+ result ? true : default_low_memory_exempt
216
215
  end
217
216
 
218
217
  def default_low_memory_exempt
@@ -242,8 +241,24 @@ module Cisco
242
241
  type: Encryption.symbol_to_cli(default_password_type),
243
242
  passwd: val.to_s)
244
243
  else
244
+ cli_type = nil
245
+ if platform == :ios_xr
246
+ case type
247
+ when :cleartext
248
+ cli_type = 'clear'
249
+ when :md5
250
+ cli_type = 'encrypted'
251
+ else
252
+ fail Cisco::UnsupportedError.new(
253
+ 'RouterBgpNeighbor', 'password',
254
+ nil, "type '#{type}'")
255
+ end
256
+ else
257
+ cli_type = Encryption.symbol_to_cli(type)
258
+ end
259
+
245
260
  set_args_keys(state: '',
246
- type: Encryption.symbol_to_cli(type),
261
+ type: cli_type,
247
262
  passwd: val.to_s)
248
263
  end
249
264
  config_set('bgp_neighbor', 'password', @set_args)
@@ -259,7 +274,7 @@ module Cisco
259
274
 
260
275
  def password_type
261
276
  result = config_get('bgp_neighbor', 'password_type', @get_args)
262
- Encryption.cli_to_symbol(result.to_i)
277
+ Encryption.cli_to_symbol(result.to_s)
263
278
  end
264
279
 
265
280
  def default_password_type
@@ -303,7 +318,7 @@ module Cisco
303
318
 
304
319
  def default_remove_private_as
305
320
  result = config_get_default('bgp_neighbor', 'remove_private_as')
306
- result.to_sym
321
+ result.nil? ? nil : result.to_sym
307
322
  end
308
323
 
309
324
  def shutdown=(val)
@@ -375,18 +390,52 @@ module Cisco
375
390
  ["#{default_timers_keepalive}", "#{default_timers_holdtime}"]
376
391
  end
377
392
 
393
+ def transport_passive_mode=(val)
394
+ if platform == :nexus
395
+ if val == :active_only
396
+ fail Cisco::UnsupportedError.new(
397
+ 'RouterBgpNeighbor', 'transport_passive_mode',
398
+ nil, "value '#{val}'")
399
+ else
400
+ set_args_keys(state: (val == :passive_only) ? '' : 'no')
401
+ config_set('bgp_neighbor', 'transport_passive_mode', @set_args)
402
+ end
403
+ else
404
+ set_args_keys(mode: mode_symbol_to_cli(val),
405
+ state: (val == :none) ? 'no' : '')
406
+ config_set('bgp_neighbor', 'transport_passive_mode', @set_args)
407
+ end
408
+ end
409
+
410
+ def transport_passive_mode
411
+ result = config_get('bgp_neighbor', 'transport_passive_mode', @get_args)
412
+ if platform == :nexus
413
+ result ? :passive_only : :none
414
+ else
415
+ mode_cli_to_symbol(result)
416
+ end
417
+ end
418
+
419
+ def default_transport_passive_mode
420
+ result = config_get_default('bgp_neighbor', 'transport_passive_mode')
421
+ if platform == :nexus
422
+ result ? :passive_only : :none
423
+ else
424
+ mode_cli_to_symbol(result)
425
+ end
426
+ end
427
+
378
428
  def transport_passive_only=(val)
379
- set_args_keys(state: (val) ? '' : 'no')
380
- config_set('bgp_neighbor', 'transport_passive_only', @set_args)
429
+ # TODO: add "deprecated" warning?
430
+ self.transport_passive_mode = (val ? :passive_only : :none)
381
431
  end
382
432
 
383
433
  def transport_passive_only
384
- result = config_get('bgp_neighbor', 'transport_passive_only', @get_args)
385
- result ? true : false
434
+ transport_passive_mode == :passive_only
386
435
  end
387
436
 
388
437
  def default_transport_passive_only
389
- config_get_default('bgp_neighbor', 'transport_passive_only')
438
+ default_transport_passive_mode == :passive_only
390
439
  end
391
440
 
392
441
  def update_source=(val)
@@ -406,5 +455,36 @@ module Cisco
406
455
  def default_update_source
407
456
  config_get_default('bgp_neighbor', 'update_source')
408
457
  end
458
+
459
+ def mode_symbol_to_cli(symbol)
460
+ symbol = symbol.downcase if symbol.is_a? String
461
+ case symbol
462
+ when :active_only
463
+ 'active-only'
464
+ when :passive_only
465
+ 'passive-only'
466
+ when :both
467
+ 'both'
468
+ when :none
469
+ ''
470
+ else
471
+ fail KeyError
472
+ end
473
+ end
474
+
475
+ def mode_cli_to_symbol(cli)
476
+ case cli
477
+ when 'active-only'
478
+ :active_only
479
+ when 'passive-only'
480
+ :passive_only
481
+ when 'both'
482
+ :both
483
+ when ''
484
+ :none
485
+ else
486
+ fail KeyError
487
+ end
488
+ end
409
489
  end # class
410
490
  end # module
@@ -70,6 +70,13 @@ module Cisco
70
70
  fail ArgumentError, "'af' must be an array specifying afi and safi" unless
71
71
  af.is_a?(Array) || af.length == 2
72
72
 
73
+ # XR BGP does not support <address>/<mask>
74
+ if platform == :ios_xr && nbr['/'] == '/'
75
+ fail UnsupportedError.new(
76
+ 'validate_args',
77
+ "IOS XR does not support 'slash' notation")
78
+ end
79
+
73
80
  nbr = Utils.process_network_mask(nbr)
74
81
  @asn = RouterBgp.validate_asnum(asn)
75
82
  @vrf = vrf
@@ -92,7 +99,7 @@ module Cisco
92
99
  # rubocop:enable Style/AccessorMethodNamefor
93
100
 
94
101
  def create
95
- Feature.bgp_enable
102
+ Feature.bgp_enable if platform == :nexus
96
103
  set_args_keys(state: '')
97
104
  config_set('bgp_neighbor', 'af', @set_args)
98
105
  end
@@ -224,7 +231,8 @@ module Cisco
224
231
  end
225
232
 
226
233
  def default_additional_paths_receive
227
- config_get_default('bgp_neighbor_af', 'additional_paths_receive').to_sym
234
+ ret = config_get_default('bgp_neighbor_af', 'additional_paths_receive')
235
+ ret.to_sym unless ret.nil?
228
236
  end
229
237
 
230
238
  # -----------------------
@@ -249,7 +257,8 @@ module Cisco
249
257
  end
250
258
 
251
259
  def default_additional_paths_send
252
- config_get_default('bgp_neighbor_af', 'additional_paths_send').to_sym
260
+ ret = config_get_default('bgp_neighbor_af', 'additional_paths_send')
261
+ ret.to_sym unless ret.to_s == ''
253
262
  end
254
263
 
255
264
  # -----------------------
@@ -258,7 +267,7 @@ module Cisco
258
267
  def default_originate_get
259
268
  val = config_get('bgp_neighbor_af', 'default_originate', @get_args)
260
269
  return nil unless val
261
- (val[/route-map/]) ? val.split.last : true
270
+ (val[/route-(map|policy)/]) ? val.split.last : true
262
271
  end
263
272
 
264
273
  def default_originate
@@ -272,7 +281,11 @@ module Cisco
272
281
  end
273
282
 
274
283
  def default_originate_set(state, map=nil)
275
- map = "route-map #{map}" unless map.nil?
284
+ if platform == :ios_xr
285
+ map = "route-policy #{map}" unless map.nil?
286
+ else
287
+ map = "route-map #{map}" unless map.nil?
288
+ end
276
289
  set_args_keys(state: (state ? '' : 'no'), map: map)
277
290
  config_set('bgp_neighbor_af', 'default_originate', @set_args)
278
291
  end
@@ -545,23 +558,50 @@ module Cisco
545
558
  end
546
559
 
547
560
  # -----------------------
548
- # <state> send-community [ both | extended | standard ]
549
- # NOTE: 'standard' is default but does not nvgen on some platforms
550
- # Returns: none, both, extended, or standard
561
+ # Nexus and XR implementations of send community differ enough that it makes
562
+ # sense to split up the individual methods to support them
551
563
  def send_community
552
564
  val = config_get('bgp_neighbor_af', 'send_community', @get_args)
553
565
  return default_send_community if val.nil?
566
+ platform == :nexus ? send_community_nexus(val) : send_community_xr(val)
567
+ end
568
+
569
+ # Nexus: <state> send-community [ both | extended | standard ]
570
+ # NOTE: 'standard' is default but does not nvgen on some platforms
571
+ # Returns: none, both, extended, or standard
572
+ def send_community_nexus(val)
554
573
  val = val.split.last
555
574
  return 'standard' if val[/send-community/] # Workaround
556
575
  val
557
576
  end
558
577
 
578
+ # XR: 'send-community-ebgp' and 'send-extended-community-ebgp' are
579
+ # the equivalents of the NXOS: standard | extended functionality
580
+ # Returns: node, 'send-community-ebgp', 'send-extended-community-ebgp' or
581
+ # 'send-community-ebgp send-extended-community-ebgp' which is the 'both'
582
+ # keyword equivalent
583
+ def send_community_xr(val)
584
+ if val == ['send-community-ebgp', 'send-extended-community-ebgp']
585
+ val = 'both'
586
+ elsif val == ['send-community-ebgp']
587
+ val = 'standard'
588
+ else # val == ['send-extended-community-ebgp']
589
+ val = 'extended'
590
+ end
591
+ val
592
+ end
593
+
559
594
  def send_community=(val)
595
+ platform == :nexus ? send_comm_nexus_set(val) : send_comm_ios_xr_set(val)
596
+ end
597
+
598
+ def send_comm_nexus_set(val)
560
599
  if val[/none/]
561
600
  state = 'no'
562
601
  val = 'both'
563
602
  end
564
603
  if val[/extended|standard/]
604
+ # Case where already configured.
565
605
  case send_community
566
606
  when /both/
567
607
  state = 'no'
@@ -580,6 +620,33 @@ module Cisco
580
620
  config_set('bgp_neighbor_af', 'send_community', @set_args)
581
621
  end
582
622
 
623
+ def send_comm_ios_xr_set(val)
624
+ case val.to_s
625
+ when 'none'
626
+ set_args_keys(state: 'no', attr: 'send-community-ebgp')
627
+ config_set('bgp_neighbor_af', 'send_community', @set_args)
628
+ set_args_keys(state: 'no', attr: 'send-extended-community-ebgp')
629
+ config_set('bgp_neighbor_af', 'send_community', @set_args)
630
+ when 'standard'
631
+ set_args_keys(state: '', attr: 'send-community-ebgp')
632
+ config_set('bgp_neighbor_af', 'send_community', @set_args)
633
+ set_args_keys(state: 'no', attr: 'send-extended-community-ebgp')
634
+ config_set('bgp_neighbor_af', 'send_community', @set_args)
635
+ when 'extended'
636
+ set_args_keys(state: 'no', attr: 'send-community-ebgp')
637
+ config_set('bgp_neighbor_af', 'send_community', @set_args)
638
+ set_args_keys(state: '', attr: 'send-extended-community-ebgp')
639
+ config_set('bgp_neighbor_af', 'send_community', @set_args)
640
+ when 'both'
641
+ set_args_keys(state: '', attr: 'send-community-ebgp')
642
+ config_set('bgp_neighbor_af', 'send_community', @set_args)
643
+ set_args_keys(state: '', attr: 'send-extended-community-ebgp')
644
+ config_set('bgp_neighbor_af', 'send_community', @set_args)
645
+ else
646
+ fail ArgumentError, "Invalid value '#{val}'"
647
+ end
648
+ end
649
+
583
650
  def default_send_community
584
651
  config_get_default('bgp_neighbor_af', 'send_community')
585
652
  end
@@ -0,0 +1,183 @@
1
+ # NXAPI implementation of BridgeDomain class
2
+ #
3
+ # February 2016, Rohan Gandhi Korlepara
4
+ #
5
+ # Copyright (c) 2015-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
+ require_relative 'feature'
21
+
22
+ module Cisco
23
+ # node_utils class for bridge_domain
24
+ class BridgeDomain < NodeUtil
25
+ attr_reader :bd_ids
26
+
27
+ def initialize(bds, instantiate=true)
28
+ # Spaces are removed as bridge-domain cli doesn't accept value with
29
+ # space
30
+ @bd_ids = bds.to_s.gsub(/\s+/, '')
31
+ fail 'bridge-domain value is empty' if @bd_ids.empty? # no empty strings
32
+
33
+ create if instantiate
34
+ end
35
+
36
+ def to_s
37
+ "Bridge Domain #{bd_ids}"
38
+ end
39
+
40
+ # This will expand the string to a list of bds as integers
41
+ def self.bd_ids_to_array(bdid_string)
42
+ list = []
43
+ narray = bdid_string.split(',')
44
+ narray.each do |elem|
45
+ if elem.include?('-')
46
+ es = elem.gsub('-', '..')
47
+ ea = es.split('..').map { |d| Integer(d) }
48
+ er = ea[0]..ea[1]
49
+ list << er.to_a
50
+ else
51
+ list << elem.to_i
52
+ end
53
+ end
54
+ list.flatten
55
+ end
56
+
57
+ # This method will generate a batched string if a list is passed as
58
+ # argument
59
+ # Input would be as [1,2,3,4,5,10,11,12,7,30,100,31,32]
60
+ # output will be 1-5,10-12,7,30,100,31-32
61
+ def self.bd_list_to_string(bd_list)
62
+ farray = bd_list.compact
63
+ lranges = []
64
+ unless farray.empty?
65
+ left = bd_list.first
66
+ right = nil
67
+ farray.each do |aelem|
68
+ if right && aelem != right.succ
69
+ if left == right
70
+ lranges << left
71
+ else
72
+ lranges << Range.new(left, right)
73
+ end
74
+ left = aelem
75
+ end
76
+ right = aelem
77
+ end
78
+ if left == right
79
+ lranges << left
80
+ else
81
+ lranges << Range.new(left, right)
82
+ end
83
+ end
84
+ lranges.to_s.gsub('..', '-').delete('[').delete(']').delete(' ')
85
+ end
86
+
87
+ def self.bds
88
+ hash = {}
89
+ bd_list = config_get('bridge_domain', 'all_bds')
90
+ return hash if bd_list.nil?
91
+
92
+ final_bd_list =
93
+ bd_list.map { |elem| BridgeDomain.bd_ids_to_array(elem) }
94
+ .flatten.uniq.sort
95
+ final_bd_list.each do |id|
96
+ hash[id.to_s] = BridgeDomain.new(id, false)
97
+ end
98
+ hash
99
+ end
100
+
101
+ # This function will first add bds to the system bridge-domain and then
102
+ # create the bds. If bds already existing then just create. Else add the
103
+ # non added bds to system range first then create all. This is to avoid the
104
+ # idempotency issue as system add command throws error if a bd is already
105
+ # present in the system range.
106
+ def create
107
+ sys_bds_array = BridgeDomain.bd_ids_to_array(system_bridge_domain)
108
+ inp_bds_array = BridgeDomain.bd_ids_to_array(@bd_ids)
109
+ if (inp_bds_array - sys_bds_array).any?
110
+ add_bds = BridgeDomain.bd_list_to_string(inp_bds_array - sys_bds_array)
111
+ config_set('bridge_domain', 'system_bridge_domain', oper: 'add',
112
+ bd: add_bds)
113
+ end
114
+ config_set('bridge_domain', 'create', bd: @bd_ids)
115
+ end
116
+
117
+ def destroy
118
+ config_set('bridge_domain', 'destroy', bd: @bd_ids)
119
+ config_set('bridge_domain', 'system_bridge_domain', oper: 'remove',
120
+ bd: @bd_ids)
121
+ end
122
+
123
+ ########################################################
124
+ # PROPERTIES #
125
+ ########################################################
126
+
127
+ # Bridge-Domain name assigning case
128
+ # bridge-domain 100
129
+ # name bd100
130
+ def bd_name
131
+ config_get('bridge_domain', 'bd_name', bd: @bd_ids)
132
+ end
133
+
134
+ def bd_name=(str)
135
+ str = str.to_s
136
+ state = str.empty? ? 'no' : ''
137
+ config_set('bridge_domain', 'bd_name', bd: @bd_ids, state: state,
138
+ name: str)
139
+ end
140
+
141
+ def default_bd_name
142
+ config_get_default('bridge_domain', 'bd_name')
143
+ end
144
+
145
+ # Bridge-Domain type change to fabric-control
146
+ # bridge-domain 100
147
+ # fabric-control
148
+ # This type property can be defined only for one bd
149
+ def fabric_control
150
+ config_get('bridge_domain', 'fabric_control', bd: @bd_ids)
151
+ end
152
+
153
+ def fabric_control=(val)
154
+ state = (val) ? '' : 'no'
155
+ config_set('bridge_domain', 'fabric_control', bd: @bd_ids, state: state)
156
+ end
157
+
158
+ def default_fabric_control
159
+ config_get_default('bridge_domain', 'fabric_control')
160
+ end
161
+
162
+ # Bridge-Domain Shutdown case
163
+ # bridge-domain 100
164
+ # shutdown
165
+ def shutdown
166
+ config_get('bridge_domain', 'shutdown', bd: @bd_ids)
167
+ end
168
+
169
+ def shutdown=(val)
170
+ state = (val) ? '' : 'no'
171
+ config_set('bridge_domain', 'shutdown', bd: @bd_ids, state: state)
172
+ end
173
+
174
+ def default_shutdown
175
+ config_get_default('bridge_domain', 'shutdown')
176
+ end
177
+
178
+ # getter for system bridge-domain
179
+ def system_bridge_domain
180
+ config_get('bridge_domain', 'system_bridge_domain')
181
+ end
182
+ end # Class
183
+ end # Module