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.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/CHANGELOG.md +126 -1
- data/README.md +19 -12
- data/Rakefile +1 -0
- data/bin/git/hooks/commit-msg/enforce_style +8 -0
- data/cisco_node_utils.gemspec +4 -3
- data/docs/README-develop-best-practices.md +127 -109
- data/docs/README-develop-node-utils-APIs.md +47 -39
- data/docs/template-router.rb +3 -7
- data/lib/.rubocop.yml +4 -4
- data/lib/cisco_node_utils.rb +1 -1
- data/lib/cisco_node_utils/aaa_authentication_login.rb +96 -0
- data/lib/cisco_node_utils/aaa_authentication_login_service.rb +133 -0
- data/lib/cisco_node_utils/aaa_authorization_service.rb +150 -0
- data/lib/cisco_node_utils/ace.rb +196 -0
- data/lib/cisco_node_utils/acl.rb +100 -0
- data/lib/cisco_node_utils/bgp.rb +301 -163
- data/lib/cisco_node_utils/bgp_af.rb +187 -19
- data/lib/cisco_node_utils/bgp_neighbor.rb +18 -33
- data/lib/cisco_node_utils/bgp_neighbor_af.rb +25 -48
- data/lib/cisco_node_utils/cisco_cmn_utils.rb +23 -4
- data/lib/cisco_node_utils/cmd_ref/README_YAML.md +593 -0
- data/lib/cisco_node_utils/cmd_ref/aaa_auth_login_service.yaml +22 -0
- data/lib/cisco_node_utils/cmd_ref/aaa_authentication_login.yaml +31 -0
- data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +22 -0
- data/lib/cisco_node_utils/cmd_ref/acl.yaml +43 -0
- data/lib/cisco_node_utils/cmd_ref/bgp.yaml +242 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +164 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +131 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +179 -0
- data/lib/cisco_node_utils/cmd_ref/dnsclient.yaml +34 -0
- data/lib/cisco_node_utils/cmd_ref/evpn_vni.yaml +42 -0
- data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +172 -0
- data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +35 -0
- data/lib/cisco_node_utils/cmd_ref/feature.yaml +42 -0
- data/lib/cisco_node_utils/cmd_ref/fex.yaml +9 -0
- data/lib/cisco_node_utils/cmd_ref/images.yaml +7 -0
- data/lib/cisco_node_utils/cmd_ref/interface.yaml +339 -0
- data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +28 -0
- data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +61 -0
- data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +54 -0
- data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +32 -0
- data/lib/cisco_node_utils/cmd_ref/inventory.yaml +45 -0
- data/lib/cisco_node_utils/cmd_ref/memory.yaml +13 -0
- data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +7 -0
- data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +14 -0
- data/lib/cisco_node_utils/cmd_ref/ospf.yaml +74 -0
- data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +33 -0
- data/lib/cisco_node_utils/cmd_ref/pim.yaml +40 -0
- data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +69 -0
- data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +25 -0
- data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +64 -0
- data/lib/cisco_node_utils/cmd_ref/radius_server_group.yaml +14 -0
- data/lib/cisco_node_utils/cmd_ref/show_system.yaml +5 -0
- data/lib/cisco_node_utils/cmd_ref/show_version.yaml +72 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +23 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_group.yaml +7 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +50 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +51 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +55 -0
- data/lib/cisco_node_utils/cmd_ref/snmpnotification.yaml +11 -0
- data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +18 -0
- data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +7 -0
- data/lib/cisco_node_utils/cmd_ref/system.yaml +6 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +49 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_server_group.yaml +33 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +35 -0
- data/lib/cisco_node_utils/cmd_ref/vdc.yaml +38 -0
- data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +6 -0
- data/lib/cisco_node_utils/cmd_ref/vlan.yaml +56 -0
- data/lib/cisco_node_utils/cmd_ref/vni.yaml +76 -0
- data/lib/cisco_node_utils/cmd_ref/vpc.yaml +197 -0
- data/lib/cisco_node_utils/cmd_ref/vrf.yaml +88 -0
- data/lib/cisco_node_utils/cmd_ref/vtp.yaml +38 -0
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +60 -0
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +39 -0
- data/lib/cisco_node_utils/cmd_ref/yum.yaml +13 -0
- data/lib/cisco_node_utils/command_reference.rb +359 -187
- data/lib/cisco_node_utils/configparser_lib.rb +1 -1
- data/lib/cisco_node_utils/dns_domain.rb +19 -5
- data/lib/cisco_node_utils/domain_name.rb +4 -8
- data/lib/cisco_node_utils/evpn_vni.rb +157 -0
- data/lib/cisco_node_utils/fabricpath_global.rb +388 -0
- data/lib/cisco_node_utils/fabricpath_topology.rb +150 -0
- data/lib/cisco_node_utils/feature.rb +111 -0
- data/lib/cisco_node_utils/interface.rb +390 -97
- data/lib/cisco_node_utils/interface_channel_group.rb +124 -0
- data/lib/cisco_node_utils/interface_ospf.rb +11 -34
- data/lib/cisco_node_utils/interface_portchannel.rb +157 -0
- data/lib/cisco_node_utils/interface_service_vni.rb +132 -0
- data/lib/cisco_node_utils/name_server.rb +1 -1
- data/lib/cisco_node_utils/node.rb +55 -249
- data/lib/cisco_node_utils/node_util.rb +5 -1
- data/lib/cisco_node_utils/ntp_config.rb +2 -2
- data/lib/cisco_node_utils/ntp_server.rb +14 -5
- data/lib/cisco_node_utils/overlay_global.rb +153 -0
- data/lib/cisco_node_utils/pim.rb +124 -0
- data/lib/cisco_node_utils/pim_group_list.rb +108 -0
- data/lib/cisco_node_utils/pim_rp_address.rb +102 -0
- data/lib/cisco_node_utils/platform.rb +8 -9
- data/lib/cisco_node_utils/portchannel_global.rb +277 -0
- data/lib/cisco_node_utils/radius_global.rb +9 -19
- data/lib/cisco_node_utils/radius_server.rb +31 -41
- data/lib/cisco_node_utils/radius_server_group.rb +117 -0
- data/lib/cisco_node_utils/router_ospf.rb +1 -1
- data/lib/cisco_node_utils/router_ospf_vrf.rb +14 -19
- data/lib/cisco_node_utils/snmp_notification_receiver.rb +158 -0
- data/lib/cisco_node_utils/snmpcommunity.rb +3 -5
- data/lib/cisco_node_utils/snmpgroup.rb +1 -1
- data/lib/cisco_node_utils/snmpnotification.rb +57 -0
- data/lib/cisco_node_utils/snmpserver.rb +8 -17
- data/lib/cisco_node_utils/snmpuser.rb +67 -28
- data/lib/cisco_node_utils/syslog_server.rb +3 -9
- data/lib/cisco_node_utils/syslog_settings.rb +2 -10
- data/lib/cisco_node_utils/tacacs_server.rb +9 -14
- data/lib/cisco_node_utils/tacacs_server_group.rb +145 -0
- data/lib/cisco_node_utils/tacacs_server_host.rb +5 -9
- data/lib/cisco_node_utils/vdc.rb +88 -0
- data/lib/cisco_node_utils/version.rb +5 -2
- data/lib/cisco_node_utils/vlan.rb +71 -8
- data/lib/cisco_node_utils/vni.rb +227 -0
- data/lib/cisco_node_utils/vpc.rb +377 -0
- data/lib/cisco_node_utils/vrf.rb +60 -9
- data/lib/cisco_node_utils/vrf_af.rb +191 -0
- data/lib/cisco_node_utils/vtp.rb +8 -6
- data/lib/cisco_node_utils/vxlan_vtep.rb +151 -0
- data/lib/cisco_node_utils/vxlan_vtep_vni.rb +234 -0
- data/lib/cisco_node_utils/yum.rb +1 -1
- data/tests/.rubocop.yml +1 -1
- data/tests/basetest.rb +16 -7
- data/tests/ciscotest.rb +55 -13
- data/tests/cmd_config.yaml +2 -2
- data/tests/platform_info.rb +3 -2
- data/tests/test_aaa_authentication_login.rb +219 -0
- data/tests/test_aaa_authentication_login_service.rb +759 -0
- data/tests/test_aaa_authorization_service.rb +1041 -0
- data/tests/test_ace.rb +160 -0
- data/tests/test_acl.rb +176 -0
- data/tests/test_bgp_af.rb +269 -13
- data/tests/test_bgp_neighbor.rb +38 -40
- data/tests/test_bgp_neighbor_af.rb +92 -32
- data/tests/test_command_config.rb +5 -5
- data/tests/test_command_reference.rb +284 -101
- data/tests/test_dns_domain.rb +1 -1
- data/tests/test_domain_name.rb +1 -1
- data/tests/test_evpn_vni.rb +106 -0
- data/tests/test_fabricpath_global.rb +243 -0
- data/tests/test_fabricpath_topology.rb +98 -0
- data/tests/test_interface.rb +292 -74
- data/tests/test_interface_channel_group.rb +74 -0
- data/tests/test_interface_ospf.rb +9 -4
- data/tests/test_interface_portchannel.rb +105 -0
- data/tests/test_interface_service_vni.rb +232 -0
- data/tests/test_interface_svi.rb +77 -62
- data/tests/test_interface_switchport.rb +17 -5
- data/tests/test_name_server.rb +1 -1
- data/tests/test_node.rb +1 -1
- data/tests/test_node_ext.rb +10 -20
- data/tests/test_ntp_config.rb +1 -1
- data/tests/test_ntp_server.rb +18 -6
- data/tests/test_overlay_global.rb +102 -0
- data/tests/test_pim.rb +177 -0
- data/tests/test_pim_group_list.rb +181 -0
- data/tests/test_pim_rp_address.rb +153 -0
- data/tests/test_platform.rb +3 -3
- data/tests/test_portchannel_global.rb +202 -0
- data/tests/test_radius_global.rb +1 -1
- data/tests/test_radius_server.rb +92 -57
- data/tests/test_radius_server_group.rb +149 -0
- data/tests/test_router_bgp.rb +283 -112
- data/tests/test_router_ospf.rb +2 -2
- data/tests/test_router_ospf_vrf.rb +4 -4
- data/tests/test_snmp_notification_receiver.rb +167 -0
- data/tests/test_snmpcommunity.rb +1 -1
- data/tests/test_snmpgroup.rb +1 -1
- data/tests/test_snmpnotification.rb +72 -0
- data/tests/test_snmpserver.rb +29 -105
- data/tests/test_snmpuser.rb +32 -30
- data/tests/test_syslog_server.rb +36 -10
- data/tests/test_syslog_settings.rb +1 -1
- data/tests/test_tacacs_server.rb +1 -1
- data/tests/test_tacacs_server_group.rb +405 -0
- data/tests/test_tacacs_server_host.rb +1 -1
- data/tests/test_vdc.rb +78 -0
- data/tests/test_vlan.rb +74 -19
- data/tests/test_vlan_mt_full.rb +95 -0
- data/tests/test_vni.rb +106 -0
- data/tests/test_vpc.rb +361 -0
- data/tests/test_vrf.rb +172 -29
- data/tests/test_vtp.rb +1 -1
- data/tests/test_vxlan_vtep.rb +214 -0
- data/tests/test_vxlan_vtep_vni.rb +201 -0
- data/tests/test_yum.rb +1 -1
- metadata +120 -11
- data/lib/cisco_node_utils/README_YAML.md +0 -325
- data/lib/cisco_node_utils/command_reference_common.yaml +0 -1051
- data/lib/cisco_node_utils/command_reference_common_bgp.yaml +0 -535
- data/lib/cisco_node_utils/command_reference_n3064.yaml +0 -13
- data/lib/cisco_node_utils/command_reference_n7k.yaml +0 -52
- data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -26
- 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
|
-
`
|
|
108
|
+
`lib/cisco_node_utils/cmd_ref/eigrp.yaml`
|
|
108
109
|
|
|
109
|
-
|
|
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
|
-
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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.
|
data/docs/template-router.rb
CHANGED
|
@@ -43,8 +43,7 @@ module Cisco
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def feature_enabled
|
|
46
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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:
|
|
6
|
+
Max: 45
|
|
7
7
|
|
|
8
8
|
Metrics/CyclomaticComplexity:
|
|
9
|
-
Max:
|
|
9
|
+
Max: 23
|
|
10
10
|
|
|
11
11
|
Metrics/MethodLength:
|
|
12
|
-
Max:
|
|
12
|
+
Max: 48
|
|
13
13
|
|
|
14
14
|
Metrics/ParameterLists:
|
|
15
15
|
Max: 9
|
|
16
16
|
|
|
17
17
|
Metrics/PerceivedComplexity:
|
|
18
|
-
Max:
|
|
18
|
+
Max: 24
|
data/lib/cisco_node_utils.rb
CHANGED
|
@@ -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
|