cisco_node_utils 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -26,6 +26,10 @@ module Cisco
26
26
  validate_args(name)
27
27
  end
28
28
 
29
+ def to_s
30
+ "interface_channel_group #{name}"
31
+ end
32
+
29
33
  def self.interfaces
30
34
  hash = {}
31
35
  all = config_get('interface_channel_group', 'all_interfaces')
@@ -52,10 +56,6 @@ module Cisco
52
56
  @set_args = @get_args.merge!(hash) unless hash.empty?
53
57
  end
54
58
 
55
- def fail_cli(e)
56
- fail "[#{@name}] '#{e.command}' : #{e.clierror}"
57
- end
58
-
59
59
  ########################################################
60
60
  # PROPERTIES #
61
61
  ########################################################
@@ -65,12 +65,13 @@ module Cisco
65
65
  end
66
66
 
67
67
  def channel_group=(group)
68
- # 'force' is needed by cli_nxos to handle the case where a port-channel
68
+ # 'force' is needed by NXOS to handle the case where a port-channel
69
69
  # interface is created prior to the channel-group cli; in which case
70
70
  # the properties of the port-channel interface will be different from
71
71
  # the ethernet interface. 'force' is not needed if the port-channel is
72
72
  # created as a result of the channel-group cli but since it does no
73
73
  # harm we will use it every time.
74
+ # IOS XR simply ignores 'force'
74
75
  if group
75
76
  state = ''
76
77
  force = 'force'
@@ -81,7 +82,11 @@ module Cisco
81
82
  config_set('interface_channel_group', 'channel_group',
82
83
  set_args_keys(state: state, group: group, force: force))
83
84
  rescue Cisco::CliError => e
84
- fail_cli(e)
85
+ # Some XR platforms do not support channel-group configuration
86
+ # on some OS versions. Since this is an OS version difference and not
87
+ # a platform difference, we can't handle this in the YAML.
88
+ raise unless e.message[/the entered commands do not exist/]
89
+ raise Cisco::UnsupportedError.new('interface', 'channel_group')
85
90
  end
86
91
 
87
92
  def default_channel_group
@@ -97,8 +102,6 @@ module Cisco
97
102
  state = desc.strip.empty? ? 'no' : ''
98
103
  config_set('interface_channel_group', 'description',
99
104
  set_args_keys(state: state, desc: desc))
100
- rescue Cisco::CliError => e
101
- fail_cli(e)
102
105
  end
103
106
 
104
107
  def default_description
@@ -113,8 +116,6 @@ module Cisco
113
116
  def shutdown=(state)
114
117
  config_set('interface_channel_group', 'shutdown',
115
118
  set_args_keys(state: state ? '' : 'no'))
116
- rescue Cisco::CliError => e
117
- fail_cli(e)
118
119
  end
119
120
 
120
121
  def default_shutdown
@@ -41,8 +41,7 @@ module Cisco
41
41
  @ospf_name = ospf_name
42
42
 
43
43
  return unless create
44
- # enable feature ospf if it isn't
45
- RouterOspf.enable unless RouterOspf.enabled
44
+ Feature.ospf_enable
46
45
 
47
46
  config_set('interface_ospf', 'area', @interface.name,
48
47
  '', @ospf_name, area)
@@ -32,6 +32,10 @@ module Cisco
32
32
  create if instantiate
33
33
  end
34
34
 
35
+ def to_s
36
+ "interface_port_channel #{name}"
37
+ end
38
+
35
39
  def self.interfaces
36
40
  hash = {}
37
41
  intf_list = config_get('interface', 'all_interfaces')
@@ -65,8 +69,6 @@ module Cisco
65
69
  no_cmd = (state ? '' : 'no')
66
70
  config_set('interface_portchannel',
67
71
  'lacp_graceful_convergence', @name, no_cmd)
68
- rescue Cisco::CliError => e
69
- raise "[#{@name}] '#{e.command}' : #{e.clierror}"
70
72
  end
71
73
 
72
74
  def default_lacp_graceful_convergence
@@ -79,8 +81,6 @@ module Cisco
79
81
 
80
82
  def lacp_max_bundle=(val)
81
83
  config_set('interface_portchannel', 'lacp_max_bundle', @name, val)
82
- rescue Cisco::CliError => e
83
- raise "[#{@name}] '#{e.command}' : #{e.clierror}"
84
84
  end
85
85
 
86
86
  def default_lacp_max_bundle
@@ -93,8 +93,6 @@ module Cisco
93
93
 
94
94
  def lacp_min_links=(val)
95
95
  config_set('interface_portchannel', 'lacp_min_links', @name, val)
96
- rescue Cisco::CliError => e
97
- raise "[#{@name}] '#{e.command}' : #{e.clierror}"
98
96
  end
99
97
 
100
98
  def default_lacp_min_links
@@ -109,8 +107,6 @@ module Cisco
109
107
  no_cmd = (state ? '' : 'no')
110
108
  config_set('interface_portchannel',
111
109
  'lacp_suspend_individual', @name, no_cmd)
112
- rescue Cisco::CliError => e
113
- raise "[#{@name}] '#{e.command}' : #{e.clierror}"
114
110
  end
115
111
 
116
112
  def default_lacp_suspend_individual
@@ -130,8 +126,6 @@ module Cisco
130
126
  end
131
127
  config_set('interface_portchannel',
132
128
  'port_hash_distribution', @name, state, val)
133
- rescue Cisco::CliError => e
134
- raise "[#{@name}] '#{e.command}' : #{e.clierror}"
135
129
  end
136
130
 
137
131
  def default_port_hash_distribution
@@ -146,8 +140,6 @@ module Cisco
146
140
  no_cmd = (state ? '' : 'no')
147
141
  config_set('interface_portchannel',
148
142
  'port_load_defer', @name, no_cmd)
149
- rescue Cisco::CliError => e
150
- raise "[#{@name}] '#{e.command}' : #{e.clierror}"
151
143
  end
152
144
 
153
145
  def default_port_load_defer
@@ -15,7 +15,7 @@
15
15
  # limitations under the License.
16
16
 
17
17
  require_relative 'node_util'
18
- require_relative 'vni'
18
+ require_relative 'feature'
19
19
 
20
20
  module Cisco
21
21
  # InterfaceServiceVni - node utility class for Service VNI Instance commands
@@ -30,6 +30,10 @@ module Cisco
30
30
  create if instantiate
31
31
  end
32
32
 
33
+ def to_s
34
+ "interface_service_vni #{name} #{@sid}"
35
+ end
36
+
33
37
  def self.svc_vni_ids
34
38
  hash = {}
35
39
  intf_list = config_get('interface', 'all_interfaces')
@@ -49,7 +53,7 @@ module Cisco
49
53
  end
50
54
 
51
55
  def create
52
- Vni.feature_vni_enable unless Vni.feature_vni_enabled
56
+ Feature.vni_enable
53
57
  @set_args[:state] = ''
54
58
  config_set('interface_service_vni', 'create_destroy', @set_args)
55
59
  end
@@ -87,7 +91,7 @@ module Cisco
87
91
  end
88
92
 
89
93
  def encapsulation_profile_vni=(profile)
90
- Vni.feature_vni_enable unless Vni.feature_vni_enabled
94
+ Feature.vni_enable
91
95
  state = profile.empty? ? 'no' : ''
92
96
  current = encapsulation_profile_vni
93
97
 
@@ -103,8 +107,6 @@ module Cisco
103
107
  config_set('interface_service_vni', 'encapsulation_profile_vni',
104
108
  set_args_keys(state: state, profile: profile))
105
109
  end
106
- rescue Cisco::CliError => e
107
- raise "[#{@name}] '#{e.command}' : #{e.clierror}"
108
110
  end
109
111
 
110
112
  def default_encapsulation_profile_vni
@@ -121,8 +123,6 @@ module Cisco
121
123
  def shutdown=(state)
122
124
  config_set('interface_service_vni', 'shutdown',
123
125
  set_args_keys(state: state ? '' : 'no'))
124
- rescue Cisco::CliError => e
125
- raise "[#{@name}] '#{e.command}' : #{e.clierror}"
126
126
  end
127
127
 
128
128
  def default_shutdown
@@ -0,0 +1,248 @@
1
+ # February 2016, Sai Chintalapudi
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
+ require_relative 'node_util'
18
+
19
+ module Cisco
20
+ # node_utils class for itd_device_group
21
+ class ItdDeviceGroup < NodeUtil
22
+ attr_reader :name
23
+
24
+ def initialize(name, instantiate=true)
25
+ fail TypeError unless name.is_a?(String)
26
+ fail ArgumentError unless name.length > 0
27
+ @name = name
28
+
29
+ set_args_keys_default
30
+ create if instantiate
31
+ end
32
+
33
+ def self.itds
34
+ hash = {}
35
+ groups = config_get('itd_device_group',
36
+ 'all_itd_device_groups')
37
+ return hash if groups.nil?
38
+
39
+ groups.each do |id|
40
+ hash[id] = ItdDeviceGroup.new(id, false)
41
+ end
42
+ hash
43
+ end
44
+
45
+ ########################################################
46
+ # PROPERTIES #
47
+ ########################################################
48
+
49
+ def create
50
+ Feature.itd_enable
51
+ config_set('itd_device_group', 'create', name: @name)
52
+ end
53
+
54
+ def destroy
55
+ config_set('itd_device_group', 'destroy', name: @name)
56
+ end
57
+
58
+ # Helper method to delete @set_args hash keys
59
+ def set_args_keys_default
60
+ keys = { name: @name }
61
+ @get_args = @set_args = keys
62
+ end
63
+
64
+ # rubocop:disable Style/AccessorMethodName
65
+ def set_args_keys(hash={})
66
+ set_args_keys_default
67
+ @set_args = @get_args.merge!(hash) unless hash.empty?
68
+ end
69
+
70
+ # extract value of property from probe
71
+ def extract_value(prop, prefix=nil)
72
+ prefix = prop if prefix.nil?
73
+ probe_match = probe_get
74
+
75
+ # matching probe not found
76
+ return nil if probe_match.nil? # no matching probe found
77
+
78
+ # property not defined for matching probe
79
+ return nil unless probe_match.names.include?(prop)
80
+
81
+ # extract and return value that follows prefix + <space>
82
+ regexp = Regexp.new("#{Regexp.escape(prefix)} (?<extracted>.*)")
83
+ value_match = regexp.match(probe_match[prop])
84
+ return nil if value_match.nil?
85
+ value_match[:extracted]
86
+ end
87
+
88
+ # prepend property name prefix/keyword to value
89
+ def attach_prefix(val, prop, prefix=nil)
90
+ prefix = prop.to_s if prefix.nil?
91
+ @set_args[prop] = val.to_s.empty? ? val : "#{prefix} #{val}"
92
+ end
93
+
94
+ # probe configuration is all done in a single line (like below)
95
+ # probe tcp port 32 frequency 10 timeout 5 retry-down-count 3 ...
96
+ # probe udp port 23 frequency 10 timeout 5 retry-down-count 3 ...
97
+ # probe icmp frequency 10 timeout 5 retry-down-count 3 retry-up-count 3
98
+ # probe dns host 8.8.8.8 frequency 10 timeout 5 retry-down-count 3 ...
99
+ # also the 'control enable' can be set if the type is tcp or udp only
100
+ # probe udp port 23 control enable frequency 10 timeout 5 ...
101
+ def probe_get
102
+ str = config_get('itd_device_group', 'probe', @get_args)
103
+ return nil if str.nil?
104
+ regexp = Regexp.new('(?<type>\S+)'\
105
+ ' *(?<dns_host>host \S+)?'\
106
+ ' *(?<port>port \d+)?'\
107
+ ' *(?<control>control \S+)?'\
108
+ ' *(?<frequency>frequency \d+)?'\
109
+ ' *(?<timeout>timeout \d+)'\
110
+ ' *(?<retry_down>retry-down-count \d+)'\
111
+ ' *(?<retry_up>retry-up-count \d+)')
112
+ regexp.match(str)
113
+ end
114
+
115
+ def probe_control
116
+ val = extract_value('control')
117
+ return default_probe_control if val.nil?
118
+ val == 'enable' ? true : default_probe_control
119
+ end
120
+
121
+ def probe_control=(control)
122
+ if control
123
+ @set_args[:control] = 'control enable'
124
+ else
125
+ @set_args[:control] = ''
126
+ end
127
+ end
128
+
129
+ def default_probe_control
130
+ config_get_default('itd_device_group', 'probe_control')
131
+ end
132
+
133
+ def probe_dns_host
134
+ extract_value('dns_host', 'host')
135
+ end
136
+
137
+ def probe_dns_host=(dns_host)
138
+ attach_prefix(dns_host, :dns_host, 'host')
139
+ end
140
+
141
+ def probe_frequency
142
+ val = extract_value('frequency')
143
+ return default_probe_frequency if val.nil?
144
+ val.to_i
145
+ end
146
+
147
+ def probe_frequency=(frequency)
148
+ attach_prefix(frequency, :frequency)
149
+ end
150
+
151
+ def default_probe_frequency
152
+ config_get_default('itd_device_group', 'probe_frequency')
153
+ end
154
+
155
+ def probe_port
156
+ val = extract_value('port')
157
+ val.to_i unless val.nil?
158
+ end
159
+
160
+ def probe_port=(port)
161
+ attach_prefix(port, :port)
162
+ end
163
+
164
+ def probe_retry_down
165
+ val = extract_value('retry_down', 'retry-down-count')
166
+ return default_probe_retry_down if val.nil?
167
+ val.to_i
168
+ end
169
+
170
+ def probe_retry_down=(rdc)
171
+ attach_prefix(rdc, :retry_down_count, 'retry-down-count')
172
+ end
173
+
174
+ def default_probe_retry_down
175
+ config_get_default('itd_device_group', 'probe_retry_down')
176
+ end
177
+
178
+ def probe_retry_up
179
+ val = extract_value('retry_up', 'retry-up-count')
180
+ return default_probe_retry_up if val.nil?
181
+ val.to_i
182
+ end
183
+
184
+ def probe_retry_up=(ruc)
185
+ attach_prefix(ruc, :retry_up_count, 'retry-up-count')
186
+ end
187
+
188
+ def default_probe_retry_up
189
+ config_get_default('itd_device_group', 'probe_retry_up')
190
+ end
191
+
192
+ def probe_timeout
193
+ val = extract_value('timeout')
194
+ return default_probe_timeout if val.nil?
195
+ val.to_i
196
+ end
197
+
198
+ def probe_timeout=(timeout)
199
+ attach_prefix(timeout, :timeout)
200
+ end
201
+
202
+ def default_probe_timeout
203
+ config_get_default('itd_device_group', 'probe_timeout')
204
+ end
205
+
206
+ def probe_type
207
+ match = probe_get
208
+ return default_probe_type if match.nil?
209
+ match.names.include?('type') ? match[:type] : default_probe_type
210
+ end
211
+
212
+ def probe_type=(type)
213
+ @set_args[:type] = type
214
+ end
215
+
216
+ def default_probe_type
217
+ config_get_default('itd_device_group', 'probe_type')
218
+ end
219
+
220
+ def probe_set(attrs)
221
+ if attrs[:probe_type] == false
222
+ cmd = 'probe_type'
223
+ @set_args[:state] = 'no'
224
+ else
225
+ cmd = 'probe'
226
+ set_args_keys_default
227
+ set_args_keys(attrs)
228
+ [:probe_type,
229
+ :probe_dns_host,
230
+ :probe_port,
231
+ :probe_control,
232
+ :probe_frequency,
233
+ :probe_timeout,
234
+ :probe_retry_down,
235
+ :probe_retry_up,
236
+ ].each do |p|
237
+ attrs[p] = '' if attrs[p].nil?
238
+ send(p.to_s + '=', attrs[p])
239
+ end
240
+ # for boolean we need to do this
241
+ send('probe_control=', false) if attrs[:probe_control] == ''
242
+ @get_args = @set_args
243
+ end
244
+ config_set('itd_device_group', cmd, @set_args)
245
+ set_args_keys_default
246
+ end
247
+ end # Class
248
+ end # Module
@@ -0,0 +1,144 @@
1
+ # February 2016, Sai Chintalapudi
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
+ require_relative 'node_util'
18
+ require_relative 'itd_device_group'
19
+
20
+ module Cisco
21
+ # node_utils class for itd_device_group_node
22
+ class ItdDeviceGroupNode < ItdDeviceGroup
23
+ attr_reader :itd_device_group_name, :name, :node_type
24
+
25
+ def initialize(itd_dg_name, node_name, node_type, instantiate=true)
26
+ fail TypeError unless itd_dg_name.is_a?(String)
27
+ fail TypeError unless node_name.is_a?(String)
28
+ fail ArgumentError unless itd_dg_name.length > 0
29
+ fail ArgumentError unless node_name.length > 0
30
+
31
+ @itd_device_group_name = itd_dg_name
32
+ @itddg = ItdDeviceGroup.itds[itd_dg_name]
33
+ fail "itd device-group #{itd_dg_name} does not exist" if
34
+ @itddg.nil?
35
+ @name = node_name
36
+ @node_type = node_type
37
+
38
+ set_args_keys_default
39
+ create_node if instantiate
40
+ end
41
+
42
+ # itd_device_group_nodes have the name form as
43
+ # node ip 1.1.1.1
44
+ # node IPv6 2000::1
45
+ # and they depdend on the device_group
46
+ def self.itd_nodes(node_name=nil)
47
+ fail TypeError unless node_name.is_a?(String) || node_name.nil?
48
+ itd_nodes = {}
49
+ itd_list = ItdDeviceGroup.itds
50
+ return itd_nodes if itd_list.nil?
51
+ itd_list.keys.each do |name|
52
+ itd_nodes[name] = {}
53
+ match = config_get('itd_device_group',
54
+ 'all_itd_device_group_nodes', name: name)
55
+ next if match.nil?
56
+ match.each do |vars|
57
+ ntype = vars[0]
58
+ nname = vars[1].strip
59
+ next unless node_name.nil? || nname == node_name
60
+ itd_nodes[name][nname] =
61
+ ItdDeviceGroupNode.new(name, nname, ntype, false)
62
+ end
63
+ end
64
+ itd_nodes
65
+ end
66
+
67
+ ########################################################
68
+ # PROPERTIES #
69
+ ########################################################
70
+
71
+ def ==(other)
72
+ (itd_device_group_name == other.itd_device_group_name) &&
73
+ (name == other.name) && (node_type == other.node_type)
74
+ end
75
+
76
+ def create_node
77
+ config_set('itd_device_group', 'create_node',
78
+ name: @itddg.name, ntype: @node_type, nname: @name)
79
+ end
80
+
81
+ def destroy
82
+ config_set('itd_device_group', 'destroy_node', name: @itddg.name,
83
+ ntype: @node_type, nname: @name)
84
+ end
85
+
86
+ # Helper method to delete @set_args hash keys
87
+ def set_args_keys_default
88
+ @set_args = { name: @itddg.name }
89
+ @set_args[:ntype] = @node_type
90
+ @set_args[:nname] = @name
91
+ @get_args = @set_args
92
+ end
93
+
94
+ def hot_standby
95
+ config_get('itd_device_group', 'hot_standby', @get_args)
96
+ end
97
+
98
+ # DO NOT call this directly
99
+ def lhot_standby=(state)
100
+ no_cmd = (state ? '' : 'no')
101
+ @set_args[:state] = no_cmd
102
+ config_set('itd_device_group', 'hot_standby', @set_args)
103
+ set_args_keys_default
104
+ end
105
+
106
+ def default_hot_standby
107
+ config_get_default('itd_device_group', 'hot_standby')
108
+ end
109
+
110
+ def weight
111
+ config_get('itd_device_group', 'weight', @get_args)
112
+ end
113
+
114
+ # DO NOT call this directly
115
+ def lweight=(val)
116
+ @set_args[:state] = val == default_weight ? 'no' : ''
117
+ @set_args[:weight] = val
118
+ config_set('itd_device_group', 'weight', @set_args)
119
+ end
120
+
121
+ # Call this for setting hot_standby and weight together because
122
+ # the CLI is pretty weird and it accepts these params in a very
123
+ # particular way and they cannot even be reset unless proper
124
+ # order is followed
125
+ def hs_weight(hs, wt)
126
+ if hs != hot_standby && hot_standby == default_hot_standby
127
+ self.lweight = wt unless weight == wt
128
+ self.lhot_standby = hs
129
+ elsif hs != hot_standby && hot_standby != default_hot_standby
130
+ self.lhot_standby = hs
131
+ self.lweight = wt unless weight == wt
132
+ elsif wt != weight && weight == default_weight
133
+ self.lweight = wt
134
+ elsif wt != weight && weight != default_weight
135
+ self.lweight = wt
136
+ end
137
+ set_args_keys_default
138
+ end
139
+
140
+ def default_weight
141
+ config_get_default('itd_device_group', 'weight')
142
+ end
143
+ end # Class
144
+ end # Module