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,676 @@
1
+ # January 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 'interface'
19
+ require_relative 'vlan'
20
+
21
+ module Cisco
22
+ # node_utils class for stp_global
23
+ class StpGlobal < NodeUtil
24
+ attr_reader :name
25
+
26
+ def initialize(name)
27
+ fail TypeError unless name.is_a?(String)
28
+ fail ArgumentError unless name == 'default'
29
+ @name = name.downcase
30
+ @bdr = config_get('stp_global', 'bd_range')
31
+ @mr = config_get('stp_global', 'mst_range')
32
+ @mir = config_get('stp_global', 'mst_inst_range')
33
+ @vr = config_get('stp_global', 'vlan_range')
34
+ end
35
+
36
+ def self.globals
37
+ { 'default' => StpGlobal.new('default') }
38
+ end
39
+
40
+ ########################################################
41
+ # PROPERTIES #
42
+ ########################################################
43
+
44
+ # Getter: Builds an array of bd designated priority
45
+ # commands currently on the device.
46
+ # cli: bridge-domain 2-42 designated priority 40960
47
+ # bridge-domain 83-92,1000-2300 designated priority 53248
48
+ # array: [['2-42', '40960'], ['83-92,1000-2300', '53248']]
49
+ #
50
+ def bd_designated_priority
51
+ config_get('stp_global', 'bd_designated_priority')
52
+ end
53
+
54
+ def bd_designated_priority=(list)
55
+ vlans = bd_total_range_with_vlans
56
+ config_set('stp_global', 'bd_designated_priority',
57
+ state: 'no',
58
+ range: Utils.get_reset_range(@bdr, vlans),
59
+ val: '') if list.empty?
60
+ set_range_based_params(list, 'bd_designated_priority')
61
+ end
62
+
63
+ def default_bd_designated_priority
64
+ config_get_default('stp_global', 'bd_designated_priority')
65
+ end
66
+
67
+ # Getter: Builds an array of bd forward time
68
+ # commands currently on the device.
69
+ # cli: spanning-tree bridge-domain 2-42 forward-time 4
70
+ # spanning-tree bridge-domain 83-92,1000-2300 forward-time 30
71
+ # array: [['2-42', '4'], ['83-92,1000-2300', '30']]
72
+ #
73
+ def bd_forward_time
74
+ config_get('stp_global', 'bd_forward_time')
75
+ end
76
+
77
+ def bd_forward_time=(list)
78
+ vlans = bd_total_range_with_vlans
79
+ config_set('stp_global', 'bd_forward_time',
80
+ state: 'no',
81
+ range: Utils.get_reset_range(@bdr, vlans),
82
+ val: '') if list.empty?
83
+ set_range_based_params(list, 'bd_forward_time')
84
+ end
85
+
86
+ def default_bd_forward_time
87
+ config_get_default('stp_global', 'bd_forward_time')
88
+ end
89
+
90
+ # Getter: Builds an array of bd hello time
91
+ # commands currently on the device.
92
+ # cli: spanning-tree bridge-domain 2-42 hello-time 6
93
+ # spanning-tree bridge-domain 83-92,1000-2300 hello-time 9
94
+ # array: [['2-42', '6'], ['83-92,1000-2300', '9']]
95
+ #
96
+ def bd_hello_time
97
+ config_get('stp_global', 'bd_hello_time')
98
+ end
99
+
100
+ def bd_hello_time=(list)
101
+ vlans = bd_total_range_with_vlans
102
+ config_set('stp_global', 'bd_hello_time',
103
+ state: 'no',
104
+ range: Utils.get_reset_range(@bdr, vlans),
105
+ val: '') if list.empty?
106
+ set_range_based_params(list, 'bd_hello_time')
107
+ end
108
+
109
+ def default_bd_hello_time
110
+ config_get_default('stp_global', 'bd_hello_time')
111
+ end
112
+
113
+ # Getter: Builds an array of bd max age
114
+ # commands currently on the device.
115
+ # cli: spanning-tree bridge-domain 2-42 max-age 10
116
+ # spanning-tree bridge-domain 83-92,1000-2300 max-age 40
117
+ # array: [['2-42', '10'], ['83-92,1000-2300', '40']]
118
+ #
119
+ def bd_max_age
120
+ config_get('stp_global', 'bd_max_age')
121
+ end
122
+
123
+ def bd_max_age=(list)
124
+ vlans = bd_total_range_with_vlans
125
+ config_set('stp_global', 'bd_max_age',
126
+ state: 'no',
127
+ range: Utils.get_reset_range(@bdr, vlans),
128
+ val: '') if list.empty?
129
+ set_range_based_params(list, 'bd_max_age')
130
+ end
131
+
132
+ def default_bd_max_age
133
+ config_get_default('stp_global', 'bd_max_age')
134
+ end
135
+
136
+ # Getter: Builds an array of bd priority
137
+ # commands currently on the device.
138
+ # cli: spanning-tree bridge-domain 2-42 priority 40960
139
+ # spanning-tree bridge-domain 83-92,1000-2300 priority 53248
140
+ # array: [['2-42', '40960'], ['83-92,1000-2300', '53248']]
141
+ #
142
+ def bd_priority
143
+ config_get('stp_global', 'bd_priority')
144
+ end
145
+
146
+ def bd_priority=(list)
147
+ vlans = bd_total_range_with_vlans
148
+ config_set('stp_global', 'bd_priority',
149
+ state: 'no',
150
+ range: Utils.get_reset_range(@bdr, vlans),
151
+ val: '') if list.empty?
152
+ set_range_based_params(list, 'bd_priority')
153
+ end
154
+
155
+ def default_bd_priority
156
+ config_get_default('stp_global', 'bd_priority')
157
+ end
158
+
159
+ # Getter: Builds an array of bd root priority
160
+ # commands currently on the device.
161
+ # cli: bridge-domain 2-42 root priority 40960
162
+ # bridge-domain 83-92,1000-2300 root priority 53248
163
+ # array: [['2-42', '40960'], ['83-92,1000-2300', '53248']]
164
+ #
165
+ def bd_root_priority
166
+ config_get('stp_global', 'bd_root_priority')
167
+ end
168
+
169
+ def bd_root_priority=(list)
170
+ vlans = bd_total_range_with_vlans
171
+ config_set('stp_global', 'bd_root_priority',
172
+ state: 'no',
173
+ range: Utils.get_reset_range(@bdr, vlans),
174
+ val: '') if list.empty?
175
+ set_range_based_params(list, 'bd_root_priority')
176
+ end
177
+
178
+ def default_bd_root_priority
179
+ config_get_default('stp_global', 'bd_root_priority')
180
+ end
181
+
182
+ def bpdufilter
183
+ config_get('stp_global', 'bpdufilter')
184
+ end
185
+
186
+ def bpdufilter=(state)
187
+ fail TypeError unless state == true || state == false
188
+ no_cmd = (state ? '' : 'no')
189
+ config_set('stp_global', 'bpdufilter', state: no_cmd)
190
+ end
191
+
192
+ def default_bpdufilter
193
+ config_get_default('stp_global', 'bpdufilter')
194
+ end
195
+
196
+ def bpduguard
197
+ config_get('stp_global', 'bpduguard')
198
+ end
199
+
200
+ def bpduguard=(state)
201
+ fail TypeError unless state == true || state == false
202
+ no_cmd = (state ? '' : 'no')
203
+ config_set('stp_global', 'bpduguard', state: no_cmd)
204
+ end
205
+
206
+ def default_bpduguard
207
+ config_get_default('stp_global', 'bpduguard')
208
+ end
209
+
210
+ def bridge_assurance
211
+ config_get('stp_global', 'bridge_assurance')
212
+ end
213
+
214
+ def bridge_assurance=(state)
215
+ fail TypeError unless state == true || state == false
216
+ no_cmd = (state ? '' : 'no')
217
+ config_set('stp_global', 'bridge_assurance', state: no_cmd)
218
+ end
219
+
220
+ def default_bridge_assurance
221
+ config_get_default('stp_global', 'bridge_assurance')
222
+ end
223
+
224
+ def domain
225
+ config_get('stp_global', 'domain')
226
+ end
227
+
228
+ def domain=(val)
229
+ if val
230
+ state = ''
231
+ else
232
+ state = 'no'
233
+ val = '1' # dummy val to satisfy the CLI
234
+ end
235
+ config_set('stp_global',
236
+ 'domain', state: state, domain: val)
237
+ end
238
+
239
+ def default_domain
240
+ config_get_default('stp_global', 'domain')
241
+ end
242
+
243
+ def fcoe
244
+ config_get('stp_global', 'fcoe')
245
+ end
246
+
247
+ def fcoe=(state)
248
+ fail TypeError unless state == true || state == false
249
+ no_cmd = (state ? '' : 'no')
250
+ config_set('stp_global', 'fcoe', state: no_cmd)
251
+ end
252
+
253
+ def default_fcoe
254
+ config_get_default('stp_global', 'fcoe')
255
+ end
256
+
257
+ def loopguard
258
+ config_get('stp_global', 'loopguard')
259
+ end
260
+
261
+ def loopguard=(state)
262
+ fail TypeError unless state == true || state == false
263
+ no_cmd = (state ? '' : 'no')
264
+ config_set('stp_global', 'loopguard', state: no_cmd)
265
+ end
266
+
267
+ def default_loopguard
268
+ config_get_default('stp_global', 'loopguard')
269
+ end
270
+
271
+ def mode
272
+ config_get('stp_global', 'mode')
273
+ end
274
+
275
+ def mode=(val)
276
+ if val == default_mode
277
+ config_set('stp_global', 'mode', state: 'no', mode: '')
278
+ else
279
+ config_set('stp_global', 'mode', state: '', mode: val)
280
+ end
281
+ end
282
+
283
+ def default_mode
284
+ config_get_default('stp_global', 'mode')
285
+ end
286
+
287
+ # Getter: Builds an array of mst designated priority
288
+ # commands currently on the device.
289
+ # cli: spanning-tree mst 2-42 designated priority 40960
290
+ # spanning-tree mst 83-92,1000-2300 designated priority 53248
291
+ # array: [['2-42', '40960'], ['83-92,1000-2300', '53248']]
292
+ #
293
+ def mst_designated_priority
294
+ config_get('stp_global', 'mst_designated_priority')
295
+ end
296
+
297
+ def mst_designated_priority=(list)
298
+ check_stp_mode_mst
299
+ config_set('stp_global', 'mst_designated_priority',
300
+ state: 'no', range: @mr, val: '') if list.empty?
301
+ set_range_based_params(list, 'mst_designated_priority')
302
+ end
303
+
304
+ def default_mst_designated_priority
305
+ config_get_default('stp_global', 'mst_designated_priority')
306
+ end
307
+
308
+ def mst_forward_time
309
+ config_get('stp_global', 'mst_forward_time')
310
+ end
311
+
312
+ def mst_forward_time=(val)
313
+ check_stp_mode_mst
314
+ if val == default_mst_forward_time
315
+ state = 'no'
316
+ val = ''
317
+ else
318
+ state = ''
319
+ end
320
+ config_set('stp_global',
321
+ 'mst_forward_time', state: state, ft: val)
322
+ end
323
+
324
+ def default_mst_forward_time
325
+ config_get_default('stp_global', 'mst_forward_time')
326
+ end
327
+
328
+ def mst_hello_time
329
+ config_get('stp_global', 'mst_hello_time')
330
+ end
331
+
332
+ def mst_hello_time=(val)
333
+ check_stp_mode_mst
334
+ if val == default_mst_hello_time
335
+ state = 'no'
336
+ val = ''
337
+ else
338
+ state = ''
339
+ end
340
+ config_set('stp_global',
341
+ 'mst_hello_time', state: state, ht: val)
342
+ end
343
+
344
+ def default_mst_hello_time
345
+ config_get_default('stp_global', 'mst_hello_time')
346
+ end
347
+
348
+ # Getter: Builds an array of mst instance to vlan range
349
+ # commands currently on the device.
350
+ # cli: instance 2 vlan 6-47
351
+ # instance 3000 vlan 1000-3200
352
+ # array: [['2', '6-47'], ['3000', '1000-3200']]
353
+ #
354
+ def mst_inst_vlan_map
355
+ config_get('stp_global', 'mst_inst_vlan_map')
356
+ end
357
+
358
+ def mst_inst_vlan_map=(list)
359
+ check_stp_mode_mst
360
+ config_set('stp_global', 'mst_inst_vlan_map', state: '',
361
+ instance: '0', vlan: 'vlan', range: @mir) if list.empty?
362
+ list.each do |inst, range|
363
+ # if a particular range is set to default, use 'no' cmd
364
+ if range == 'default'
365
+ config_set('stp_global', 'mst_inst_vlan_map', state: 'no',
366
+ instance: inst, vlan: '', range: '')
367
+ else
368
+ config_set('stp_global', 'mst_inst_vlan_map', state: '',
369
+ instance: inst, vlan: 'vlan', range: range)
370
+ end
371
+ end
372
+ end
373
+
374
+ def default_mst_inst_vlan_map
375
+ config_get_default('stp_global', 'mst_inst_vlan_map')
376
+ end
377
+
378
+ def mst_max_age
379
+ config_get('stp_global', 'mst_max_age')
380
+ end
381
+
382
+ def mst_max_age=(val)
383
+ check_stp_mode_mst
384
+ if val == default_mst_max_age
385
+ state = 'no'
386
+ val = ''
387
+ else
388
+ state = ''
389
+ end
390
+ config_set('stp_global',
391
+ 'mst_max_age', state: state, ma: val)
392
+ end
393
+
394
+ def default_mst_max_age
395
+ config_get_default('stp_global', 'mst_max_age')
396
+ end
397
+
398
+ def mst_max_hops
399
+ config_get('stp_global', 'mst_max_hops')
400
+ end
401
+
402
+ def mst_max_hops=(val)
403
+ check_stp_mode_mst
404
+ if val == default_mst_max_hops
405
+ state = 'no'
406
+ val = ''
407
+ else
408
+ state = ''
409
+ end
410
+ config_set('stp_global',
411
+ 'mst_max_hops', state: state, mh: val)
412
+ end
413
+
414
+ def default_mst_max_hops
415
+ config_get_default('stp_global', 'mst_max_hops')
416
+ end
417
+
418
+ def mst_name
419
+ config_get('stp_global', 'mst_name')
420
+ end
421
+
422
+ def mst_name=(val)
423
+ check_stp_mode_mst
424
+ if val
425
+ state = ''
426
+ else
427
+ state = 'no'
428
+ val = ''
429
+ end
430
+ config_set('stp_global',
431
+ 'mst_name', state: state, name: val)
432
+ end
433
+
434
+ def default_mst_name
435
+ config_get_default('stp_global', 'mst_name')
436
+ end
437
+
438
+ # Getter: Builds an array of mst priority
439
+ # commands currently on the device.
440
+ # cli: spanning-tree mst 2-42 priority 40960
441
+ # spanning-tree mst 83-92,1000-2300 priority 53248
442
+ # array: [['2-42', '40960'], ['83-92,1000-2300', '53248']]
443
+ #
444
+ def mst_priority
445
+ config_get('stp_global', 'mst_priority')
446
+ end
447
+
448
+ def mst_priority=(list)
449
+ check_stp_mode_mst
450
+ config_set('stp_global', 'mst_priority',
451
+ state: 'no', range: @mr, val: '') if list.empty?
452
+ set_range_based_params(list, 'mst_priority')
453
+ end
454
+
455
+ def default_mst_priority
456
+ config_get_default('stp_global', 'mst_priority')
457
+ end
458
+
459
+ def mst_revision
460
+ config_get('stp_global', 'mst_revision')
461
+ end
462
+
463
+ def mst_revision=(val)
464
+ check_stp_mode_mst
465
+ if val.zero?
466
+ state = 'no'
467
+ val = ''
468
+ else
469
+ state = ''
470
+ end
471
+ config_set('stp_global',
472
+ 'mst_revision', state: state, rev: val)
473
+ end
474
+
475
+ def default_mst_revision
476
+ config_get_default('stp_global', 'mst_revision')
477
+ end
478
+
479
+ # Getter: Builds an array of mst root priority
480
+ # commands currently on the device.
481
+ # cli: spanning-tree mst 2-42 root priority 40960
482
+ # spanning-tree mst 83-92,1000-2300 root priority 53248
483
+ # array: [['2-42', '40960'], ['83-92,1000-2300', '53248']]
484
+ #
485
+ def mst_root_priority
486
+ config_get('stp_global', 'mst_root_priority')
487
+ end
488
+
489
+ def mst_root_priority=(list)
490
+ check_stp_mode_mst
491
+ config_set('stp_global', 'mst_root_priority',
492
+ state: 'no', range: @mr, val: '') if list.empty?
493
+ set_range_based_params(list, 'mst_root_priority')
494
+ end
495
+
496
+ def default_mst_root_priority
497
+ config_get_default('stp_global', 'mst_root_priority')
498
+ end
499
+
500
+ def pathcost
501
+ config_get('stp_global', 'pathcost')
502
+ end
503
+
504
+ def pathcost=(val)
505
+ if val == default_pathcost
506
+ config_set('stp_global', 'pathcost', state: 'no', method: '')
507
+ else
508
+ config_set('stp_global', 'pathcost', state: '', method: val)
509
+ end
510
+ end
511
+
512
+ def default_pathcost
513
+ config_get_default('stp_global', 'pathcost')
514
+ end
515
+
516
+ # Getter: Builds an array of vlan designated priority
517
+ # commands currently on the device.
518
+ # cli: vlan 1-42 designated priority 40960
519
+ # vlan 83-92,1000-2300 designated priority 53248
520
+ # array: [['1-42', '40960'], ['83-92,1000-2300', '53248']]
521
+ #
522
+ def vlan_designated_priority
523
+ config_get('stp_global', 'vlan_designated_priority')
524
+ end
525
+
526
+ def vlan_designated_priority=(list)
527
+ config_set('stp_global', 'vlan_designated_priority',
528
+ state: 'no', range: @vr, val: '') if list.empty?
529
+ set_range_based_params(list, 'vlan_designated_priority')
530
+ end
531
+
532
+ def default_vlan_designated_priority
533
+ config_get_default('stp_global', 'vlan_designated_priority')
534
+ end
535
+
536
+ # Getter: Builds an array of vlan forward time
537
+ # commands currently on the device.
538
+ # cli: spanning-tree vlan 1-42 forward-time 19
539
+ # spanning-tree vlan 3000-3700 forward-time 13
540
+ # array: [['1-42', '19'], ['3000-3700', '13']]
541
+ #
542
+ def vlan_forward_time
543
+ config_get('stp_global', 'vlan_forward_time')
544
+ end
545
+
546
+ def vlan_forward_time=(list)
547
+ config_set('stp_global', 'vlan_forward_time',
548
+ state: 'no', range: @vr, val: '') if list.empty?
549
+ set_range_based_params(list, 'vlan_forward_time')
550
+ end
551
+
552
+ def default_vlan_forward_time
553
+ config_get_default('stp_global', 'vlan_forward_time')
554
+ end
555
+
556
+ # Getter: Builds an array of vlan hello time
557
+ # commands currently on the device.
558
+ # cli: spanning-tree vlan 1-42 hello-time 10
559
+ # spanning-tree vlan 3000-3700 hello-time 6
560
+ # array: [['1-42', '10'], ['3000-3700', '6']]
561
+ #
562
+ def vlan_hello_time
563
+ config_get('stp_global', 'vlan_hello_time')
564
+ end
565
+
566
+ def vlan_hello_time=(list)
567
+ config_set('stp_global', 'vlan_hello_time',
568
+ state: '', range: @vr, val: '2') if list.empty?
569
+ list.each do |range, property_value|
570
+ if property_value == 'default'
571
+ config_set('stp_global', 'vlan_hello_time',
572
+ state: '', range: range, val: '2')
573
+ else
574
+ config_set('stp_global', 'vlan_hello_time',
575
+ state: '', range: range, val: property_value)
576
+ end
577
+ end
578
+ end
579
+
580
+ def default_vlan_hello_time
581
+ config_get_default('stp_global', 'vlan_hello_time')
582
+ end
583
+
584
+ # Getter: Builds an array of vlan max-age
585
+ # commands currently on the device.
586
+ # cli: spanning-tree vlan 1-42 max-age 21
587
+ # spanning-tree vlan 3000-3700 max-age 13
588
+ # array: [['1-42', '21'], ['3000-3700', '13']]
589
+ #
590
+ def vlan_max_age
591
+ config_get('stp_global', 'vlan_max_age')
592
+ end
593
+
594
+ def vlan_max_age=(list)
595
+ config_set('stp_global', 'vlan_max_age',
596
+ state: 'no', range: @vr, val: '') if list.empty?
597
+ set_range_based_params(list, 'vlan_max_age')
598
+ end
599
+
600
+ def default_vlan_max_age
601
+ config_get_default('stp_global', 'vlan_max_age')
602
+ end
603
+
604
+ # Getter: Builds an array of vlan priority
605
+ # commands currently on the device.
606
+ # cli: spanning-tree vlan 1-42 priority 40960
607
+ # spanning-tree vlan 83-92,1000-2300 priority 53248
608
+ # array: [['1-42', '40960'], ['83-92,1000-2300', '53248']]
609
+ #
610
+ def vlan_priority
611
+ config_get('stp_global', 'vlan_priority')
612
+ end
613
+
614
+ def vlan_priority=(list)
615
+ config_set('stp_global', 'vlan_priority',
616
+ state: 'no', range: @vr, val: '') if list.empty?
617
+ set_range_based_params(list, 'vlan_priority')
618
+ end
619
+
620
+ def default_vlan_priority
621
+ config_get_default('stp_global', 'vlan_priority')
622
+ end
623
+
624
+ # Getter: Builds an array of vlan root priority
625
+ # commands currently on the device.
626
+ # cli: vlan 1-42 root priority 40960
627
+ # vlan 83-92,1000-2300 root priority 53248
628
+ # array: [['1-42', '40960'], ['83-92,1000-2300', '53248']]
629
+ #
630
+ def vlan_root_priority
631
+ config_get('stp_global', 'vlan_root_priority')
632
+ end
633
+
634
+ def vlan_root_priority=(list)
635
+ config_set('stp_global', 'vlan_root_priority',
636
+ state: 'no', range: @vr, val: '') if list.empty?
637
+ set_range_based_params(list, 'vlan_root_priority')
638
+ end
639
+
640
+ def default_vlan_root_priority
641
+ config_get_default('stp_global', 'vlan_root_priority')
642
+ end
643
+
644
+ def check_stp_mode_mst
645
+ fail "#{caller[0][/`.*'/][1..-2]} cannot be set unless spanning-tree" \
646
+ ' mode is mst' unless mode == 'mst'
647
+ end
648
+
649
+ # bridge-domain and vlans are mutually exclusive
650
+ # so when there are vlans, we need to remove them
651
+ # from the bd range while restting
652
+ def bd_total_range_with_vlans
653
+ hash = Vlan.vlans
654
+ arr = []
655
+ hash.keys.each do |id|
656
+ arr << id.to_i
657
+ end
658
+ Utils.array_to_str(arr)
659
+ ret_arr = []
660
+ ret_arr << Utils.array_to_str(arr)
661
+ end
662
+
663
+ def set_range_based_params(list, param_name)
664
+ list.each do |range, property_value|
665
+ # if a particular range is set to default, use 'no' cmd
666
+ if property_value == 'default'
667
+ config_set('stp_global', param_name,
668
+ state: 'no', range: range, val: '')
669
+ else
670
+ config_set('stp_global', param_name,
671
+ state: '', range: range, val: property_value)
672
+ end
673
+ end
674
+ end
675
+ end # class
676
+ end # module