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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
#
|
|
4
4
|
# September 2015, Hunter Haugen
|
|
5
5
|
#
|
|
6
|
-
# Copyright (c) 2015 Cisco and/or its affiliates.
|
|
6
|
+
# Copyright (c) 2015-2016 Cisco and/or its affiliates.
|
|
7
7
|
#
|
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
9
|
# you may not use this file except in compliance with the License.
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
#
|
|
5
5
|
# December 2014, Glenn F. Matthews
|
|
6
6
|
#
|
|
7
|
-
# Copyright (c) 2014-
|
|
7
|
+
# Copyright (c) 2014-2016 Cisco and/or its affiliates.
|
|
8
8
|
#
|
|
9
9
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
10
|
# you may not use this file except in compliance with the License.
|
|
@@ -50,10 +50,6 @@ module Cisco
|
|
|
50
50
|
class Node
|
|
51
51
|
include Singleton
|
|
52
52
|
|
|
53
|
-
# BEGIN NODE API
|
|
54
|
-
# This is most of what a client/provider should need to code against.
|
|
55
|
-
# Actual implementations of these methods are later in this file.
|
|
56
|
-
|
|
57
53
|
# Convenience wrapper for show(command, :structured).
|
|
58
54
|
# Uses CommandReference to look up the given show command and key
|
|
59
55
|
# of interest, executes that command, and returns the value corresponding
|
|
@@ -69,46 +65,64 @@ module Cisco
|
|
|
69
65
|
# @return [String, Hash, Array]
|
|
70
66
|
# @example config_get("show_version", "system_image")
|
|
71
67
|
# @example config_get("ospf", "router_id",
|
|
72
|
-
#
|
|
68
|
+
# {name: "green", vrf: "one"})
|
|
73
69
|
def config_get(feature, name, *args)
|
|
74
70
|
fail 'lazy_connect specified but did not request connect' unless @cmd_ref
|
|
75
71
|
ref = @cmd_ref.lookup(feature, name)
|
|
76
72
|
|
|
73
|
+
return ref.default_value if ref.default_only?
|
|
74
|
+
|
|
77
75
|
begin
|
|
78
|
-
token =
|
|
79
|
-
rescue IndexError
|
|
80
|
-
# IndexError
|
|
76
|
+
token = ref.config_get_token(*args)
|
|
77
|
+
rescue IndexError
|
|
78
|
+
# IndexError: no entry for config_get_token
|
|
81
79
|
token = nil
|
|
82
80
|
end
|
|
83
|
-
if token.
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
token[0][0] == '/' &&
|
|
98
|
-
(token[0][-1] == '/' || token[0][-2..-1] == '/i')
|
|
99
|
-
|
|
100
|
-
token = token_str_to_regexp(token, args)
|
|
101
|
-
text = build_config_get(feature, ref, :ascii)
|
|
102
|
-
return Cisco.find_ascii(text, token[-1], *token[0..-2])
|
|
81
|
+
if token.nil?
|
|
82
|
+
# Just get the whole output
|
|
83
|
+
return massage(show(ref.config_get, :structured), ref)
|
|
84
|
+
elsif token[0].kind_of?(Regexp)
|
|
85
|
+
return massage(Cisco.find_ascii(show(ref.config_get, :ascii),
|
|
86
|
+
token[-1],
|
|
87
|
+
*token[0..-2]), ref)
|
|
88
|
+
else
|
|
89
|
+
return massage(
|
|
90
|
+
config_get_handle_structured(token,
|
|
91
|
+
show(ref.config_get, :structured)),
|
|
92
|
+
ref)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
103
95
|
|
|
96
|
+
# Attempt to massage the given value into the format specified by the
|
|
97
|
+
# given CmdRef object.
|
|
98
|
+
def massage(value, ref)
|
|
99
|
+
CiscoLogger.debug "Massaging '#{value}' (#{value.inspect})"
|
|
100
|
+
if value.is_a?(Array) && !ref.multiple
|
|
101
|
+
fail "Expected zero/one value but got '#{value}'" if value.length > 1
|
|
102
|
+
value = value[0]
|
|
103
|
+
end
|
|
104
|
+
if (value.nil? || value.empty?) && ref.default_value? && ref.auto_default
|
|
105
|
+
CiscoLogger.debug "Default: #{ref.default_value}"
|
|
106
|
+
return ref.default_value
|
|
107
|
+
end
|
|
108
|
+
return value unless ref.kind
|
|
109
|
+
case ref.kind
|
|
110
|
+
when :boolean
|
|
111
|
+
if value.nil? || value.empty?
|
|
112
|
+
value = false
|
|
113
|
+
elsif /^no / =~ value
|
|
114
|
+
value = false
|
|
104
115
|
else
|
|
105
|
-
|
|
106
|
-
return config_get_handle_structured(token, result)
|
|
116
|
+
value = true
|
|
107
117
|
end
|
|
108
|
-
|
|
109
|
-
|
|
118
|
+
when :int
|
|
119
|
+
value = value.to_i unless value.nil?
|
|
120
|
+
when :string
|
|
121
|
+
value = '' if value.nil?
|
|
122
|
+
value = value.to_s.strip
|
|
110
123
|
end
|
|
111
|
-
|
|
124
|
+
CiscoLogger.debug "Massaged to '#{value}'"
|
|
125
|
+
value
|
|
112
126
|
end
|
|
113
127
|
|
|
114
128
|
# Uses CommandReference to lookup the default value for a given
|
|
@@ -144,31 +158,7 @@ module Cisco
|
|
|
144
158
|
def config_set(feature, name, *args)
|
|
145
159
|
fail 'lazy_connect specified but did not request connect' unless @cmd_ref
|
|
146
160
|
ref = @cmd_ref.lookup(feature, name)
|
|
147
|
-
config_set
|
|
148
|
-
if config_set.is_a?(String)
|
|
149
|
-
param_count = config_set.scan(/%/).length
|
|
150
|
-
elsif config_set.is_a?(Array)
|
|
151
|
-
param_count = config_set.join(' ').scan(/%/).length
|
|
152
|
-
else
|
|
153
|
-
fail TypeError, '%{config_set.class} not supported for config_set'
|
|
154
|
-
end
|
|
155
|
-
unless args[0].is_a? Hash
|
|
156
|
-
if param_count != args.length
|
|
157
|
-
fail ArgumentError, 'Wrong number of params - expected: ' \
|
|
158
|
-
"#{param_count} actual: #{args.length}"
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
if config_set.is_a?(String)
|
|
162
|
-
config(sprintf(config_set, *args))
|
|
163
|
-
elsif config_set.is_a?(Array)
|
|
164
|
-
new_config_set = []
|
|
165
|
-
config_set.each do |line|
|
|
166
|
-
param_count = line.scan(/%/).length
|
|
167
|
-
new_config_set << sprintf(line, *args.first(param_count))
|
|
168
|
-
args = args[param_count..-1]
|
|
169
|
-
end
|
|
170
|
-
config(new_config_set)
|
|
171
|
-
end
|
|
161
|
+
config(ref.config_set(*args))
|
|
172
162
|
end
|
|
173
163
|
|
|
174
164
|
# Clear the cache of CLI output results.
|
|
@@ -209,7 +199,10 @@ module Cisco
|
|
|
209
199
|
# "hidden" API - used for UT but shouldn't be used elsewhere
|
|
210
200
|
def connect(*args)
|
|
211
201
|
@client = CiscoNxapi::NxapiClient.new(*args)
|
|
212
|
-
|
|
202
|
+
# Hard-code platform and cli for now
|
|
203
|
+
@cmd_ref = CommandReference.new(product: product_id,
|
|
204
|
+
platform: :nexus,
|
|
205
|
+
cli: true)
|
|
213
206
|
cache_flush
|
|
214
207
|
end
|
|
215
208
|
|
|
@@ -234,159 +227,6 @@ module Cisco
|
|
|
234
227
|
@client.cache_auto = enable
|
|
235
228
|
end
|
|
236
229
|
|
|
237
|
-
# Helper method for converting token strings to regexps. This helper
|
|
238
|
-
# facilitates non-standard regexp options like ignore-case.
|
|
239
|
-
# Example inputs:
|
|
240
|
-
# token = ["/%s/i", "/%s foo %s/", "/zzz/i"]
|
|
241
|
-
# args = ["LoopBack2", "no", "bar"]
|
|
242
|
-
# Expected outputs:
|
|
243
|
-
# [/LoopBack2/i, /no foo bar/, /zzz/i]
|
|
244
|
-
#
|
|
245
|
-
def token_str_to_regexp(token, args)
|
|
246
|
-
unless args[0].is_a? Hash
|
|
247
|
-
expected_args = token.join.scan(/%/).length
|
|
248
|
-
fail "Given #{args.length} args, but token #{token} requires " \
|
|
249
|
-
"#{expected_args}" unless args.length == expected_args
|
|
250
|
-
end
|
|
251
|
-
# replace all %s with *args
|
|
252
|
-
token.map! { |str| sprintf(str, *args.shift(str.scan(/%/).length)) }
|
|
253
|
-
# convert all to Regexp objects
|
|
254
|
-
token.map! do |str|
|
|
255
|
-
if str[-2..-1] == '/i'
|
|
256
|
-
Regexp.new(str[1..-3], Regexp::IGNORECASE)
|
|
257
|
-
else
|
|
258
|
-
Regexp.new(str[1..-2])
|
|
259
|
-
end
|
|
260
|
-
end
|
|
261
|
-
token
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
# Helper method to replace <> place holders in the config_get_token
|
|
265
|
-
# and config_get_token_append yaml entries.
|
|
266
|
-
#
|
|
267
|
-
# @param regexp [String][Array] regexp entry with <> placeholders
|
|
268
|
-
# @param values [Hash] Hash of named values to replace each <>
|
|
269
|
-
# @return [String]
|
|
270
|
-
def replace_token_ids(regexp, values)
|
|
271
|
-
final = replace_token_ids_string(regexp, values) if regexp.is_a?(String)
|
|
272
|
-
final = replace_token_ids_array(regexp, values) if regexp.is_a?(Array)
|
|
273
|
-
final
|
|
274
|
-
end
|
|
275
|
-
|
|
276
|
-
# @param regexp [String] regexp entry with <> placeholders
|
|
277
|
-
# @param values [Hash] Hash of named values to replace each <>
|
|
278
|
-
# @return [String]
|
|
279
|
-
def replace_token_ids_string(regexp, values)
|
|
280
|
-
replace = regexp.scan(/<(\S+)>/).flatten.map(&:to_sym)
|
|
281
|
-
replace.each do |item|
|
|
282
|
-
regexp = regexp.sub "<#{item}>",
|
|
283
|
-
values[item].to_s if values.key?(item)
|
|
284
|
-
end
|
|
285
|
-
# Only return lines that actually replaced ids or did not have any
|
|
286
|
-
# ids to replace. Implicit nil returned if not.
|
|
287
|
-
return regexp if /<\S+>/.match(regexp).nil?
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
# @param regexp [Array] regexp entry with <> placeholders
|
|
291
|
-
# @param values [Hash] Hash of named values to replace each <>
|
|
292
|
-
# @return [String]
|
|
293
|
-
def replace_token_ids_array(regexp, values)
|
|
294
|
-
final_regexp = []
|
|
295
|
-
regexp.each do |line|
|
|
296
|
-
final_regexp.push(replace_token_ids_string(line, values))
|
|
297
|
-
end
|
|
298
|
-
final_regexp
|
|
299
|
-
end
|
|
300
|
-
|
|
301
|
-
# Helper method to build a multi-line config_get_token if
|
|
302
|
-
# the feature, name contains a config_get_token_append entry.
|
|
303
|
-
#
|
|
304
|
-
# @param feature [String]
|
|
305
|
-
# @param ref [CommandReference::CmdRef]
|
|
306
|
-
# @return [String, Array]
|
|
307
|
-
def build_config_get_token(feature, ref, args)
|
|
308
|
-
fail 'lazy_connect specified but did not request connect' unless @cmd_ref
|
|
309
|
-
# Why clone token? A bug in some ruby versions caused token to convert
|
|
310
|
-
# to type Regexp unexpectedly. The clone hard copy resolved it.
|
|
311
|
-
|
|
312
|
-
# If the options are presented as type Hash process as
|
|
313
|
-
# key-value replacement pairs
|
|
314
|
-
return ref.config_get_token.clone unless args[0].is_a?(Hash)
|
|
315
|
-
options = args[0]
|
|
316
|
-
token = []
|
|
317
|
-
# Use _template yaml entry if config_get_token_append
|
|
318
|
-
if ref.to_s[/config_get_token_append/]
|
|
319
|
-
# Get yaml feature template:
|
|
320
|
-
template = @cmd_ref.lookup(feature, '_template')
|
|
321
|
-
# Process config_get_token: from template:
|
|
322
|
-
token.push(replace_token_ids(template.config_get_token, options))
|
|
323
|
-
# Process config_get_token_append sequence: from template:
|
|
324
|
-
template.config_get_token_append.each do |line|
|
|
325
|
-
token.push(replace_token_ids(line, options))
|
|
326
|
-
end
|
|
327
|
-
# Add feature->property config_get_token append line
|
|
328
|
-
token.push(ref.config_get_token_append)
|
|
329
|
-
else
|
|
330
|
-
token.push(replace_token_ids(ref.config_get_token, options))
|
|
331
|
-
end
|
|
332
|
-
token.flatten!
|
|
333
|
-
token.compact!
|
|
334
|
-
token
|
|
335
|
-
end
|
|
336
|
-
|
|
337
|
-
# Helper method to use the feature, name config_get
|
|
338
|
-
# if present else use feature, "template" config_get
|
|
339
|
-
#
|
|
340
|
-
# @param feature [String]
|
|
341
|
-
# @param ref [CommandReference::CmdRef]
|
|
342
|
-
# @param type [Symbol]
|
|
343
|
-
# @return [String, Array]
|
|
344
|
-
def build_config_get(feature, ref, type)
|
|
345
|
-
fail 'lazy_connect specified but did not request connect' unless @cmd_ref
|
|
346
|
-
# Use feature name config_get string if present
|
|
347
|
-
# else use feature template: config_get
|
|
348
|
-
if ref.hash.key?('config_get')
|
|
349
|
-
return show(ref.config_get, type)
|
|
350
|
-
else
|
|
351
|
-
template = @cmd_ref.lookup(feature, '_template')
|
|
352
|
-
return show(template.config_get, type)
|
|
353
|
-
end
|
|
354
|
-
end
|
|
355
|
-
|
|
356
|
-
# Helper method to build a multi-line config_set if
|
|
357
|
-
# the feature, name contains a config_get_set_append
|
|
358
|
-
# yaml entry.
|
|
359
|
-
#
|
|
360
|
-
# @param feature [String]
|
|
361
|
-
# @param ref [CommandReference::CmdRef]
|
|
362
|
-
# @return [String, Array]
|
|
363
|
-
def build_config_set(feature, ref, args)
|
|
364
|
-
fail 'lazy_connect specified but did not request connect' unless @cmd_ref
|
|
365
|
-
# If the options are presented as type Hash process as
|
|
366
|
-
# key-value replacement pairs
|
|
367
|
-
return ref.config_set unless args[0].is_a?(Hash)
|
|
368
|
-
options = args[0]
|
|
369
|
-
config_set = []
|
|
370
|
-
# Use _template yaml entry if config_set_append
|
|
371
|
-
if ref.to_s[/config_set_append/]
|
|
372
|
-
# Get yaml feature template:
|
|
373
|
-
template = @cmd_ref.lookup(feature, '_template')
|
|
374
|
-
# Process config_set: from template:
|
|
375
|
-
config_set.push(replace_token_ids(template.config_set, options))
|
|
376
|
-
# Process config_set_append sequence: from template:
|
|
377
|
-
template.config_set_append.each do |line|
|
|
378
|
-
config_set.push(replace_token_ids(line, options))
|
|
379
|
-
end
|
|
380
|
-
# Add feature->property config_set append line
|
|
381
|
-
config_set.push(replace_token_ids(ref.config_set_append, options))
|
|
382
|
-
else
|
|
383
|
-
config_set.push(replace_token_ids(ref.config_set, options))
|
|
384
|
-
end
|
|
385
|
-
config_set.flatten!
|
|
386
|
-
config_set.compact!
|
|
387
|
-
config_set
|
|
388
|
-
end
|
|
389
|
-
|
|
390
230
|
# Helper method for config_get().
|
|
391
231
|
# @param token [Array, Hash] lookup sequence
|
|
392
232
|
# @param result [Array, Hash] structured output from node
|
|
@@ -482,12 +322,7 @@ module Cisco
|
|
|
482
322
|
|
|
483
323
|
# @return [String] such as "example.com"
|
|
484
324
|
def domain_name
|
|
485
|
-
|
|
486
|
-
if result.nil?
|
|
487
|
-
return ''
|
|
488
|
-
else
|
|
489
|
-
return result[0]
|
|
490
|
-
end
|
|
325
|
+
config_get('dnsclient', 'domain_name')
|
|
491
326
|
end
|
|
492
327
|
|
|
493
328
|
# @return [Integer] System uptime, in seconds
|
|
@@ -495,7 +330,6 @@ module Cisco
|
|
|
495
330
|
cache_flush
|
|
496
331
|
t = config_get('show_system', 'uptime')
|
|
497
332
|
fail 'failed to retrieve system uptime' if t.nil?
|
|
498
|
-
t = t.shift
|
|
499
333
|
# time units: t = ["0", "23", "15", "49"]
|
|
500
334
|
t.map!(&:to_i)
|
|
501
335
|
d, h, m, s = t
|
|
@@ -504,12 +338,7 @@ module Cisco
|
|
|
504
338
|
|
|
505
339
|
# @return [String] timestamp of last reset time
|
|
506
340
|
def last_reset_time
|
|
507
|
-
|
|
508
|
-
return '' if output.nil?
|
|
509
|
-
# NX-OS may provide leading/trailing whitespace:
|
|
510
|
-
# " Sat Oct 25 00:39:25 2014\n"
|
|
511
|
-
# so be sure to strip() it down to the actual string.
|
|
512
|
-
output.strip
|
|
341
|
+
config_get('show_version', 'last_reset_time')
|
|
513
342
|
end
|
|
514
343
|
|
|
515
344
|
# @return [String] such as "Reset Requested by CLI command reload"
|
|
@@ -537,29 +366,6 @@ module Cisco
|
|
|
537
366
|
end
|
|
538
367
|
end
|
|
539
368
|
|
|
540
|
-
# Convenience wrapper for find_ascii. Operates under the assumption
|
|
541
|
-
# that there will be zero or one matches for the given query
|
|
542
|
-
# and returns the match string (or "") rather than an array.
|
|
543
|
-
#
|
|
544
|
-
# @raise [RuntimeError] if more than one match is found.
|
|
545
|
-
#
|
|
546
|
-
# @param body [String] The body of text to search
|
|
547
|
-
# @param regex_query [Regex] The regular expression to match
|
|
548
|
-
# @param parents [*Regex] zero or more regular expressions defining
|
|
549
|
-
# the parent configs to filter by.
|
|
550
|
-
# @return [String] the matching (sub)string or "" if no match.
|
|
551
|
-
#
|
|
552
|
-
# @example Get the domain name if any
|
|
553
|
-
# domain_name = find_one_ascii(running_cfg, "ip domain-name (.*)")
|
|
554
|
-
# => 'example.com'
|
|
555
|
-
def find_one_ascii(body, regex_query, *parent_cfg)
|
|
556
|
-
matches = find_ascii(body, regex_query, *parent_cfg)
|
|
557
|
-
return '' if matches.nil?
|
|
558
|
-
fail RuntimeError if matches.length > 1
|
|
559
|
-
matches[0]
|
|
560
|
-
end
|
|
561
|
-
module_function :find_one_ascii
|
|
562
|
-
|
|
563
369
|
# Method for working with hierarchical show command output such as
|
|
564
370
|
# "show running-config". Searches the given multi-line string
|
|
565
371
|
# for all matches to the given regex_query. If parents is provided,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# September 2015, Glenn F. Matthews
|
|
2
2
|
#
|
|
3
|
-
# Copyright (c) 2014-
|
|
3
|
+
# Copyright (c) 2014-2016 Cisco and/or its affiliates.
|
|
4
4
|
#
|
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
6
|
# you may not use this file except in compliance with the License.
|
|
@@ -57,5 +57,9 @@ module Cisco
|
|
|
57
57
|
def config_set(*args)
|
|
58
58
|
node.config_set(*args)
|
|
59
59
|
end
|
|
60
|
+
|
|
61
|
+
def show(*args)
|
|
62
|
+
node.show(*args)
|
|
63
|
+
end
|
|
60
64
|
end
|
|
61
65
|
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# Jonathan Tripathy et al., September 2015
|
|
4
4
|
#
|
|
5
|
-
# Copyright (c) 2014-
|
|
5
|
+
# Copyright (c) 2014-2016 Cisco and/or its affiliates.
|
|
6
6
|
#
|
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
8
|
# you may not use this file except in compliance with the License.
|
|
@@ -43,7 +43,7 @@ module Cisco
|
|
|
43
43
|
|
|
44
44
|
def source_interface
|
|
45
45
|
source_interface = config_get('ntp_config', 'source_interface')
|
|
46
|
-
source_interface = source_interface
|
|
46
|
+
source_interface = source_interface.downcase \
|
|
47
47
|
unless source_interface.nil?
|
|
48
48
|
source_interface
|
|
49
49
|
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
#
|
|
3
3
|
# Jonathan Tripathy et al., September 2015
|
|
4
4
|
#
|
|
5
|
-
# Copyright (c) 2014-
|
|
5
|
+
# Copyright (c) 2014-2016 Cisco and/or its affiliates.
|
|
6
6
|
#
|
|
7
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
8
|
# you may not use this file except in compliance with the License.
|
|
@@ -25,9 +25,19 @@ module Cisco
|
|
|
25
25
|
def initialize(ntpserver_id, prefer, instantiate=true)
|
|
26
26
|
@ntpserver_id = ntpserver_id.to_s
|
|
27
27
|
@ntpserver_prefer = prefer
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
|
|
29
|
+
unless @ntpserver_id =~ /^[a-zA-Z0-9\.\:]*$/
|
|
30
|
+
fail ArgumentError,
|
|
31
|
+
'Invalid value (IPv4/IPv6 address contains invalid characters)'
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
begin
|
|
35
|
+
IPAddr.new(@ntpserver_id)
|
|
36
|
+
rescue
|
|
37
|
+
raise ArgumentError,
|
|
38
|
+
'Invalid value (Name is not a valid single IPv4/IPv6 address)'
|
|
30
39
|
end
|
|
40
|
+
|
|
31
41
|
unless @ntpserver_prefer == true ||
|
|
32
42
|
@ntpserver_prefer == false ||
|
|
33
43
|
@ntpserver_prefer.nil?
|
|
@@ -39,10 +49,9 @@ module Cisco
|
|
|
39
49
|
def self.ntpservers
|
|
40
50
|
hash = {}
|
|
41
51
|
ntpservers_list = config_get('ntp_server', 'server')
|
|
42
|
-
return hash if ntpservers_list.
|
|
52
|
+
return hash if ntpservers_list.empty?
|
|
43
53
|
|
|
44
54
|
preferred_servers = config_get('ntp_server', 'prefer')
|
|
45
|
-
preferred_servers = [] unless preferred_servers
|
|
46
55
|
|
|
47
56
|
ntpservers_list.each do |id|
|
|
48
57
|
hash[id] = NtpServer.new(id, preferred_servers.include?(id), false)
|