cisco_node_utils_mgx 2.1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rubocop.yml +96 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +676 -0
- data/CONTRIBUTING.md +43 -0
- data/Gemfile +10 -0
- data/LICENSE +201 -0
- data/README.md +246 -0
- data/Rakefile +44 -0
- data/SUPPORT.md +3 -0
- data/bin/.rubocop.yml +18 -0
- data/bin/check_metric_limits.rb +109 -0
- data/bin/git/hooks/commit-msg/enforce_style +89 -0
- data/bin/git/hooks/hook_lib +115 -0
- data/bin/git/hooks/hooks-wrapper +38 -0
- data/bin/git/hooks/post-flow-hotfix-start/update-version +24 -0
- data/bin/git/hooks/post-flow-release-finish/update-version +29 -0
- data/bin/git/hooks/post-flow-release-start/update-version +19 -0
- data/bin/git/hooks/post-merge/update-hooks +6 -0
- data/bin/git/hooks/post-rewrite/update-hooks +6 -0
- data/bin/git/hooks/pre-commit/check_unstaged_changes +18 -0
- data/bin/git/hooks/pre-commit/rubocop +25 -0
- data/bin/git/hooks/pre-commit/validate-diffs +45 -0
- data/bin/git/hooks/pre-commit/validate-yaml +18 -0
- data/bin/git/hooks/pre-push/check-changelog +24 -0
- data/bin/git/hooks/pre-push/rubocop +7 -0
- data/bin/git/update-hooks +123 -0
- data/bin/show_running_yang.rb +233 -0
- data/cisco_node_utils.gemspec +41 -0
- data/docs/README-develop-best-practices.md +521 -0
- data/docs/README-develop-node-utils-APIs.md +570 -0
- data/docs/README-maintainers.md +77 -0
- data/docs/README-test-execution.md +57 -0
- data/docs/README-utilities.md +14 -0
- data/docs/agent_files.png +0 -0
- data/docs/cisco_node_utils.yaml.example +36 -0
- data/docs/template-router.rb +123 -0
- data/docs/template-test_router.rb +104 -0
- data/ext/mkrf_conf.rb +63 -0
- data/lib/.rubocop.yml +18 -0
- data/lib/cisco_node_utils/aaa_authentication_login.rb +95 -0
- data/lib/cisco_node_utils/aaa_authentication_login_service.rb +138 -0
- data/lib/cisco_node_utils/aaa_authorization_service.rb +156 -0
- data/lib/cisco_node_utils/ace.rb +467 -0
- data/lib/cisco_node_utils/acl.rb +101 -0
- data/lib/cisco_node_utils/banner.rb +63 -0
- data/lib/cisco_node_utils/bfd_global.rb +305 -0
- data/lib/cisco_node_utils/bgp.rb +988 -0
- data/lib/cisco_node_utils/bgp_af.rb +545 -0
- data/lib/cisco_node_utils/bgp_af_aggr_addr.rb +207 -0
- data/lib/cisco_node_utils/bgp_neighbor.rb +527 -0
- data/lib/cisco_node_utils/bgp_neighbor_af.rb +780 -0
- data/lib/cisco_node_utils/bridge_domain.rb +178 -0
- data/lib/cisco_node_utils/bridge_domain_vni.rb +206 -0
- data/lib/cisco_node_utils/cisco_cmn_utils.rb +444 -0
- data/lib/cisco_node_utils/client/client.rb +238 -0
- data/lib/cisco_node_utils/client/grpc/client.rb +395 -0
- data/lib/cisco_node_utils/client/grpc/ems.proto +148 -0
- data/lib/cisco_node_utils/client/grpc/ems.rb +111 -0
- data/lib/cisco_node_utils/client/grpc/ems_services.rb +49 -0
- data/lib/cisco_node_utils/client/grpc.rb +33 -0
- data/lib/cisco_node_utils/client/nxapi/client.rb +368 -0
- data/lib/cisco_node_utils/client/nxapi.rb +31 -0
- data/lib/cisco_node_utils/client/utils.rb +180 -0
- data/lib/cisco_node_utils/client.rb +35 -0
- data/lib/cisco_node_utils/cmd_ref/README_YAML.md +590 -0
- data/lib/cisco_node_utils/cmd_ref/aaa_auth_login_service.yaml +25 -0
- data/lib/cisco_node_utils/cmd_ref/aaa_authentication_login.yaml +38 -0
- data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +40 -0
- data/lib/cisco_node_utils/cmd_ref/acl.yaml +48 -0
- data/lib/cisco_node_utils/cmd_ref/banner.yaml +11 -0
- data/lib/cisco_node_utils/cmd_ref/bfd_global.yaml +117 -0
- data/lib/cisco_node_utils/cmd_ref/bgp.yaml +383 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +223 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_af_aa.yaml +38 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +174 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +236 -0
- data/lib/cisco_node_utils/cmd_ref/bridge_domain.yaml +49 -0
- data/lib/cisco_node_utils/cmd_ref/bridge_domain_vni.yaml +33 -0
- data/lib/cisco_node_utils/cmd_ref/dhcp_relay_global.yaml +128 -0
- data/lib/cisco_node_utils/cmd_ref/dnsclient.yaml +55 -0
- data/lib/cisco_node_utils/cmd_ref/encapsulation.yaml +25 -0
- data/lib/cisco_node_utils/cmd_ref/evpn_multicast.yaml +12 -0
- data/lib/cisco_node_utils/cmd_ref/evpn_multisite.yaml +18 -0
- data/lib/cisco_node_utils/cmd_ref/evpn_stormcontrol.yaml +18 -0
- data/lib/cisco_node_utils/cmd_ref/evpn_vni.yaml +48 -0
- data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +183 -0
- data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +40 -0
- data/lib/cisco_node_utils/cmd_ref/feature.yaml +126 -0
- data/lib/cisco_node_utils/cmd_ref/hostname.yaml +8 -0
- data/lib/cisco_node_utils/cmd_ref/hsrp_global.yaml +25 -0
- data/lib/cisco_node_utils/cmd_ref/images.yaml +8 -0
- data/lib/cisco_node_utils/cmd_ref/interface.yaml +781 -0
- data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +45 -0
- data/lib/cisco_node_utils/cmd_ref/interface_evpn_multisite.yaml +17 -0
- data/lib/cisco_node_utils/cmd_ref/interface_hsrp_group.yaml +120 -0
- data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +112 -0
- data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +87 -0
- data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +42 -0
- data/lib/cisco_node_utils/cmd_ref/inventory.yaml +45 -0
- data/lib/cisco_node_utils/cmd_ref/ip_multicast.yaml +22 -0
- data/lib/cisco_node_utils/cmd_ref/itd_device_group.yaml +83 -0
- data/lib/cisco_node_utils/cmd_ref/itd_service.yaml +119 -0
- data/lib/cisco_node_utils/cmd_ref/memory.yaml +24 -0
- data/lib/cisco_node_utils/cmd_ref/ntp_auth_key.yaml +10 -0
- data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +27 -0
- data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +34 -0
- data/lib/cisco_node_utils/cmd_ref/object_group.yaml +32 -0
- data/lib/cisco_node_utils/cmd_ref/ospf.yaml +91 -0
- data/lib/cisco_node_utils/cmd_ref/ospf_area.yaml +91 -0
- data/lib/cisco_node_utils/cmd_ref/ospf_area_vlink.yaml +88 -0
- data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +37 -0
- data/lib/cisco_node_utils/cmd_ref/pim.yaml +43 -0
- data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +86 -0
- data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +37 -0
- data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +100 -0
- data/lib/cisco_node_utils/cmd_ref/radius_server_group.yaml +19 -0
- data/lib/cisco_node_utils/cmd_ref/route_map.yaml +601 -0
- data/lib/cisco_node_utils/cmd_ref/show_system.yaml +9 -0
- data/lib/cisco_node_utils/cmd_ref/show_version.yaml +84 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +81 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_group.yaml +9 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +74 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +91 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +57 -0
- data/lib/cisco_node_utils/cmd_ref/snmpnotification.yaml +23 -0
- data/lib/cisco_node_utils/cmd_ref/span_session.yaml +65 -0
- data/lib/cisco_node_utils/cmd_ref/stp_global.yaml +235 -0
- data/lib/cisco_node_utils/cmd_ref/syslog_facility.yaml +10 -0
- data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +34 -0
- data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +45 -0
- data/lib/cisco_node_utils/cmd_ref/system.yaml +7 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_global.yaml +37 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +63 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_server_group.yaml +45 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +64 -0
- data/lib/cisco_node_utils/cmd_ref/upgrade.yaml +38 -0
- data/lib/cisco_node_utils/cmd_ref/vdc.yaml +52 -0
- data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +8 -0
- data/lib/cisco_node_utils/cmd_ref/vlan.yaml +106 -0
- data/lib/cisco_node_utils/cmd_ref/vpc.yaml +233 -0
- data/lib/cisco_node_utils/cmd_ref/vrf.yaml +86 -0
- data/lib/cisco_node_utils/cmd_ref/vrf_af.yaml +139 -0
- data/lib/cisco_node_utils/cmd_ref/vtp.yaml +32 -0
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +114 -0
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +71 -0
- data/lib/cisco_node_utils/cmd_ref/yang.yaml +7 -0
- data/lib/cisco_node_utils/cmd_ref/yum.yaml +68 -0
- data/lib/cisco_node_utils/command_reference.rb +724 -0
- data/lib/cisco_node_utils/configparser_lib.rb +195 -0
- data/lib/cisco_node_utils/constants.rb +40 -0
- data/lib/cisco_node_utils/dhcp_relay_global.rb +302 -0
- data/lib/cisco_node_utils/dns_domain.rb +93 -0
- data/lib/cisco_node_utils/domain_name.rb +82 -0
- data/lib/cisco_node_utils/encapsulation.rb +112 -0
- data/lib/cisco_node_utils/environment.rb +110 -0
- data/lib/cisco_node_utils/evpn_multicast.rb +66 -0
- data/lib/cisco_node_utils/evpn_multisite.rb +96 -0
- data/lib/cisco_node_utils/evpn_stormcontrol.rb +84 -0
- data/lib/cisco_node_utils/evpn_vni.rb +159 -0
- data/lib/cisco_node_utils/exceptions.rb +140 -0
- data/lib/cisco_node_utils/fabricpath_global.rb +405 -0
- data/lib/cisco_node_utils/fabricpath_topology.rb +137 -0
- data/lib/cisco_node_utils/feature.rb +377 -0
- data/lib/cisco_node_utils/hostname.rb +62 -0
- data/lib/cisco_node_utils/hsrp_global.rb +97 -0
- data/lib/cisco_node_utils/interface.rb +2128 -0
- data/lib/cisco_node_utils/interface_channel_group.rb +142 -0
- data/lib/cisco_node_utils/interface_evpn_multisite.rb +72 -0
- data/lib/cisco_node_utils/interface_hsrp_group.rb +557 -0
- data/lib/cisco_node_utils/interface_ospf.rb +378 -0
- data/lib/cisco_node_utils/interface_portchannel.rb +180 -0
- data/lib/cisco_node_utils/interface_service_vni.rb +132 -0
- data/lib/cisco_node_utils/ip_multicast.rb +90 -0
- data/lib/cisco_node_utils/itd_device_group.rb +228 -0
- data/lib/cisco_node_utils/itd_device_group_node.rb +144 -0
- data/lib/cisco_node_utils/itd_service.rb +511 -0
- data/lib/cisco_node_utils/logger.rb +78 -0
- data/lib/cisco_node_utils/name_server.rb +64 -0
- data/lib/cisco_node_utils/node.rb +443 -0
- data/lib/cisco_node_utils/node_util.rb +111 -0
- data/lib/cisco_node_utils/ntp_auth_key.rb +67 -0
- data/lib/cisco_node_utils/ntp_config.rb +83 -0
- data/lib/cisco_node_utils/ntp_server.rb +86 -0
- data/lib/cisco_node_utils/object_group.rb +75 -0
- data/lib/cisco_node_utils/object_group_entry.rb +143 -0
- data/lib/cisco_node_utils/overlay_global.rb +142 -0
- data/lib/cisco_node_utils/pim.rb +131 -0
- data/lib/cisco_node_utils/pim_group_list.rb +109 -0
- data/lib/cisco_node_utils/pim_rp_address.rb +103 -0
- data/lib/cisco_node_utils/platform.rb +217 -0
- data/lib/cisco_node_utils/portchannel_global.rb +347 -0
- data/lib/cisco_node_utils/radius_global.rb +165 -0
- data/lib/cisco_node_utils/radius_server.rb +421 -0
- data/lib/cisco_node_utils/radius_server_group.rb +117 -0
- data/lib/cisco_node_utils/route_map.rb +2540 -0
- data/lib/cisco_node_utils/router_ospf.rb +77 -0
- data/lib/cisco_node_utils/router_ospf_area.rb +416 -0
- data/lib/cisco_node_utils/router_ospf_area_vlink.rb +313 -0
- data/lib/cisco_node_utils/router_ospf_vrf.rb +342 -0
- data/lib/cisco_node_utils/snmp_notification_receiver.rb +176 -0
- data/lib/cisco_node_utils/snmpcommunity.rb +109 -0
- data/lib/cisco_node_utils/snmpgroup.rb +54 -0
- data/lib/cisco_node_utils/snmpnotification.rb +57 -0
- data/lib/cisco_node_utils/snmpserver.rb +132 -0
- data/lib/cisco_node_utils/snmpuser.rb +403 -0
- data/lib/cisco_node_utils/span_session.rb +149 -0
- data/lib/cisco_node_utils/stp_global.rb +676 -0
- data/lib/cisco_node_utils/syslog_facility.rb +64 -0
- data/lib/cisco_node_utils/syslog_server.rb +146 -0
- data/lib/cisco_node_utils/syslog_settings.rb +174 -0
- data/lib/cisco_node_utils/tacacs_global.rb +137 -0
- data/lib/cisco_node_utils/tacacs_server.rb +173 -0
- data/lib/cisco_node_utils/tacacs_server_group.rb +149 -0
- data/lib/cisco_node_utils/tacacs_server_host.rb +216 -0
- data/lib/cisco_node_utils/upgrade.rb +122 -0
- data/lib/cisco_node_utils/vdc.rb +118 -0
- data/lib/cisco_node_utils/version.rb +21 -0
- data/lib/cisco_node_utils/vlan.rb +301 -0
- data/lib/cisco_node_utils/vpc.rb +466 -0
- data/lib/cisco_node_utils/vrf.rb +192 -0
- data/lib/cisco_node_utils/vrf_af.rb +327 -0
- data/lib/cisco_node_utils/vtp.rb +125 -0
- data/lib/cisco_node_utils/vxlan_vtep.rb +286 -0
- data/lib/cisco_node_utils/vxlan_vtep_vni.rb +331 -0
- data/lib/cisco_node_utils/yang.rb +160 -0
- data/lib/cisco_node_utils/yum.rb +213 -0
- data/lib/cisco_node_utils.rb +21 -0
- data/lib/minitest/environment_plugin.rb +31 -0
- data/lib/minitest/log_level_plugin.rb +41 -0
- data/spec/client_spec.rb +7 -0
- data/spec/environment_spec.rb +384 -0
- data/spec/grpc_client_spec.rb +23 -0
- data/spec/isolate/all_clients_spec.rb +9 -0
- data/spec/isolate/grpc_only_spec.rb +16 -0
- data/spec/isolate/no_clients_spec.rb +26 -0
- data/spec/isolate/nxapi_only_spec.rb +16 -0
- data/spec/nxapi_client_spec.rb +42 -0
- data/spec/schema.yaml +82 -0
- data/spec/shared_examples_for_clients.rb +14 -0
- data/spec/spec_helper.rb +91 -0
- data/spec/whitespace_spec.rb +10 -0
- data/spec/yaml_spec.rb +42 -0
- data/tests/.rubocop.yml +18 -0
- data/tests/CSCuxdublin-1.0.0-7.0.3.I3.1.lib32_n9000.rpm +0 -0
- data/tests/basetest.rb +243 -0
- data/tests/ciscotest.rb +577 -0
- data/tests/cmd_config.yaml +75 -0
- data/tests/cmd_config_invalid.yaml +16 -0
- data/tests/n9000_sample-1.0.0-7.0.3.x86_64.rpm +0 -0
- data/tests/noop.rb +7 -0
- data/tests/platform_info.rb +63 -0
- data/tests/tacacs_server.yaml.example +6 -0
- data/tests/test_aaa_authentication_login.rb +243 -0
- data/tests/test_aaa_authentication_login_service.rb +761 -0
- data/tests/test_aaa_authorization_service.rb +874 -0
- data/tests/test_ace.rb +304 -0
- data/tests/test_acl.rb +185 -0
- data/tests/test_banner.rb +85 -0
- data/tests/test_bfd_global.rb +272 -0
- data/tests/test_bgp_af.rb +875 -0
- data/tests/test_bgp_af_aa.rb +108 -0
- data/tests/test_bgp_neighbor.rb +596 -0
- data/tests/test_bgp_neighbor_af.rb +781 -0
- data/tests/test_bridge_domain.rb +198 -0
- data/tests/test_bridge_domain_vni.rb +109 -0
- data/tests/test_client_utils.rb +111 -0
- data/tests/test_cmn_utils.rb +76 -0
- data/tests/test_command_config.rb +206 -0
- data/tests/test_command_reference.rb +669 -0
- data/tests/test_dhcp_relay_global.rb +286 -0
- data/tests/test_dns_domain.rb +123 -0
- data/tests/test_domain_name.rb +96 -0
- data/tests/test_encapsulation.rb +75 -0
- data/tests/test_evpn_multicast.rb +65 -0
- data/tests/test_evpn_multisite.rb +70 -0
- data/tests/test_evpn_stormcontrol.rb +56 -0
- data/tests/test_evpn_vni.rb +131 -0
- data/tests/test_fabricpath_global.rb +246 -0
- data/tests/test_fabricpath_topology.rb +77 -0
- data/tests/test_feature.rb +272 -0
- data/tests/test_grpc.rb +166 -0
- data/tests/test_hostname.rb +64 -0
- data/tests/test_hsrp_global.rb +79 -0
- data/tests/test_interface.rb +1958 -0
- data/tests/test_interface_bdi.rb +80 -0
- data/tests/test_interface_channel_group.rb +131 -0
- data/tests/test_interface_evpn_multisite.rb +94 -0
- data/tests/test_interface_hsrp.rb +134 -0
- data/tests/test_interface_hsrp_group.rb +570 -0
- data/tests/test_interface_ospf.rb +820 -0
- data/tests/test_interface_portchannel.rb +135 -0
- data/tests/test_interface_private_vlan.rb +365 -0
- data/tests/test_interface_service_vni.rb +203 -0
- data/tests/test_interface_svi.rb +210 -0
- data/tests/test_interface_switchport.rb +468 -0
- data/tests/test_ip_multicast.rb +80 -0
- data/tests/test_itd_device_group.rb +145 -0
- data/tests/test_itd_device_group_node.rb +199 -0
- data/tests/test_itd_service.rb +314 -0
- data/tests/test_logger.rb +43 -0
- data/tests/test_name_server.rb +94 -0
- data/tests/test_node.rb +50 -0
- data/tests/test_node_ext.rb +406 -0
- data/tests/test_node_util.rb +119 -0
- data/tests/test_ntp_auth_key.rb +77 -0
- data/tests/test_ntp_config.rb +100 -0
- data/tests/test_ntp_server.rb +146 -0
- data/tests/test_nxapi.rb +236 -0
- data/tests/test_object_group.rb +122 -0
- data/tests/test_overlay_global.rb +108 -0
- data/tests/test_pim.rb +203 -0
- data/tests/test_pim_group_list.rb +147 -0
- data/tests/test_pim_rp_address.rb +155 -0
- data/tests/test_platform.rb +254 -0
- data/tests/test_portchannel_global.rb +322 -0
- data/tests/test_radius_global.rb +108 -0
- data/tests/test_radius_server.rb +377 -0
- data/tests/test_radius_server_group.rb +151 -0
- data/tests/test_route_map.rb +1479 -0
- data/tests/test_router_bgp.rb +1325 -0
- data/tests/test_router_ospf.rb +56 -0
- data/tests/test_router_ospf_area.rb +433 -0
- data/tests/test_router_ospf_area_vlink.rb +298 -0
- data/tests/test_router_ospf_vrf.rb +690 -0
- data/tests/test_snmp_notification_receiver.rb +169 -0
- data/tests/test_snmpcommunity.rb +422 -0
- data/tests/test_snmpgroup.rb +71 -0
- data/tests/test_snmpnotification.rb +91 -0
- data/tests/test_snmpserver.rb +251 -0
- data/tests/test_snmpuser.rb +666 -0
- data/tests/test_span_session.rb +155 -0
- data/tests/test_stp_global.rb +575 -0
- data/tests/test_syslog_facility.rb +80 -0
- data/tests/test_syslog_server.rb +119 -0
- data/tests/test_syslog_settings.rb +123 -0
- data/tests/test_tacacs_global.rb +109 -0
- data/tests/test_tacacs_server.rb +436 -0
- data/tests/test_tacacs_server_group.rb +434 -0
- data/tests/test_tacacs_server_host.rb +427 -0
- data/tests/test_upgrade.rb +105 -0
- data/tests/test_vdc.rb +64 -0
- data/tests/test_vlan.rb +386 -0
- data/tests/test_vlan_private.rb +656 -0
- data/tests/test_vpc.rb +548 -0
- data/tests/test_vrf.rb +248 -0
- data/tests/test_vrf_af.rb +288 -0
- data/tests/test_vtp.rb +278 -0
- data/tests/test_vxlan_vtep.rb +327 -0
- data/tests/test_vxlan_vtep_vni.rb +326 -0
- data/tests/test_yang.rb +369 -0
- data/tests/test_yum.rb +109 -0
- data/tests/upgrade_info.yaml.example +3 -0
- data/tests/yum_package.yaml +94 -0
- metadata +534 -0
@@ -0,0 +1,443 @@
|
|
1
|
+
# Cisco node helper class. Abstracts away the details of the underlying
|
2
|
+
# transport (whether NXAPI or some other future transport) and provides
|
3
|
+
# various convenient helper methods.
|
4
|
+
#
|
5
|
+
# December 2014, Glenn F. Matthews
|
6
|
+
#
|
7
|
+
# Copyright (c) 2014-2017 Cisco and/or its affiliates.
|
8
|
+
#
|
9
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
10
|
+
# you may not use this file except in compliance with the License.
|
11
|
+
# You may obtain a copy of the License at
|
12
|
+
#
|
13
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
14
|
+
#
|
15
|
+
# Unless required by applicable law or agreed to in writing, software
|
16
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
17
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
|
21
|
+
require_relative 'client'
|
22
|
+
require_relative 'command_reference'
|
23
|
+
require_relative 'exceptions'
|
24
|
+
require_relative 'logger'
|
25
|
+
|
26
|
+
# Add node management classes and APIs to the Cisco namespace.
|
27
|
+
module Cisco
|
28
|
+
# class Cisco::Node
|
29
|
+
# Singleton representing the network node (switch/router) that is
|
30
|
+
# running this code. The singleton is lazily instantiated, meaning that
|
31
|
+
# it doesn't exist until some client requests it (with Node.instance())
|
32
|
+
class Node
|
33
|
+
@instance = nil
|
34
|
+
|
35
|
+
# Convenience wrapper for get()
|
36
|
+
# Uses CommandReference to look up the given show command and key
|
37
|
+
# of interest, executes that command, and returns the value corresponding
|
38
|
+
# to that key.
|
39
|
+
#
|
40
|
+
# @raise [IndexError] if the given (feature, name) pair is not in the
|
41
|
+
# CommandReference data or if the data doesn't have values defined
|
42
|
+
# for the 'get_command' and (optional) 'get_value' fields.
|
43
|
+
# @raise [Cisco::UnsupportedError] if the (feature, name) pair is flagged
|
44
|
+
# in the YAML as unsupported on this device.
|
45
|
+
# @raise [Cisco::RequestFailed] if the command is rejected by the device.
|
46
|
+
#
|
47
|
+
# @param feature [String]
|
48
|
+
# @param name [String]
|
49
|
+
# @return [String, Hash, Array]
|
50
|
+
# @example config_get("show_version", "system_image")
|
51
|
+
# @example config_get("ospf", "router_id",
|
52
|
+
# {name: "green", vrf: "one"})
|
53
|
+
def config_get(feature, property, *args)
|
54
|
+
ref = @cmd_ref.lookup(feature, property)
|
55
|
+
|
56
|
+
# If we have a default value but no getter, just return the default
|
57
|
+
return ref.default_value if ref.default_value? && !ref.getter?
|
58
|
+
|
59
|
+
get_args, ref = massage_structured(ref.getter(*args).clone, ref)
|
60
|
+
data = get(command: get_args[:command],
|
61
|
+
data_format: get_args[:data_format],
|
62
|
+
context: get_args[:context],
|
63
|
+
value: get_args[:value])
|
64
|
+
massage(data, ref)
|
65
|
+
end
|
66
|
+
|
67
|
+
# The yaml file may specifiy an Array as the get_value to drill down into
|
68
|
+
# nxapi_structured table output. The table may contain multiple rows but
|
69
|
+
# only one of the rows has the interesting data.
|
70
|
+
def massage_structured(get_args, ref)
|
71
|
+
# Nothing to do unless nxapi_structured.
|
72
|
+
return [get_args, ref] unless
|
73
|
+
ref.hash['get_data_format'] == :nxapi_structured
|
74
|
+
|
75
|
+
# The CmdRef object will contain a get_value Array with 2 values.
|
76
|
+
# The first value is the key to identify the correct row in the table
|
77
|
+
# of structured output and the second is the key to identify the data
|
78
|
+
# to retrieve.
|
79
|
+
#
|
80
|
+
# Example: Get vlanshowbr-vlanname in the row that contains a specific
|
81
|
+
# vlan_id.
|
82
|
+
# "get_value"=>["vlanshowbr-vlanid-utf <vlan_id>", "vlanshowbr-vlanname"]
|
83
|
+
#
|
84
|
+
# TBD: Why do we need to check is_a?(Array) here?
|
85
|
+
if ref.hash['get_value'].is_a?(Array) && ref.hash['get_value'].size >= 2
|
86
|
+
# Replace the get_value hash entry with the value after any tokens
|
87
|
+
# specified in the yaml file have been replaced and set get_args[:value]
|
88
|
+
# to nil so that the structured table data can be retrieved properly.
|
89
|
+
ref.hash['get_value'] = get_args[:value]
|
90
|
+
ref.hash['drill_down'] = true
|
91
|
+
get_args[:value] = nil
|
92
|
+
end
|
93
|
+
[get_args, ref]
|
94
|
+
end
|
95
|
+
|
96
|
+
# Drill down into structured nxapi table data and return value from the
|
97
|
+
# row specified by a two part key.
|
98
|
+
#
|
99
|
+
# Example: Get vlanshowbr-vlanname in the row that contains vlan id 1000
|
100
|
+
# "get_value"=>["vlanshowbr-vlanid-utf 1000", "vlanshowbr-vlanname"]
|
101
|
+
# Example with optional regexp match
|
102
|
+
# "get_value"=>["vlanshowbr-vlanid-utf 1000", "vlanshowbr-vlanname",
|
103
|
+
# '/^shutdown$/']
|
104
|
+
def drill_down_structured(value, ref)
|
105
|
+
# Nothing to do unless nxapi_structured
|
106
|
+
return value unless ref.hash['drill_down']
|
107
|
+
|
108
|
+
row_key = ref.hash['get_value'][0][/^\S+/]
|
109
|
+
|
110
|
+
# Escape special characters if any in row_index and add
|
111
|
+
# anchors for exact match.
|
112
|
+
row_index = Regexp.escape(ref.hash['get_value'][0][/\S+$/])
|
113
|
+
row_index = "^#{row_index}$"
|
114
|
+
|
115
|
+
data_key = ref.hash['get_value'][1]
|
116
|
+
regexp_filter = nil
|
117
|
+
if ref.hash['get_value'][2]
|
118
|
+
regexp_filter = Regexp.new ref.hash['get_value'][2][1..-2]
|
119
|
+
end
|
120
|
+
# Get the value using the row_key, row_index and data_key
|
121
|
+
value = value.is_a?(Hash) ? [value] : value
|
122
|
+
data = nil
|
123
|
+
value.each do |row|
|
124
|
+
if row[row_key].to_s[/#{row_index}/]
|
125
|
+
data = row[data_key]
|
126
|
+
data = data.nil? ? '' : data
|
127
|
+
end
|
128
|
+
end
|
129
|
+
return value if data.nil?
|
130
|
+
if regexp_filter
|
131
|
+
filtered = regexp_filter.match(data)
|
132
|
+
return filtered.nil? ? filtered : filtered[filtered.size - 1]
|
133
|
+
end
|
134
|
+
data
|
135
|
+
end
|
136
|
+
|
137
|
+
# Attempt to massage the given value into the format specified by the
|
138
|
+
# given CmdRef object.
|
139
|
+
def massage(value, ref)
|
140
|
+
Cisco::Logger.debug "Massaging '#{value}' (#{value.inspect})"
|
141
|
+
value = drill_down_structured(value, ref)
|
142
|
+
if value.is_a?(Array) && !ref.multiple
|
143
|
+
fail "Expected zero/one value but got '#{value}'" if value.length > 1
|
144
|
+
value = value[0]
|
145
|
+
end
|
146
|
+
if (value.nil? || value.to_s.empty?) &&
|
147
|
+
ref.default_value? && ref.auto_default
|
148
|
+
Cisco::Logger.debug "Default: #{ref.default_value}"
|
149
|
+
return ref.default_value
|
150
|
+
end
|
151
|
+
if ref.multiple && ref.hash['get_data_format'] == :nxapi_structured
|
152
|
+
return value if value.nil?
|
153
|
+
value = [value.to_s] if value.is_a?(String) || value.is_a?(Fixnum)
|
154
|
+
end
|
155
|
+
return value unless ref.kind
|
156
|
+
value = massage_kind(value, ref)
|
157
|
+
Cisco::Logger.debug "Massaged to '#{value}'"
|
158
|
+
value
|
159
|
+
end
|
160
|
+
|
161
|
+
def massage_kind(value, ref)
|
162
|
+
case ref.kind
|
163
|
+
when :boolean
|
164
|
+
if value.nil? || value.empty?
|
165
|
+
value = false
|
166
|
+
elsif /^no / =~ value
|
167
|
+
value = false
|
168
|
+
elsif /disable$/ =~ value
|
169
|
+
value = false
|
170
|
+
else
|
171
|
+
value = true
|
172
|
+
end
|
173
|
+
when :int
|
174
|
+
value = value.to_i unless value.nil?
|
175
|
+
when :string
|
176
|
+
value = '' if value.nil?
|
177
|
+
value = value.to_s.strip
|
178
|
+
when :symbol
|
179
|
+
value = value.to_sym unless value.nil?
|
180
|
+
end
|
181
|
+
value
|
182
|
+
end
|
183
|
+
|
184
|
+
# Uses CommandReference to lookup the default value for a given
|
185
|
+
# feature and feature property.
|
186
|
+
#
|
187
|
+
# @raise [IndexError] if the given (feature, name) pair is not in the
|
188
|
+
# CommandReference data or if the data doesn't have values defined
|
189
|
+
# for the 'default_value' field.
|
190
|
+
# @param feature [String]
|
191
|
+
# @param name [String]
|
192
|
+
# @return [String]
|
193
|
+
# @return [nil] if this feature/name pair is marked as unsupported
|
194
|
+
# @example config_get_default("vtp", "file")
|
195
|
+
def config_get_default(feature, property)
|
196
|
+
ref = @cmd_ref.lookup(feature, property)
|
197
|
+
ref.default_value
|
198
|
+
end
|
199
|
+
|
200
|
+
# Uses CommandReference to look up the given config command(s) of interest
|
201
|
+
# and then applies the configuration.
|
202
|
+
#
|
203
|
+
# @raise [IndexError] if no relevant cmd_ref config_set exists
|
204
|
+
# @raise [ArgumentError] if too many or too few args are provided.
|
205
|
+
# @raise [Cisco::UnsupportedError] if this feature/name is unsupported
|
206
|
+
# @raise [Cisco::RequestFailed] if any command is rejected by the device.
|
207
|
+
#
|
208
|
+
# @param feature [String]
|
209
|
+
# @param name [String]
|
210
|
+
# @param args [*String] zero or more args to be substituted into the cmdref.
|
211
|
+
# @example config_set("vtp", "domain", "example.com")
|
212
|
+
# @example config_set("ospf", "router_id",
|
213
|
+
# {:name => "green", :vrf => "one", :state => "",
|
214
|
+
# :router_id => "192.0.0.1"})
|
215
|
+
def config_set(feature, property, *args)
|
216
|
+
ref = @cmd_ref.lookup(feature, property)
|
217
|
+
set_args = ref.setter(*args)
|
218
|
+
set(**set_args)
|
219
|
+
end
|
220
|
+
|
221
|
+
# Clear the cache of CLI output results.
|
222
|
+
#
|
223
|
+
# If cache_auto is true (default) then this will be performed automatically
|
224
|
+
# whenever a config_set() is called, but providers may also call this
|
225
|
+
# to explicitly force the cache to be cleared.
|
226
|
+
def cache_flush
|
227
|
+
@client.cache_flush
|
228
|
+
end
|
229
|
+
|
230
|
+
# Here and below are implementation details and private APIs that most
|
231
|
+
# providers shouldn't need to know about or use.
|
232
|
+
|
233
|
+
attr_reader :cmd_ref, :client
|
234
|
+
|
235
|
+
def self.instance
|
236
|
+
@instance ||= new
|
237
|
+
end
|
238
|
+
|
239
|
+
# Allow instance cache to be reset
|
240
|
+
def self.reset_instance
|
241
|
+
@instance = nil
|
242
|
+
end
|
243
|
+
|
244
|
+
def initialize
|
245
|
+
@client = Cisco::Client.create
|
246
|
+
@cmd_ref = nil
|
247
|
+
@cmd_ref = CommandReference.new(product: product_id,
|
248
|
+
platform: @client.platform,
|
249
|
+
data_formats: @client.data_formats)
|
250
|
+
cache_flush
|
251
|
+
end
|
252
|
+
|
253
|
+
def to_s
|
254
|
+
client.to_s
|
255
|
+
end
|
256
|
+
|
257
|
+
def inspect
|
258
|
+
"Node: client:'#{client.inspect}' cmd_ref:'#{cmd_ref.inspect}'"
|
259
|
+
end
|
260
|
+
|
261
|
+
def cache_enable?
|
262
|
+
@client.cache_enable?
|
263
|
+
end
|
264
|
+
|
265
|
+
def cache_enable=(enable)
|
266
|
+
@client.cache_enable = enable
|
267
|
+
end
|
268
|
+
|
269
|
+
def cache_auto?
|
270
|
+
@client.cache_auto?
|
271
|
+
end
|
272
|
+
|
273
|
+
def cache_auto=(enable)
|
274
|
+
@client.cache_auto = enable
|
275
|
+
end
|
276
|
+
|
277
|
+
# Send a config command to the device.
|
278
|
+
# In general, clients should use config_set() rather than calling
|
279
|
+
# this function directly.
|
280
|
+
#
|
281
|
+
# @raise [Cisco::RequestFailed] if any command is rejected by the device.
|
282
|
+
def set(**kwargs)
|
283
|
+
@client.set(**kwargs)
|
284
|
+
end
|
285
|
+
|
286
|
+
# Send a show command to the device.
|
287
|
+
# In general, clients should use config_get() rather than calling
|
288
|
+
# this function directly.
|
289
|
+
#
|
290
|
+
# @raise [Cisco::RequestFailed] if any command is rejected by the device.
|
291
|
+
def get(**kwargs)
|
292
|
+
@client.get(**kwargs)
|
293
|
+
end
|
294
|
+
|
295
|
+
# Merge the specified JSON YANG config with the running config on
|
296
|
+
# the device.
|
297
|
+
def merge_yang(yang)
|
298
|
+
@client.set(data_format: :yang_json, values: [yang], mode: :merge_config)
|
299
|
+
end
|
300
|
+
|
301
|
+
# Replace the running config on the device with the specified
|
302
|
+
# JSON YANG config.
|
303
|
+
def replace_yang(yang)
|
304
|
+
@client.set(data_format: :yang_json, values: [yang],
|
305
|
+
mode: :replace_config)
|
306
|
+
end
|
307
|
+
|
308
|
+
# Delete the specified JSON YANG config from the device.
|
309
|
+
def delete_yang(yang)
|
310
|
+
@client.set(data_format: :yang_json, values: [yang], mode: :delete_config)
|
311
|
+
end
|
312
|
+
|
313
|
+
# Retrieve JSON YANG config from the device for the specified path.
|
314
|
+
def get_yang(yang_path)
|
315
|
+
@client.get(data_format: :yang_json, command: yang_path)
|
316
|
+
end
|
317
|
+
|
318
|
+
# Retrieve JSON YANG operational data for the specified path.
|
319
|
+
def get_yang_oper(yang_path)
|
320
|
+
@client.get(data_format: :yang_json, command: yang_path, mode: :get_oper)
|
321
|
+
end
|
322
|
+
|
323
|
+
# @return [String] such as "Cisco Nexus Operating System (NX-OS) Software"
|
324
|
+
def os
|
325
|
+
o = config_get('show_version', 'header')
|
326
|
+
fail 'failed to retrieve operating system information' if o.nil?
|
327
|
+
o.split("\n")[0]
|
328
|
+
end
|
329
|
+
|
330
|
+
# @return [String] such as "6.0(2)U5(1) [build 6.0(2)U5(0.941)]"
|
331
|
+
def os_version
|
332
|
+
config_get('show_version', 'version')
|
333
|
+
end
|
334
|
+
|
335
|
+
# @return [String] such as "Nexus 3048 Chassis"
|
336
|
+
def product_description
|
337
|
+
config_get('show_version', 'description')
|
338
|
+
end
|
339
|
+
|
340
|
+
# @return [String] such as "N3K-C3048TP-1GE"
|
341
|
+
def product_id
|
342
|
+
if @cmd_ref
|
343
|
+
prod = config_get('inventory', 'productid')
|
344
|
+
all = config_get('inventory', 'all')
|
345
|
+
prod_qualifier(prod, all)
|
346
|
+
else
|
347
|
+
# We use this function to *find* the appropriate CommandReference
|
348
|
+
if @client.platform == :nexus
|
349
|
+
entries = get(command: 'show inventory',
|
350
|
+
data_format: :nxapi_structured)
|
351
|
+
prod = entries['TABLE_inv']['ROW_inv'][0]['productid']
|
352
|
+
prod_qualifier(prod, entries['TABLE_inv']['ROW_inv'])
|
353
|
+
elsif @client.platform == :ios_xr
|
354
|
+
# No support for structured output for this command yet
|
355
|
+
output = get(command: 'show inventory',
|
356
|
+
data_format: :cli)
|
357
|
+
return /NAME: .*\nPID: (\S+)/.match(output)[1]
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
def prod_qualifier(prod, inventory)
|
363
|
+
case prod
|
364
|
+
when /N(3|9)K/
|
365
|
+
# one datapoint is used to determine if the current n9k/n3k
|
366
|
+
# platform is a fretta based or non-fretta.
|
367
|
+
#
|
368
|
+
# Module == *-R
|
369
|
+
inventory.each do |row|
|
370
|
+
if row['productid'][/-R/]
|
371
|
+
# Append -F for fretta platform.
|
372
|
+
return prod.concat('-F') unless prod[/-F/]
|
373
|
+
end
|
374
|
+
end
|
375
|
+
end
|
376
|
+
prod
|
377
|
+
end
|
378
|
+
|
379
|
+
# @return [String] such as "V01"
|
380
|
+
def product_version_id
|
381
|
+
config_get('inventory', 'versionid')
|
382
|
+
end
|
383
|
+
|
384
|
+
# @return [String] such as "FOC1722R0ET"
|
385
|
+
def product_serial_number
|
386
|
+
config_get('inventory', 'serialnum')
|
387
|
+
end
|
388
|
+
|
389
|
+
# @return [String] such as "bxb-oa-n3k-7"
|
390
|
+
def host_name
|
391
|
+
config_get('show_version', 'host_name')
|
392
|
+
end
|
393
|
+
|
394
|
+
# @return [String] such as "example.com"
|
395
|
+
def domain_name
|
396
|
+
config_get('dnsclient', 'domain_name')
|
397
|
+
end
|
398
|
+
|
399
|
+
# @return [Integer] System uptime, in seconds
|
400
|
+
def system_uptime
|
401
|
+
cache_flush
|
402
|
+
t = config_get('show_system', 'uptime')
|
403
|
+
fail 'failed to retrieve system uptime' if t.nil?
|
404
|
+
# time units: t = ["0", "23", "15", "49"]
|
405
|
+
t.map!(&:to_i)
|
406
|
+
d, h, m, s = t
|
407
|
+
(s + 60 * (m + 60 * (h + 24 * (d))))
|
408
|
+
end
|
409
|
+
|
410
|
+
# @return [String] timestamp of last reset time
|
411
|
+
def last_reset_time
|
412
|
+
config_get('show_version', 'last_reset_time')
|
413
|
+
end
|
414
|
+
|
415
|
+
# @return [String] such as "Reset Requested by CLI command reload"
|
416
|
+
def last_reset_reason
|
417
|
+
config_get('show_version', 'last_reset_reason')
|
418
|
+
end
|
419
|
+
|
420
|
+
# @return [Float] combined user/kernel CPU utilization
|
421
|
+
def system_cpu_utilization
|
422
|
+
output = config_get('system', 'resources')
|
423
|
+
return output if output.nil?
|
424
|
+
output['cpu_state_user'].to_f + output['cpu_state_kernel'].to_f
|
425
|
+
end
|
426
|
+
|
427
|
+
# @return [String] such as
|
428
|
+
# "bootflash:///n3000-uk9-kickstart.6.0.2.U5.0.941.bin"
|
429
|
+
def boot
|
430
|
+
config_get('show_version', 'boot_image')
|
431
|
+
end
|
432
|
+
|
433
|
+
# @return [String] such as
|
434
|
+
# "bootflash:///n3000-uk9.6.0.2.U5.0.941.bin"
|
435
|
+
def system
|
436
|
+
config_get('show_version', 'system_image')
|
437
|
+
end
|
438
|
+
|
439
|
+
def os_version_get(feature, property)
|
440
|
+
@cmd_ref.lookup(feature, property).os_version
|
441
|
+
end
|
442
|
+
end
|
443
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
# September 2015, Glenn F. Matthews
|
2
|
+
#
|
3
|
+
# Copyright (c) 2014-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'
|
18
|
+
require_relative 'exceptions'
|
19
|
+
|
20
|
+
module Cisco
|
21
|
+
# NodeUtil - generic functionality for node utility subclasses to use
|
22
|
+
class NodeUtil
|
23
|
+
def self.node
|
24
|
+
Cisco::Node.instance
|
25
|
+
end
|
26
|
+
|
27
|
+
def node
|
28
|
+
self.class.node
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.client
|
32
|
+
node.client
|
33
|
+
end
|
34
|
+
|
35
|
+
def client
|
36
|
+
node.client
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.config_get(*args)
|
40
|
+
node.config_get(*args)
|
41
|
+
rescue Cisco::RequestFailed => e
|
42
|
+
e2 = e.class.new("[#{self}] #{e}", **e.kwargs)
|
43
|
+
e2.set_backtrace(e.backtrace)
|
44
|
+
raise e2
|
45
|
+
end
|
46
|
+
|
47
|
+
def config_get(*args)
|
48
|
+
node.config_get(*args)
|
49
|
+
rescue Cisco::RequestFailed => e
|
50
|
+
e2 = e.class.new("[#{self}] #{e}", **e.kwargs)
|
51
|
+
e2.set_backtrace(e.backtrace)
|
52
|
+
raise e2
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.config_get_default(*args)
|
56
|
+
node.config_get_default(*args)
|
57
|
+
end
|
58
|
+
|
59
|
+
def config_get_default(*args)
|
60
|
+
node.config_get_default(*args)
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.config_set(*args)
|
64
|
+
node.config_set(*args)
|
65
|
+
rescue Cisco::RequestFailed => e
|
66
|
+
e2 = e.class.new("[#{self}] #{e}", **e.kwargs)
|
67
|
+
e2.set_backtrace(e.backtrace)
|
68
|
+
raise e2
|
69
|
+
end
|
70
|
+
|
71
|
+
def config_set(*args)
|
72
|
+
node.config_set(*args)
|
73
|
+
rescue Cisco::RequestFailed => e
|
74
|
+
e2 = e.class.new("[#{self}] #{e}", **e.kwargs)
|
75
|
+
e2.set_backtrace(e.backtrace)
|
76
|
+
raise e2
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.supports?(api)
|
80
|
+
client.supports?(api)
|
81
|
+
end
|
82
|
+
|
83
|
+
def supports?(api)
|
84
|
+
client.supports?(api)
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.platform
|
88
|
+
client.platform
|
89
|
+
end
|
90
|
+
|
91
|
+
def platform
|
92
|
+
client.platform
|
93
|
+
end
|
94
|
+
|
95
|
+
def get(**kwargs)
|
96
|
+
node.get(**kwargs)
|
97
|
+
rescue Cisco::RequestFailed => e
|
98
|
+
e2 = e.class.new("[#{self}] #{e}", **e.kwargs)
|
99
|
+
e2.set_backtrace(e.backtrace)
|
100
|
+
raise e2
|
101
|
+
end
|
102
|
+
|
103
|
+
def ios_xr?
|
104
|
+
platform == :ios_xr
|
105
|
+
end
|
106
|
+
|
107
|
+
def nexus?
|
108
|
+
platform == :nexus
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# NTP Authentication key provider class
|
2
|
+
#
|
3
|
+
# Rick Sherman et al., April 2017
|
4
|
+
#
|
5
|
+
# Copyright (c) 2014-2017 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
|
+
# NtpAuthKey - node utility class for NTP authentication-key management
|
23
|
+
class NtpAuthKey < NodeUtil
|
24
|
+
attr_reader :algorithm, :mode, :password
|
25
|
+
|
26
|
+
def initialize(opts, instantiate=true)
|
27
|
+
@algorithm = opts['algorithm'].nil? ? 'md5' : opts['algorithm']
|
28
|
+
@key = opts['name']
|
29
|
+
@mode = opts['mode'].nil? ? '7' : opts['mode']
|
30
|
+
@password = opts['password']
|
31
|
+
|
32
|
+
create if instantiate
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.ntpkeys
|
36
|
+
keys = %w(name algorithm password mode)
|
37
|
+
hash = {}
|
38
|
+
ntp_auth_key_list = config_get('ntp_auth_key', 'key')
|
39
|
+
return hash if ntp_auth_key_list.empty?
|
40
|
+
|
41
|
+
ntp_auth_key_list.each do |id|
|
42
|
+
hash[id[0]] = NtpAuthKey.new(Hash[keys.zip(id)], false)
|
43
|
+
end
|
44
|
+
|
45
|
+
hash
|
46
|
+
end
|
47
|
+
|
48
|
+
def ==(other)
|
49
|
+
name == other.name
|
50
|
+
end
|
51
|
+
|
52
|
+
def create
|
53
|
+
config_set('ntp_auth_key', 'key', state: '', key: @key,
|
54
|
+
algorithm: @algorithm, password: @password, mode: @mode)
|
55
|
+
end
|
56
|
+
|
57
|
+
def destroy
|
58
|
+
# There appears to be a bug in NXOS that requires the password be passed
|
59
|
+
config_set('ntp_auth_key', 'key', state: 'no', key: @key,
|
60
|
+
algorithm: @algorithm, password: @password, mode: @mode)
|
61
|
+
end
|
62
|
+
|
63
|
+
def name
|
64
|
+
@key
|
65
|
+
end
|
66
|
+
end # class
|
67
|
+
end # module
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# NTP Config provider class
|
2
|
+
#
|
3
|
+
# Jonathan Tripathy et al., September 2015
|
4
|
+
#
|
5
|
+
# Copyright (c) 2014-2017 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
|
+
# NtpConfig - node utility class for NTP Config configuration management
|
23
|
+
class NtpConfig < NodeUtil
|
24
|
+
attr_reader :name
|
25
|
+
|
26
|
+
def initialize(name)
|
27
|
+
fail TypeError unless name.is_a?(String)
|
28
|
+
fail ArgumentError,
|
29
|
+
"This provider only accepts an id of 'default'" \
|
30
|
+
unless name.eql?('default')
|
31
|
+
@name = name
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.ntpconfigs
|
35
|
+
hash = {}
|
36
|
+
hash['default'] = NtpConfig.new('default')
|
37
|
+
hash
|
38
|
+
end
|
39
|
+
|
40
|
+
def ==(other)
|
41
|
+
name == other.name
|
42
|
+
end
|
43
|
+
|
44
|
+
def authenticate
|
45
|
+
config_get('ntp_config', 'authenticate')
|
46
|
+
end
|
47
|
+
|
48
|
+
def authenticate=(enable)
|
49
|
+
state = (enable ? '' : 'no')
|
50
|
+
config_set('ntp_config', 'authenticate', state: state)
|
51
|
+
end
|
52
|
+
|
53
|
+
def trusted_key
|
54
|
+
config_get('ntp_config', 'trusted_key')
|
55
|
+
end
|
56
|
+
|
57
|
+
def trusted_key_set(state, key)
|
58
|
+
state = (state ? '' : 'no')
|
59
|
+
config_set('ntp_config', 'trusted_key', state: state, key: key)
|
60
|
+
end
|
61
|
+
|
62
|
+
def source_interface
|
63
|
+
source_interface = config_get('ntp_config', 'source_interface')
|
64
|
+
source_interface = source_interface.downcase \
|
65
|
+
unless source_interface.nil?
|
66
|
+
source_interface
|
67
|
+
end
|
68
|
+
|
69
|
+
def source_interface=(val)
|
70
|
+
if val.nil? && !source_interface.nil?
|
71
|
+
config_set('ntp_config',
|
72
|
+
'source_interface',
|
73
|
+
state: 'no',
|
74
|
+
source_interface: source_interface)
|
75
|
+
elsif !val.nil?
|
76
|
+
config_set('ntp_config',
|
77
|
+
'source_interface',
|
78
|
+
state: '',
|
79
|
+
source_interface: val)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end # class
|
83
|
+
end # module
|