cisco_node_utils 1.1.0 → 1.2.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 (202) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/CHANGELOG.md +126 -1
  4. data/README.md +19 -12
  5. data/Rakefile +1 -0
  6. data/bin/git/hooks/commit-msg/enforce_style +8 -0
  7. data/cisco_node_utils.gemspec +4 -3
  8. data/docs/README-develop-best-practices.md +127 -109
  9. data/docs/README-develop-node-utils-APIs.md +47 -39
  10. data/docs/template-router.rb +3 -7
  11. data/lib/.rubocop.yml +4 -4
  12. data/lib/cisco_node_utils.rb +1 -1
  13. data/lib/cisco_node_utils/aaa_authentication_login.rb +96 -0
  14. data/lib/cisco_node_utils/aaa_authentication_login_service.rb +133 -0
  15. data/lib/cisco_node_utils/aaa_authorization_service.rb +150 -0
  16. data/lib/cisco_node_utils/ace.rb +196 -0
  17. data/lib/cisco_node_utils/acl.rb +100 -0
  18. data/lib/cisco_node_utils/bgp.rb +301 -163
  19. data/lib/cisco_node_utils/bgp_af.rb +187 -19
  20. data/lib/cisco_node_utils/bgp_neighbor.rb +18 -33
  21. data/lib/cisco_node_utils/bgp_neighbor_af.rb +25 -48
  22. data/lib/cisco_node_utils/cisco_cmn_utils.rb +23 -4
  23. data/lib/cisco_node_utils/cmd_ref/README_YAML.md +593 -0
  24. data/lib/cisco_node_utils/cmd_ref/aaa_auth_login_service.yaml +22 -0
  25. data/lib/cisco_node_utils/cmd_ref/aaa_authentication_login.yaml +31 -0
  26. data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +22 -0
  27. data/lib/cisco_node_utils/cmd_ref/acl.yaml +43 -0
  28. data/lib/cisco_node_utils/cmd_ref/bgp.yaml +242 -0
  29. data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +164 -0
  30. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +131 -0
  31. data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +179 -0
  32. data/lib/cisco_node_utils/cmd_ref/dnsclient.yaml +34 -0
  33. data/lib/cisco_node_utils/cmd_ref/evpn_vni.yaml +42 -0
  34. data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +172 -0
  35. data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +35 -0
  36. data/lib/cisco_node_utils/cmd_ref/feature.yaml +42 -0
  37. data/lib/cisco_node_utils/cmd_ref/fex.yaml +9 -0
  38. data/lib/cisco_node_utils/cmd_ref/images.yaml +7 -0
  39. data/lib/cisco_node_utils/cmd_ref/interface.yaml +339 -0
  40. data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +28 -0
  41. data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +61 -0
  42. data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +54 -0
  43. data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +32 -0
  44. data/lib/cisco_node_utils/cmd_ref/inventory.yaml +45 -0
  45. data/lib/cisco_node_utils/cmd_ref/memory.yaml +13 -0
  46. data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +7 -0
  47. data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +14 -0
  48. data/lib/cisco_node_utils/cmd_ref/ospf.yaml +74 -0
  49. data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +33 -0
  50. data/lib/cisco_node_utils/cmd_ref/pim.yaml +40 -0
  51. data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +69 -0
  52. data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +25 -0
  53. data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +64 -0
  54. data/lib/cisco_node_utils/cmd_ref/radius_server_group.yaml +14 -0
  55. data/lib/cisco_node_utils/cmd_ref/show_system.yaml +5 -0
  56. data/lib/cisco_node_utils/cmd_ref/show_version.yaml +72 -0
  57. data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +23 -0
  58. data/lib/cisco_node_utils/cmd_ref/snmp_group.yaml +7 -0
  59. data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +50 -0
  60. data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +51 -0
  61. data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +55 -0
  62. data/lib/cisco_node_utils/cmd_ref/snmpnotification.yaml +11 -0
  63. data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +18 -0
  64. data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +7 -0
  65. data/lib/cisco_node_utils/cmd_ref/system.yaml +6 -0
  66. data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +49 -0
  67. data/lib/cisco_node_utils/cmd_ref/tacacs_server_group.yaml +33 -0
  68. data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +35 -0
  69. data/lib/cisco_node_utils/cmd_ref/vdc.yaml +38 -0
  70. data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +6 -0
  71. data/lib/cisco_node_utils/cmd_ref/vlan.yaml +56 -0
  72. data/lib/cisco_node_utils/cmd_ref/vni.yaml +76 -0
  73. data/lib/cisco_node_utils/cmd_ref/vpc.yaml +197 -0
  74. data/lib/cisco_node_utils/cmd_ref/vrf.yaml +88 -0
  75. data/lib/cisco_node_utils/cmd_ref/vtp.yaml +38 -0
  76. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +60 -0
  77. data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +39 -0
  78. data/lib/cisco_node_utils/cmd_ref/yum.yaml +13 -0
  79. data/lib/cisco_node_utils/command_reference.rb +359 -187
  80. data/lib/cisco_node_utils/configparser_lib.rb +1 -1
  81. data/lib/cisco_node_utils/dns_domain.rb +19 -5
  82. data/lib/cisco_node_utils/domain_name.rb +4 -8
  83. data/lib/cisco_node_utils/evpn_vni.rb +157 -0
  84. data/lib/cisco_node_utils/fabricpath_global.rb +388 -0
  85. data/lib/cisco_node_utils/fabricpath_topology.rb +150 -0
  86. data/lib/cisco_node_utils/feature.rb +111 -0
  87. data/lib/cisco_node_utils/interface.rb +390 -97
  88. data/lib/cisco_node_utils/interface_channel_group.rb +124 -0
  89. data/lib/cisco_node_utils/interface_ospf.rb +11 -34
  90. data/lib/cisco_node_utils/interface_portchannel.rb +157 -0
  91. data/lib/cisco_node_utils/interface_service_vni.rb +132 -0
  92. data/lib/cisco_node_utils/name_server.rb +1 -1
  93. data/lib/cisco_node_utils/node.rb +55 -249
  94. data/lib/cisco_node_utils/node_util.rb +5 -1
  95. data/lib/cisco_node_utils/ntp_config.rb +2 -2
  96. data/lib/cisco_node_utils/ntp_server.rb +14 -5
  97. data/lib/cisco_node_utils/overlay_global.rb +153 -0
  98. data/lib/cisco_node_utils/pim.rb +124 -0
  99. data/lib/cisco_node_utils/pim_group_list.rb +108 -0
  100. data/lib/cisco_node_utils/pim_rp_address.rb +102 -0
  101. data/lib/cisco_node_utils/platform.rb +8 -9
  102. data/lib/cisco_node_utils/portchannel_global.rb +277 -0
  103. data/lib/cisco_node_utils/radius_global.rb +9 -19
  104. data/lib/cisco_node_utils/radius_server.rb +31 -41
  105. data/lib/cisco_node_utils/radius_server_group.rb +117 -0
  106. data/lib/cisco_node_utils/router_ospf.rb +1 -1
  107. data/lib/cisco_node_utils/router_ospf_vrf.rb +14 -19
  108. data/lib/cisco_node_utils/snmp_notification_receiver.rb +158 -0
  109. data/lib/cisco_node_utils/snmpcommunity.rb +3 -5
  110. data/lib/cisco_node_utils/snmpgroup.rb +1 -1
  111. data/lib/cisco_node_utils/snmpnotification.rb +57 -0
  112. data/lib/cisco_node_utils/snmpserver.rb +8 -17
  113. data/lib/cisco_node_utils/snmpuser.rb +67 -28
  114. data/lib/cisco_node_utils/syslog_server.rb +3 -9
  115. data/lib/cisco_node_utils/syslog_settings.rb +2 -10
  116. data/lib/cisco_node_utils/tacacs_server.rb +9 -14
  117. data/lib/cisco_node_utils/tacacs_server_group.rb +145 -0
  118. data/lib/cisco_node_utils/tacacs_server_host.rb +5 -9
  119. data/lib/cisco_node_utils/vdc.rb +88 -0
  120. data/lib/cisco_node_utils/version.rb +5 -2
  121. data/lib/cisco_node_utils/vlan.rb +71 -8
  122. data/lib/cisco_node_utils/vni.rb +227 -0
  123. data/lib/cisco_node_utils/vpc.rb +377 -0
  124. data/lib/cisco_node_utils/vrf.rb +60 -9
  125. data/lib/cisco_node_utils/vrf_af.rb +191 -0
  126. data/lib/cisco_node_utils/vtp.rb +8 -6
  127. data/lib/cisco_node_utils/vxlan_vtep.rb +151 -0
  128. data/lib/cisco_node_utils/vxlan_vtep_vni.rb +234 -0
  129. data/lib/cisco_node_utils/yum.rb +1 -1
  130. data/tests/.rubocop.yml +1 -1
  131. data/tests/basetest.rb +16 -7
  132. data/tests/ciscotest.rb +55 -13
  133. data/tests/cmd_config.yaml +2 -2
  134. data/tests/platform_info.rb +3 -2
  135. data/tests/test_aaa_authentication_login.rb +219 -0
  136. data/tests/test_aaa_authentication_login_service.rb +759 -0
  137. data/tests/test_aaa_authorization_service.rb +1041 -0
  138. data/tests/test_ace.rb +160 -0
  139. data/tests/test_acl.rb +176 -0
  140. data/tests/test_bgp_af.rb +269 -13
  141. data/tests/test_bgp_neighbor.rb +38 -40
  142. data/tests/test_bgp_neighbor_af.rb +92 -32
  143. data/tests/test_command_config.rb +5 -5
  144. data/tests/test_command_reference.rb +284 -101
  145. data/tests/test_dns_domain.rb +1 -1
  146. data/tests/test_domain_name.rb +1 -1
  147. data/tests/test_evpn_vni.rb +106 -0
  148. data/tests/test_fabricpath_global.rb +243 -0
  149. data/tests/test_fabricpath_topology.rb +98 -0
  150. data/tests/test_interface.rb +292 -74
  151. data/tests/test_interface_channel_group.rb +74 -0
  152. data/tests/test_interface_ospf.rb +9 -4
  153. data/tests/test_interface_portchannel.rb +105 -0
  154. data/tests/test_interface_service_vni.rb +232 -0
  155. data/tests/test_interface_svi.rb +77 -62
  156. data/tests/test_interface_switchport.rb +17 -5
  157. data/tests/test_name_server.rb +1 -1
  158. data/tests/test_node.rb +1 -1
  159. data/tests/test_node_ext.rb +10 -20
  160. data/tests/test_ntp_config.rb +1 -1
  161. data/tests/test_ntp_server.rb +18 -6
  162. data/tests/test_overlay_global.rb +102 -0
  163. data/tests/test_pim.rb +177 -0
  164. data/tests/test_pim_group_list.rb +181 -0
  165. data/tests/test_pim_rp_address.rb +153 -0
  166. data/tests/test_platform.rb +3 -3
  167. data/tests/test_portchannel_global.rb +202 -0
  168. data/tests/test_radius_global.rb +1 -1
  169. data/tests/test_radius_server.rb +92 -57
  170. data/tests/test_radius_server_group.rb +149 -0
  171. data/tests/test_router_bgp.rb +283 -112
  172. data/tests/test_router_ospf.rb +2 -2
  173. data/tests/test_router_ospf_vrf.rb +4 -4
  174. data/tests/test_snmp_notification_receiver.rb +167 -0
  175. data/tests/test_snmpcommunity.rb +1 -1
  176. data/tests/test_snmpgroup.rb +1 -1
  177. data/tests/test_snmpnotification.rb +72 -0
  178. data/tests/test_snmpserver.rb +29 -105
  179. data/tests/test_snmpuser.rb +32 -30
  180. data/tests/test_syslog_server.rb +36 -10
  181. data/tests/test_syslog_settings.rb +1 -1
  182. data/tests/test_tacacs_server.rb +1 -1
  183. data/tests/test_tacacs_server_group.rb +405 -0
  184. data/tests/test_tacacs_server_host.rb +1 -1
  185. data/tests/test_vdc.rb +78 -0
  186. data/tests/test_vlan.rb +74 -19
  187. data/tests/test_vlan_mt_full.rb +95 -0
  188. data/tests/test_vni.rb +106 -0
  189. data/tests/test_vpc.rb +361 -0
  190. data/tests/test_vrf.rb +172 -29
  191. data/tests/test_vtp.rb +1 -1
  192. data/tests/test_vxlan_vtep.rb +214 -0
  193. data/tests/test_vxlan_vtep_vni.rb +201 -0
  194. data/tests/test_yum.rb +1 -1
  195. metadata +120 -11
  196. data/lib/cisco_node_utils/README_YAML.md +0 -325
  197. data/lib/cisco_node_utils/command_reference_common.yaml +0 -1051
  198. data/lib/cisco_node_utils/command_reference_common_bgp.yaml +0 -535
  199. data/lib/cisco_node_utils/command_reference_n3064.yaml +0 -13
  200. data/lib/cisco_node_utils/command_reference_n7k.yaml +0 -52
  201. data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -26
  202. data/tests/platform_info.yaml +0 -10
@@ -102,20 +102,23 @@ Example:
102
102
 
103
103
  ### <a name="comp_yaml">Step 1. YAML Definitions: router eigrp</a>
104
104
 
105
- The new API for `router eigrp` will need some basic YAML definitions.
105
+ The new API for `router eigrp` will need some basic YAML definitions. By convention we create a new YAML file to handle a new feature set, so we will create
106
+ the following file:
106
107
 
107
- `command_reference_common.yaml` is used for settings that are common across all platforms while other files are used for settings that are unique to a given platform. Our `router eigrp` example uses the same cli syntax on all platforms, thus we only need to edit the common file:
108
+ `lib/cisco_node_utils/cmd_ref/eigrp.yaml`
108
109
 
109
- `lib/cisco_node_utils/command_reference_common.yaml`
110
+ YAML files in the `/cmd_ref/` subdirectory are automatically discovered at runtime, so we don't need to do anything special once we have created this file
110
111
 
111
- Four basic command_reference parameters will be defined for each resource property:
112
+ The following basic command_reference parameters will be defined for each resource property:
112
113
 
113
114
  1. `config_get:` This defines the NX-OS CLI command (usually a 'show...' command) used to retrieve the property's current configuration state. Note that some commands may not be present until a feature is enabled.
114
115
  2. `config_get_token:` A regexp pattern for extracting state values from the config_get output.
115
116
  3. `config_set:` The NX-OS CLI configuration command(s) used to set the property configuration. May contain wildcards for variable parameters.
116
117
  4. `default_value:` This is typically the "factory" default state of the property, expressed as an actual value (true, 12, "off", etc)
118
+ 5. `kind:` The data type of this property. If omitted, the property will be a string by default. Commonly used values for this property are `int` and `boolean`.
119
+ 6. `multiple:` By default a property is assumed to be found once or not at all by the `config_get`/`config_get_token` lookup, and an error will be raised if multiple matches are found. If multiple matches are valid and expected, you must set `multiple: true` for this property.
117
120
 
118
- There are additional YAML command parameters available which are not covered by this document. Please see the [README_YAML.md](../lib/cisco_node_utils/README_YAML.md) document for more information on the structure and semantics of these files.
121
+ There are additional YAML command parameters available which are not covered by this document. Please see the [README_YAML.md](../lib/cisco_node_utils/cmd_ref/README_YAML.md) document for more information on the structure and semantics of these files.
119
122
  The properties in this example require additional context for their config_get_token values because they need to differentiate between different eigrp instances. Most properties will also have a default value.
120
123
 
121
124
  *Note: Eigrp also has vrf and address-family contexts. These contexts require additional coding and are beyond the scope of this document.*
@@ -124,33 +127,40 @@ The properties in this example require additional context for their config_get_t
124
127
 
125
128
  *Note: The basic token definitions for multi-level commands can become long and complicated. A better solution for these commands is to use a command_reference _template: definition to simplify the configuration. The example below will use the basic syntax; see the ospf definitions in the YAML file for an example of _template: usage.*
126
129
 
130
+ *Note: Property definitions in the YAML must be given in alphabetical order. Parameters under a property can be given in any order.*
131
+
127
132
  ```yaml
128
- eigrp:
129
- feature:
130
- # feature eigrp must be enabled before configuring router eigrp
131
- config_get: 'show running eigrp all'
132
- config_get_token: '/^feature eigrp$/'
133
- config_set: '<state> feature eigrp'
134
-
135
- router:
136
- # There can be multiple eigrp instances
137
- config_get: 'show running eigrp all' # all eigrp-related configs
138
- config_get_token: '/^router eigrp (\S+)$/' # Match instance name
139
- config_set: '<state> router eigrp <name>' # config to add or remove
140
-
141
- maximum_paths:
142
- # This is an integer property
143
- config_get: 'show running eigrp all'
144
- config_get_token: ['/^router eigrp <name>$/', '/^maximum-paths (\d+)/']
145
- config_set: ['router eigrp <name>', 'maximum-paths <val>']
146
- default_value: 8
147
-
148
- shutdown:
149
- # This is a boolean property
150
- config_get: 'show running eigrp all'
151
- config_get_token: ['/^router eigrp <name>$/', '/^shutdown$/']
152
- config_set: ['router eigrp <name>', '<state> shutdown']
153
- default_value: false
133
+ # eigrp.yaml
134
+ ---
135
+ feature:
136
+ # feature eigrp must be enabled before configuring router eigrp
137
+ kind: boolean
138
+ config_get: 'show running eigrp all'
139
+ config_get_token: '/^feature eigrp$/'
140
+ config_set: '<state> feature eigrp'
141
+
142
+ maximum_paths:
143
+ # This is an integer property
144
+ kind: int
145
+ config_get: 'show running eigrp all'
146
+ config_get_token: ['/^router eigrp <name>$/', '/^maximum-paths (\d+)/']
147
+ config_set: ['router eigrp <name>', 'maximum-paths <val>']
148
+ default_value: 8
149
+
150
+ router:
151
+ # There can be multiple eigrp instances
152
+ multiple: true
153
+ config_get: 'show running eigrp all' # all eigrp-related configs
154
+ config_get_token: '/^router eigrp (\S+)$/' # Match instance name
155
+ config_set: '<state> router eigrp <name>' # config to add or remove
156
+
157
+ shutdown:
158
+ # This is a boolean property
159
+ kind: boolean
160
+ config_get: 'show running eigrp all'
161
+ config_get_token: ['/^router eigrp <name>$/', '/^shutdown$/']
162
+ config_set: ['router eigrp <name>', '<state> shutdown']
163
+ default_value: false
154
164
  ```
155
165
 
156
166
  ### <a name="comp_api">Step 2. cisco_node_utils API: router eigrp</a>
@@ -224,8 +234,7 @@ module Cisco
224
234
  end
225
235
 
226
236
  def feature_enabled
227
- feat = config_get('eigrp', 'feature')
228
- return !(feat.nil? || feat.empty?)
237
+ config_get('eigrp', 'feature')
229
238
  rescue Cisco::CliError => e
230
239
  # This cmd will syntax reject if feature is not
231
240
  # enabled. Just catch the reject and return false.
@@ -275,8 +284,7 @@ module Cisco
275
284
  end
276
285
 
277
286
  def shutdown
278
- state = config_get('eigrp', 'shutdown', name: @name)
279
- state ? true : false
287
+ config_get('eigrp', 'shutdown', name: @name)
280
288
  end
281
289
 
282
290
  def shutdown=(state)
@@ -290,8 +298,7 @@ module Cisco
290
298
  end
291
299
 
292
300
  def maximum_paths
293
- val = config_get('eigrp', 'maximum_paths', name: @name)
294
- val.nil? ? default_maximum_paths : val.first.to_i
301
+ config_get('eigrp', 'maximum_paths', name: @name)
295
302
  end
296
303
 
297
304
  def maximum_paths=(val)
@@ -477,10 +484,11 @@ Inspecting 2 file
477
484
 
478
485
  The final step is to build and install the gem that contains the new APIs.
479
486
 
480
- Please note: `gem build` will only include files that are part of the repository. This means that new file `router_eigrp.rb` will be ignored by the build until it is added to the repo with `git add`:
487
+ Please note: `gem build` will only include files that are part of the repository. This means that new files `router_eigrp.rb` and `eigrp.yaml` will be ignored by the build until they are added to the repo with `git add`:
481
488
 
482
489
  ```bash
483
- git add lib/cisco_node_utils/router_eigrp.rb
490
+ git add lib/cisco_node_utils/router_eigrp.rb \
491
+ lib/cisco_node_utils/cmd_ref/eigrp.yaml
484
492
  ```
485
493
 
486
494
  From the root of the cisco-network-node-utils repository issue the following command.
@@ -43,8 +43,7 @@ module Cisco
43
43
  end
44
44
 
45
45
  def feature_enabled
46
- feat = config_get('X__RESOURCE_NAME__X', 'feature')
47
- return !(feat.nil? || feat.empty?)
46
+ config_get('X__RESOURCE_NAME__X', 'feature')
48
47
  rescue Cisco::CliError => e
49
48
  # This cmd will syntax reject if feature is not
50
49
  # enabled. Just catch the reject and return false.
@@ -94,9 +93,7 @@ module Cisco
94
93
  end
95
94
 
96
95
  def X__PROPERTY_BOOL__X
97
- state = config_get('X__RESOURCE_NAME__X', 'X__PROPERTY_BOOL__X',
98
- name: @name)
99
- state ? true : false
96
+ config_get('X__RESOURCE_NAME__X', 'X__PROPERTY_BOOL__X', name: @name)
100
97
  end
101
98
 
102
99
  def X__PROPERTY_BOOL__X=(state)
@@ -111,8 +108,7 @@ module Cisco
111
108
  end
112
109
 
113
110
  def X__PROPERTY_INT__X
114
- val = config_get('X__RESOURCE_NAME__X', 'X__PROPERTY_INT__X', name: @name)
115
- val.nil? ? default_X__PROPERTY_INT__X : val.first.to_i
111
+ config_get('X__RESOURCE_NAME__X', 'X__PROPERTY_INT__X', name: @name)
116
112
  end
117
113
 
118
114
  def X__PROPERTY_INT__X=(val)
data/lib/.rubocop.yml CHANGED
@@ -3,16 +3,16 @@ inherit_from: ../.rubocop.yml
3
3
  # Baseline code complexity metrics for the lib/ subdirectory:
4
4
 
5
5
  Metrics/AbcSize:
6
- Max: 47
6
+ Max: 45
7
7
 
8
8
  Metrics/CyclomaticComplexity:
9
- Max: 17
9
+ Max: 23
10
10
 
11
11
  Metrics/MethodLength:
12
- Max: 39
12
+ Max: 48
13
13
 
14
14
  Metrics/ParameterLists:
15
15
  Max: 9
16
16
 
17
17
  Metrics/PerceivedComplexity:
18
- Max: 19
18
+ Max: 24
@@ -1,4 +1,4 @@
1
- # Copyright (c) 2014-2015 Cisco and/or its affiliates.
1
+ # Copyright (c) 2014-2016 Cisco and/or its affiliates.
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -0,0 +1,96 @@
1
+ #
2
+ # NXAPI implementation of AaaAuthenticationLogin class
3
+ #
4
+ # April 2015, Alex Hunsberger
5
+ #
6
+ # Copyright (c) 2015-2016 Cisco and/or its affiliates.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ require_relative 'node_util'
22
+
23
+ module Cisco
24
+ # NXAPI implementation of AAA Authentication Login class
25
+ class AaaAuthenticationLogin < NodeUtil
26
+ # rubocop:disable DoubleNegation
27
+ # There is no "feature aaa" or "aaa new-model" on nxos, and only one
28
+ # instance which is always available
29
+ def self.ascii_authentication
30
+ !!config_get('aaa_authentication_login', 'ascii_authentication')
31
+ end
32
+
33
+ def self.ascii_authentication=(val)
34
+ no_cmd = val ? '' : 'no'
35
+ config_set('aaa_authentication_login',
36
+ 'ascii_authentication', no_cmd)
37
+ end
38
+
39
+ def self.default_ascii_authentication
40
+ config_get_default('aaa_authentication_login',
41
+ 'ascii_authentication')
42
+ end
43
+
44
+ def self.chap
45
+ !!config_get('aaa_authentication_login', 'chap')
46
+ end
47
+
48
+ def self.chap=(val)
49
+ no_cmd = val ? '' : 'no'
50
+ config_set('aaa_authentication_login', 'chap', no_cmd)
51
+ end
52
+
53
+ def self.default_chap
54
+ config_get_default('aaa_authentication_login', 'chap')
55
+ end
56
+
57
+ def self.error_display
58
+ !!config_get('aaa_authentication_login', 'error_display')
59
+ end
60
+
61
+ def self.error_display=(val)
62
+ no_cmd = val ? '' : 'no'
63
+ config_set('aaa_authentication_login', 'error_display', no_cmd)
64
+ end
65
+
66
+ def self.default_error_display
67
+ config_get_default('aaa_authentication_login', 'error_display')
68
+ end
69
+
70
+ def self.mschap
71
+ !!config_get('aaa_authentication_login', 'mschap')
72
+ end
73
+
74
+ def self.mschap=(val)
75
+ no_cmd = val ? '' : 'no'
76
+ config_set('aaa_authentication_login', 'mschap', no_cmd)
77
+ end
78
+
79
+ def self.default_mschap
80
+ config_get_default('aaa_authentication_login', 'mschap')
81
+ end
82
+
83
+ def self.mschapv2
84
+ !!config_get('aaa_authentication_login', 'mschapv2')
85
+ end
86
+
87
+ def self.mschapv2=(val)
88
+ no_cmd = val ? '' : 'no'
89
+ config_set('aaa_authentication_login', 'mschapv2', no_cmd)
90
+ end
91
+
92
+ def self.default_mschapv2
93
+ config_get_default('aaa_authentication_login', 'mschapv2')
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,133 @@
1
+ #
2
+ # NXAPI implementation of AaaAuthenticationLoginService class
3
+ #
4
+ # May 2015, Alex Hunsberger
5
+ #
6
+ # Copyright (c) 2015-2016 Cisco and/or its affiliates.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+
20
+ require_relative 'node_util'
21
+
22
+ module Cisco
23
+ # NXAPI implementation of AAA Authentication Login Service class
24
+ class AaaAuthenticationLoginService < NodeUtil
25
+ attr_reader :name
26
+
27
+ def initialize(name, create=true)
28
+ fail TypeError unless name.is_a? String
29
+ # only console and default are supported currently
30
+ fail ArgumentError unless %w(console default).include? name
31
+ @name = name
32
+
33
+ # console needs to be explicitly created before it appears in
34
+ # "show run aaa all" but oddly not before it shows up in
35
+ # "show aaa authentication"
36
+ return unless create
37
+ m = default_method.to_s
38
+ config_set('aaa_auth_login_service', 'method', '', name, m)
39
+ end
40
+
41
+ def self.services
42
+ servs = {}
43
+ servs_arr = config_get('aaa_auth_login_service', 'services')
44
+ unless servs_arr.nil?
45
+ servs_arr.each do |s|
46
+ servs[s] = AaaAuthenticationLoginService.new(s, false)
47
+ end
48
+ end
49
+ servs
50
+ end
51
+
52
+ def destroy
53
+ # must specify exact current config string to unconfigure
54
+ m = method
55
+ m_str = m == :unselected ? '' : m.to_s
56
+ g_str = groups.join(' ')
57
+
58
+ if g_str.empty?
59
+ # cannot remove default local, so do nothing in this case
60
+ unless m == :local && @name == 'default'
61
+ config_set('aaa_auth_login_service', 'method',
62
+ 'no', @name, m_str)
63
+ end
64
+ else
65
+ config_set('aaa_auth_login_service', 'groups',
66
+ 'no', @name, g_str, m_str)
67
+ end
68
+ end
69
+
70
+ # groups aren't retrieved via the usual CLI regex memory method because
71
+ # there can be an arbitrary number of groups and specifying a repeating
72
+ # memory regex only captures the last match
73
+ # ex: aaa authentication login default group group1 group2 group3 none
74
+ def groups
75
+ # config_get returns the following format:
76
+ # [{service:"default",method:"group group1 none "},
77
+ # {service:"console",method:"local "}]
78
+ hsh_arr = config_get('aaa_auth_login_service', 'groups')
79
+ fail 'unable to retrieve aaa groups information' if hsh_arr.empty?
80
+ hsh = hsh_arr.find { |x| x['service'] == @name }
81
+ # this should never happen unless @name is invalid
82
+ fail "no aaa info found for service #{@name}" if hsh.nil?
83
+ fail "no method found for #{@name} - api or feature change?" unless
84
+ hsh.key? 'method'
85
+ # ex: ["group", "group1", "local"] or maybe ["none"]
86
+ grps = hsh['method'].strip.split
87
+ return [] if grps.size == 1
88
+ # remove local, none, group keywords
89
+ grps -= %w(none local group)
90
+ grps
91
+ end
92
+
93
+ # default is []
94
+ def default_groups
95
+ config_get_default('aaa_auth_login_service', 'groups')
96
+ end
97
+
98
+ def method
99
+ m = config_get('aaa_auth_login_service', 'method', @name)
100
+ m.nil? ? :unselected : m.to_sym
101
+ end
102
+
103
+ # default is :local
104
+ def default_method
105
+ config_get_default('aaa_auth_login_service', 'method')
106
+ end
107
+
108
+ # groups and method must be set in the same CLI string
109
+ # aaa authentication login { console | default } /
110
+ # none | local | group <group1 [group2, ...]> [none]
111
+ def groups_method_set(grps, m)
112
+ fail TypeError unless grps.is_a? Array
113
+ fail TypeError unless grps.all? { |x| x.is_a? String }
114
+ fail TypeError unless m.is_a? Symbol
115
+ # only the following 3 are supported (unselected = blank)
116
+ fail ArgumentError unless [:none, :local, :unselected].include? m
117
+
118
+ fail "method 'local' not allowed when groups are configured" if
119
+ m == :local && !grps.empty?
120
+ m_str = m == :unselected ? '' : m.to_s
121
+ g_str = grps.join(' ')
122
+
123
+ # config_set depends on whether we're setting groups or not
124
+ if g_str.empty?
125
+ config_set('aaa_auth_login_service', 'method',
126
+ '', @name, m_str)
127
+ else
128
+ config_set('aaa_auth_login_service', 'groups',
129
+ '', @name, g_str, m_str)
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,150 @@
1
+ # NXAPI implementation of AaaAuthorizationService class
2
+ #
3
+ # May 2015, Alex Hunsberger
4
+ #
5
+ # Copyright (c) 2015-2016 Cisco and/or its affiliates.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+
19
+ require_relative 'node_util'
20
+
21
+ module Cisco
22
+ # AaaAuthorizationService - node util class for aaa authorization management
23
+ class AaaAuthorizationService < NodeUtil
24
+ attr_reader :name, :type
25
+
26
+ def initialize(type, name, create=true)
27
+ fail TypeError unless name.is_a? String
28
+ fail TypeError unless type.is_a? Symbol
29
+ # only console and default are supported currently
30
+ fail ArgumentError unless %w(console default).include? name
31
+ fail ArgumentError unless
32
+ %i(commands config_commands ssh_certificate ssh_publickey).include? type
33
+ @name = name
34
+ @type = type
35
+ type_str = AaaAuthorizationService.auth_type_sym_to_str(type)
36
+
37
+ return unless create
38
+
39
+ config_set('aaa_authorization_service', 'method', '', type_str, name)
40
+ end
41
+
42
+ def self.services
43
+ servs = {}
44
+ servs_arr = config_get('aaa_authorization_service', 'services')
45
+ unless servs_arr.nil?
46
+ servs_arr.each do |type, name|
47
+ type = auth_type_str_to_sym(type)
48
+ servs[type] ||= {}
49
+ servs[type][name] = AaaAuthorizationService.new(type, name, false)
50
+ end
51
+ end
52
+ servs
53
+ end
54
+
55
+ def destroy
56
+ # must specify exact current config string to unconfigure
57
+ m = method
58
+ m_str = m == :unselected ? '' : m.to_s
59
+ g_str = groups.join(' ')
60
+ t_str = AaaAuthorizationService.auth_type_sym_to_str(@type)
61
+
62
+ if g_str.empty?
63
+ # cannot remove no groups + local, so do nothing in this case
64
+ unless m == :local
65
+ config_set('aaa_authorization_service', 'method',
66
+ 'no', t_str, @name)
67
+ end
68
+ else
69
+ config_set('aaa_authorization_service', 'groups',
70
+ 'no', t_str, @name, g_str, m_str)
71
+ end
72
+ end
73
+
74
+ # groups aren't retrieved via the usual CLI regex memory type because
75
+ # there can be an arbitrary number of groups and specifying a repeating
76
+ # memory regex only captures the last match
77
+ # ex: aaa authorization console group group1 group2 group3 local
78
+ def groups
79
+ # config_get returns the following format:
80
+ # [{"appl_subtype": "console",
81
+ # "cmd_type": "config-commands",
82
+ # "methods": "group foo bar local "}], ...
83
+ hsh_arr = config_get('aaa_authorization_service', 'groups')
84
+ fail 'unable to retrieve aaa groups information' if hsh_arr.empty?
85
+ type_s = AaaAuthorizationService.auth_type_sym_to_str(@type)
86
+ hsh = hsh_arr.find do |x|
87
+ x['appl_subtype'] == @name && x['cmd_type'] == type_s
88
+ end
89
+ fail "no aaa info for #{@type},#{@name}" if hsh.nil?
90
+ fail "no aaa info for #{@type},#{@name}. api/feature change?" unless
91
+ hsh.key? 'methods'
92
+ # ex: ["group", "group1", "local"]
93
+ grps = hsh['methods'].strip.split
94
+ # return [] if grps.size == 1
95
+ # remove local, group keywords
96
+ grps -= %w(local group)
97
+ grps
98
+ end
99
+
100
+ # default is []
101
+ def default_groups
102
+ config_get_default('aaa_authorization_service', 'groups')
103
+ end
104
+
105
+ def method
106
+ t_str = AaaAuthorizationService.auth_type_sym_to_str(@type)
107
+ m = config_get('aaa_authorization_service', 'method', @name, t_str)
108
+ m.nil? ? :unselected : m.to_sym
109
+ end
110
+
111
+ # default is :local
112
+ def default_method
113
+ config_get_default('aaa_authorization_service', 'method')
114
+ end
115
+
116
+ # groups and method must be set in the same CLI string
117
+ # aaa authorization login <type> <name> /
118
+ # local | group <group1 [group2, ...]> [local]
119
+ def groups_method_set(grps, m)
120
+ fail TypeError unless grps.is_a? Array
121
+ fail TypeError unless grps.all? { |x| x.is_a? String }
122
+ fail TypeError unless m.is_a? Symbol
123
+ # only the following are supported (unselected = blank)
124
+ fail ArgumentError unless [:local, :unselected].include? m
125
+
126
+ # raise "type 'local' not allowed when groups are configured" if
127
+ # m == :local and not grps.empty?
128
+ m_str = m == :unselected ? '' : m.to_s
129
+ g_str = grps.join(' ')
130
+ t_str = AaaAuthorizationService.auth_type_sym_to_str(@type)
131
+
132
+ # config_set depends on whether we're setting groups or not
133
+ if g_str.empty?
134
+ config_set('aaa_authorization_service', 'method',
135
+ '', t_str, @name)
136
+ else
137
+ config_set('aaa_authorization_service', 'groups',
138
+ '', t_str, @name, g_str, m_str)
139
+ end
140
+ end
141
+
142
+ def self.auth_type_sym_to_str(sym)
143
+ sym.to_s.sub('_', '-')
144
+ end
145
+
146
+ def self.auth_type_str_to_sym(str)
147
+ str.sub('-', '_').to_sym
148
+ end
149
+ end
150
+ end