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
@@ -0,0 +1,523 @@
1
+ # Mar 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 ItdService < 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
+ list = []
36
+ services = config_get('itd_service',
37
+ 'all_itds')
38
+ return hash if services.nil?
39
+
40
+ services.each do |service|
41
+ # The show cmd shows more than service,
42
+ # we get other things like device-groups etc.
43
+ # so filter it out to just get the service
44
+ next if service.include?('device-group')
45
+ next if service.include?('session')
46
+ next if service.include?('statistics')
47
+ list << service
48
+ end
49
+
50
+ list.each do |id|
51
+ hash[id] = ItdService.new(id, false)
52
+ end
53
+ hash
54
+ end
55
+
56
+ ########################################################
57
+ # PROPERTIES #
58
+ ########################################################
59
+
60
+ def create
61
+ Feature.itd_enable
62
+ config_set('itd_service', 'create', name: @name)
63
+ end
64
+
65
+ def destroy
66
+ # the service MUST be shutdown before it can be destroyed
67
+ config_set('itd_service', 'shutdown', name: @name, state: '')
68
+ config_set('itd_service', 'destroy', name: @name)
69
+ end
70
+
71
+ # Helper method to delete @set_args hash keys
72
+ def set_args_keys_default
73
+ keys = { name: @name }
74
+ @get_args = @set_args = keys
75
+ end
76
+
77
+ # rubocop:disable Style/AccessorMethodName
78
+ def set_args_keys(hash={})
79
+ set_args_keys_default
80
+ @set_args = @get_args.merge!(hash) unless hash.empty?
81
+ end
82
+
83
+ # extract value of property from load-balance
84
+ def extract_value(prop, prefix=nil)
85
+ prefix = prop if prefix.nil?
86
+ lb_match = lb_get
87
+
88
+ # matching lb not found
89
+ return nil if lb_match.nil? # no matching lb found
90
+
91
+ # property not defined for matching lb
92
+ return nil unless lb_match.names.include?(prop)
93
+
94
+ # extract and return value that follows prefix + <space>
95
+ regexp = Regexp.new("#{Regexp.escape(prefix)} (?<extracted>.*)")
96
+ value_match = regexp.match(lb_match[prop])
97
+ return nil if value_match.nil?
98
+ value_match[:extracted]
99
+ end
100
+
101
+ # prepend property name prefix/keyword to value
102
+ def attach_prefix(val, prop, prefix=nil)
103
+ prefix = prop.to_s if prefix.nil?
104
+ @set_args[prop] = val.to_s.empty? ? val : "#{prefix} #{val}"
105
+ end
106
+
107
+ def access_list
108
+ config_get('itd_service', 'access_list', @get_args)
109
+ end
110
+
111
+ def access_list=(val)
112
+ if val.empty?
113
+ @set_args[:state] = 'no'
114
+ @set_args[:al] = access_list
115
+ config_set('itd_service', 'access_list', @set_args) unless
116
+ access_list.empty?
117
+ else
118
+ @set_args[:state] = ''
119
+ @set_args[:al] = val
120
+ config_set('itd_service', 'access_list', @set_args)
121
+ end
122
+ set_args_keys_default
123
+ end
124
+
125
+ def default_access_list
126
+ config_get_default('itd_service', 'access_list')
127
+ end
128
+
129
+ def device_group
130
+ config_get('itd_service', 'device_group', @get_args)
131
+ end
132
+
133
+ def device_group=(val)
134
+ if val.empty?
135
+ @set_args[:state] = 'no'
136
+ @set_args[:dg] = device_group
137
+ config_set('itd_service', 'device_group', @set_args) unless
138
+ device_group.empty?
139
+ else
140
+ @set_args[:state] = ''
141
+ @set_args[:dg] = val
142
+ config_set('itd_service', 'device_group', @set_args)
143
+ end
144
+ set_args_keys_default
145
+ end
146
+
147
+ def default_device_group
148
+ config_get_default('itd_service', 'device_group')
149
+ end
150
+
151
+ def exclude_access_list
152
+ config_get('itd_service', 'exclude_access_list', @get_args)
153
+ end
154
+
155
+ def exclude_access_list=(val)
156
+ if val.empty?
157
+ @set_args[:state] = 'no'
158
+ @set_args[:al] = exclude_access_list
159
+ config_set('itd_service', 'exclude_access_list', @set_args) unless
160
+ exclude_access_list.empty?
161
+ else
162
+ @set_args[:state] = ''
163
+ @set_args[:al] = val
164
+ config_set('itd_service', 'exclude_access_list', @set_args)
165
+ end
166
+ set_args_keys_default
167
+ end
168
+
169
+ def default_exclude_access_list
170
+ config_get_default('itd_service', 'exclude_access_list')
171
+ end
172
+
173
+ def fail_action
174
+ config_get('itd_service', 'fail_action', @get_args)
175
+ end
176
+
177
+ def fail_action=(state)
178
+ no_cmd = (state ? '' : 'no')
179
+ @set_args[:state] = no_cmd
180
+ config_set('itd_service', 'fail_action', @set_args)
181
+ set_args_keys_default
182
+ end
183
+
184
+ def default_fail_action
185
+ config_get_default('itd_service', 'fail_action')
186
+ end
187
+
188
+ # this is an array like:
189
+ # [['ethernet 1/1', '1.1.1.1'], ['port-channel 100', '2.2.2.2'],
190
+ # ['vlan 2', '3.3.3.3']]
191
+ # show command output is like: Eth1/1, Po100, Vlan2
192
+ # so translate back to the input format
193
+ def ingress_interface
194
+ list = config_get('itd_service', 'ingress_interface', @get_args)
195
+ list.each do |intf, _next_hop|
196
+ intf.gsub!('Eth', 'ethernet ')
197
+ intf.gsub!('Po', 'port-channel ')
198
+ intf.gsub!('Vlan', 'vlan ')
199
+ end
200
+ list
201
+ end
202
+
203
+ def ingress_interface_cleanup
204
+ cur_list = ingress_interface
205
+ return if cur_list.empty?
206
+ @set_args[:state] = 'no'
207
+ @set_args[:next] = ''
208
+ @set_args[:nhop] = ''
209
+ # clean up the current list first
210
+ cur_list.each do |intf, _next_hop|
211
+ @set_args[:interface] = intf
212
+ config_set('itd_service', 'ingress_interface', @set_args)
213
+ end
214
+ end
215
+
216
+ # only one next-hop is allowed per interface but
217
+ # due to nxos issues, it allows more than one;
218
+ # so the workaround is to clean up the current ingress
219
+ # intf and configure all of them again
220
+ def ingress_interface=(list)
221
+ ingress_interface_cleanup
222
+ @set_args[:state] = ''
223
+ list.each do |intf, next_hop|
224
+ @set_args[:interface] = intf
225
+ @set_args[:next] = ''
226
+ @set_args[:nhop] = ''
227
+ unless next_hop == '' || next_hop == 'default'
228
+ @set_args[:next] = 'next-hop'
229
+ @set_args[:nhop] = next_hop
230
+ end
231
+ config_set('itd_service', 'ingress_interface', @set_args)
232
+ end
233
+ set_args_keys_default
234
+ end
235
+
236
+ def default_ingress_interface
237
+ config_get_default('itd_service', 'ingress_interface')
238
+ end
239
+
240
+ # the load-balance command can take several forms like:
241
+ # load-balance method dst ip
242
+ # load-balance method dst ip-l4port tcp range 3 6
243
+ # load-balance method dst ip-l4port tcp range 3 6 buckets 8 mask-position 2
244
+ # load-balance buckets 8
245
+ # load-balance mask-position 2
246
+ def lb_get
247
+ str = config_get('itd_service', 'load_balance', @get_args)
248
+ return nil if str.nil?
249
+ if str.include?('method') && str.include?('range')
250
+ regexp = Regexp.new('load-balance *(?<bundle_select>method \S+)?'\
251
+ ' *(?<bundle_hash>\S+)?'\
252
+ ' *(?<proto>\S+)?'\
253
+ ' *(?<start_port>range \d+)?'\
254
+ ' *(?<end_port>\d+)?'\
255
+ ' *(?<buckets>buckets \d+)?'\
256
+ ' *(?<mask>mask-position \d+)?')
257
+ elsif str.include?('method')
258
+ regexp = Regexp.new('load-balance *(?<bundle_select>method \S+)?'\
259
+ ' *(?<bundle_hash>\S+)?'\
260
+ ' *(?<buckets>buckets \d+)?'\
261
+ ' *(?<mask>mask-position \d+)?') unless str.include?('range')
262
+ else
263
+ regexp = Regexp.new('load-balance *(?<buckets>buckets \d+)?'\
264
+ ' *(?<mask>mask-position \d+)?')
265
+ end
266
+ regexp.match(str)
267
+ end
268
+
269
+ def load_bal_buckets
270
+ val = extract_value('buckets')
271
+ return default_load_bal_buckets if val.nil?
272
+ val.to_i
273
+ end
274
+
275
+ def load_bal_buckets=(buckets)
276
+ attach_prefix(buckets, :buckets)
277
+ end
278
+
279
+ def default_load_bal_buckets
280
+ config_get_default('itd_service', 'load_bal_buckets')
281
+ end
282
+
283
+ def load_bal_mask_pos
284
+ val = extract_value('mask', 'mask-position')
285
+ return default_load_bal_mask_pos if val.nil?
286
+ val.to_i
287
+ end
288
+
289
+ def load_bal_mask_pos=(mask)
290
+ attach_prefix(mask, :mask, 'mask-position')
291
+ end
292
+
293
+ def default_load_bal_mask_pos
294
+ config_get_default('itd_service', 'load_bal_mask_pos')
295
+ end
296
+
297
+ def load_bal_method_bundle_hash
298
+ val = default_load_bal_method_bundle_hash
299
+ match = lb_get
300
+ return val if match.nil?
301
+ match.names.include?('bundle_hash') ? match[:bundle_hash] : val
302
+ end
303
+
304
+ def load_bal_method_bundle_hash=(bh)
305
+ @set_args[:bundle_hash] = bh
306
+ end
307
+
308
+ def default_load_bal_method_bundle_hash
309
+ config_get_default('itd_service', 'load_bal_method_bundle_hash')
310
+ end
311
+
312
+ def load_bal_method_bundle_select
313
+ val = extract_value('bundle_select', 'method')
314
+ return default_load_bal_method_bundle_select if val.nil?
315
+ val
316
+ end
317
+
318
+ def load_bal_method_bundle_select=(bs)
319
+ attach_prefix(bs, :bundle_select, 'method')
320
+ end
321
+
322
+ def default_load_bal_method_bundle_select
323
+ config_get_default('itd_service', 'load_bal_method_bundle_select')
324
+ end
325
+
326
+ def load_bal_method_end_port
327
+ val = default_load_bal_method_end_port
328
+ match = lb_get
329
+ return val if match.nil?
330
+ match.names.include?('end_port') ? match[:end_port].to_i : val
331
+ end
332
+
333
+ def load_bal_method_end_port=(enport)
334
+ @set_args[:endPort] = enport
335
+ end
336
+
337
+ def default_load_bal_method_end_port
338
+ config_get_default('itd_service', 'load_bal_method_end_port')
339
+ end
340
+
341
+ def load_bal_method_start_port
342
+ val = extract_value('start_port', 'range')
343
+ return default_load_bal_method_start_port if val.nil?
344
+ val.to_i
345
+ end
346
+
347
+ def load_bal_method_start_port=(start)
348
+ attach_prefix(start, :start_port, 'range')
349
+ end
350
+
351
+ def default_load_bal_method_start_port
352
+ config_get_default('itd_service', 'load_bal_method_start_port')
353
+ end
354
+
355
+ def load_bal_method_proto
356
+ val = default_load_bal_method_proto
357
+ match = lb_get
358
+ return val if match.nil?
359
+ match.names.include?('proto') ? match[:proto] : val
360
+ end
361
+
362
+ def load_bal_method_proto=(proto)
363
+ @set_args[:proto] = proto
364
+ end
365
+
366
+ def default_load_bal_method_proto
367
+ config_get_default('itd_service', 'load_bal_method_proto')
368
+ end
369
+
370
+ def load_bal_enable
371
+ lb_get.nil? ? default_load_bal_enable : true
372
+ end
373
+
374
+ def load_bal_enable=(enable)
375
+ @set_args[:state] = enable ? '' : 'no'
376
+ end
377
+
378
+ def default_load_bal_enable
379
+ config_get_default('itd_service', 'load_bal_enable')
380
+ end
381
+
382
+ def load_balance_set(attrs)
383
+ set_args_keys_default
384
+ set_args_keys(attrs)
385
+ [:load_bal_buckets,
386
+ :load_bal_mask_pos,
387
+ :load_bal_method_bundle_hash,
388
+ :load_bal_method_bundle_select,
389
+ :load_bal_method_end_port,
390
+ :load_bal_method_start_port,
391
+ :load_bal_method_proto,
392
+ :load_bal_enable,
393
+ ].each do |p|
394
+ attrs[p] = '' if attrs[p].nil? || attrs[p] == false
395
+ send(p.to_s + '=', attrs[p])
396
+ end
397
+ # for boolean we need to do this
398
+ send('load_bal_enable=', false) if attrs[:load_bal_enable] == ''
399
+ @get_args = @set_args
400
+ config_set('itd_service', 'load_balance', @set_args)
401
+ set_args_keys_default
402
+ end
403
+
404
+ def nat_destination
405
+ config_get('itd_service', 'nat_destination', @get_args)
406
+ end
407
+
408
+ def nat_destination=(state)
409
+ no_cmd = (state ? '' : 'no')
410
+ @set_args[:state] = no_cmd
411
+ config_set('itd_service', 'nat_destination', @set_args)
412
+ set_args_keys_default
413
+ end
414
+
415
+ def default_nat_destination
416
+ config_get_default('itd_service', 'nat_destination')
417
+ end
418
+
419
+ def peer_local
420
+ config_get('itd_service', 'peer_local', @get_args)
421
+ end
422
+
423
+ def peer_local=(val)
424
+ if val.empty?
425
+ @set_args[:state] = 'no'
426
+ current_peer_local = peer_local
427
+ @set_args[:service] = current_peer_local
428
+ config_set('itd_service', 'peer_local', @set_args) unless
429
+ current_peer_local.nil? || current_peer_local.empty?
430
+ else
431
+ @set_args[:state] = ''
432
+ @set_args[:service] = val
433
+ config_set('itd_service', 'peer_local', @set_args)
434
+ end
435
+ set_args_keys_default
436
+ end
437
+
438
+ def default_peer_local
439
+ config_get_default('itd_service', 'peer_local')
440
+ end
441
+
442
+ # peer_vdc is an array of vdc and service
443
+ def peer_vdc
444
+ config_get('itd_service', 'peer_vdc', @get_args)
445
+ end
446
+
447
+ # peer_vdc is an array of vdc and service
448
+ # only one peer_vdc is allowed per service
449
+ # ex: ['switch', 'myservice']
450
+ def peer_vdc=(parray)
451
+ if parray.empty?
452
+ @set_args[:state] = 'no'
453
+ current_peer_vdc = peer_vdc
454
+ @set_args[:vdc] = current_peer_vdc[0]
455
+ @set_args[:service] = current_peer_vdc[1]
456
+ config_set('itd_service', 'peer_vdc', @set_args) unless
457
+ current_peer_vdc[0].nil? || current_peer_vdc[1].nil?
458
+ else
459
+ @set_args[:state] = ''
460
+ @set_args[:vdc] = parray[0]
461
+ @set_args[:service] = parray[1]
462
+ config_set('itd_service', 'peer_vdc', @set_args)
463
+ end
464
+ set_args_keys_default
465
+ end
466
+
467
+ def default_peer_vdc
468
+ config_get_default('itd_service', 'peer_vdc')
469
+ end
470
+
471
+ # show command shows nothing when the service is
472
+ # shutdown which is default, but it shows "no shut"
473
+ # when it is not shut
474
+ def shutdown
475
+ config_get('itd_service', 'shutdown', @get_args)
476
+ end
477
+
478
+ def shutdown=(state)
479
+ no_cmd = (state ? '' : 'no')
480
+ @set_args[:state] = no_cmd
481
+ config_set('itd_service', 'shutdown', @set_args)
482
+ set_args_keys_default
483
+ end
484
+
485
+ def default_shutdown
486
+ config_get_default('itd_service', 'shutdown')
487
+ end
488
+
489
+ def virtual_ip
490
+ config_get('itd_service', 'virtual_ip', @get_args)
491
+ end
492
+
493
+ # VIP is a large string like:
494
+ # virtual ip 2.2.2.2 10.0.0.0 udp 10 advertise enable device-group icmpGroup
495
+ # virtual ip 2.2.2.2 10.0.0.0 udp 10 advertise enable
496
+ # virtual ip 2.2.2.2 10.0.0.0 udp 10
497
+ # virtual ip 2.2.2.2 10.0.0.0
498
+ # all of the above are unique and can be added one after the other
499
+ # the entire string is unique but not individual parts of it
500
+ # currently, only one VIP can be configured due to nxos issue
501
+ # else, the switch crashes, this limitation will be set in
502
+ # puppet manifest. Also remove the current VIPs before configuring more
503
+ def virtual_ip=(values)
504
+ @set_args[:state] = 'no'
505
+ list = virtual_ip
506
+ # remove all the virtual configs first
507
+ list.each do |line|
508
+ @set_args[:string] = line
509
+ config_set('itd_service', 'virtual_ip', @set_args)
510
+ end
511
+ @set_args[:state] = ''
512
+ values.each do |value|
513
+ @set_args[:string] = value
514
+ config_set('itd_service', 'virtual_ip', @set_args)
515
+ end
516
+ set_args_keys_default
517
+ end
518
+
519
+ def default_virtual_ip
520
+ config_get_default('itd_service', 'virtual_ip')
521
+ end
522
+ end # Class
523
+ end # Module