cisco_node_utils 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +60 -1
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/cisco_node_utils.gemspec +1 -1
- data/docs/README-develop-node-utils-APIs.md +2 -0
- data/docs/README-maintainers.md +45 -80
- data/lib/cisco_node_utils/ace.rb +24 -43
- data/lib/cisco_node_utils/bfd_global.rb +1 -0
- data/lib/cisco_node_utils/bgp_af_aggr_addr.rb +207 -0
- data/lib/cisco_node_utils/bgp_neighbor.rb +8 -5
- data/lib/cisco_node_utils/bgp_neighbor_af.rb +8 -6
- data/lib/cisco_node_utils/cisco_cmn_utils.rb +40 -0
- data/lib/cisco_node_utils/cmd_ref/bfd_global.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/bgp.yaml +8 -4
- data/lib/cisco_node_utils/cmd_ref/bgp_af_aa.yaml +38 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +9 -4
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +8 -3
- data/lib/cisco_node_utils/cmd_ref/dhcp_relay_global.yaml +2 -1
- data/lib/cisco_node_utils/cmd_ref/feature.yaml +5 -0
- data/lib/cisco_node_utils/cmd_ref/interface.yaml +8 -0
- data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +7 -3
- data/lib/cisco_node_utils/cmd_ref/inventory.yaml +3 -3
- data/lib/cisco_node_utils/cmd_ref/ntp_auth_key.yaml +10 -0
- data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +13 -0
- data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +10 -2
- data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +6 -1
- data/lib/cisco_node_utils/cmd_ref/route_map.yaml +8 -0
- data/lib/cisco_node_utils/cmd_ref/span_session.yaml +65 -0
- data/lib/cisco_node_utils/cmd_ref/stp_global.yaml +2 -1
- data/lib/cisco_node_utils/cmd_ref/vpc.yaml +22 -3
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +2 -1
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +6 -3
- data/lib/cisco_node_utils/cmd_ref/yum.yaml +48 -4
- data/lib/cisco_node_utils/command_reference.rb +5 -2
- data/lib/cisco_node_utils/feature.rb +14 -1
- data/lib/cisco_node_utils/interface.rb +13 -0
- data/lib/cisco_node_utils/interface_channel_group.rb +33 -25
- data/lib/cisco_node_utils/itd_device_group.rb +17 -37
- data/lib/cisco_node_utils/itd_service.rb +9 -32
- data/lib/cisco_node_utils/node.rb +12 -4
- data/lib/cisco_node_utils/ntp_auth_key.rb +67 -0
- data/lib/cisco_node_utils/ntp_config.rb +19 -1
- data/lib/cisco_node_utils/ntp_server.rb +28 -27
- data/lib/cisco_node_utils/route_map.rb +33 -51
- data/lib/cisco_node_utils/snmpuser.rb +2 -2
- data/lib/cisco_node_utils/span_session.rb +149 -0
- data/lib/cisco_node_utils/upgrade.rb +21 -17
- data/lib/cisco_node_utils/version.rb +2 -2
- data/lib/cisco_node_utils/vlan.rb +1 -1
- data/lib/cisco_node_utils/vpc.rb +40 -0
- data/lib/cisco_node_utils/yum.rb +136 -13
- data/spec/schema.yaml +2 -0
- data/tests/ciscotest.rb +36 -0
- data/tests/test_ace.rb +6 -0
- data/tests/test_bfd_global.rb +1 -7
- data/tests/test_bgp_af.rb +2 -2
- data/tests/test_bgp_af_aa.rb +108 -0
- data/tests/test_bgp_neighbor.rb +2 -1
- data/tests/test_bgp_neighbor_af.rb +6 -6
- data/tests/test_dhcp_relay_global.rb +1 -0
- data/tests/test_interface.rb +18 -2
- data/tests/test_interface_channel_group.rb +47 -0
- data/tests/test_interface_svi.rb +1 -1
- data/tests/test_ntp_auth_key.rb +77 -0
- data/tests/test_ntp_config.rb +51 -4
- data/tests/test_ntp_server.rb +69 -9
- data/tests/test_overlay_global.rb +1 -0
- data/tests/test_route_map.rb +13 -24
- data/tests/test_router_bgp.rb +14 -9
- data/tests/test_span_session.rb +155 -0
- data/tests/test_stp_global.rb +1 -0
- data/tests/test_upgrade.rb +2 -3
- data/tests/test_vlan.rb +24 -3
- data/tests/test_vlan_private.rb +1 -1
- data/tests/test_vpc.rb +42 -17
- data/tests/test_vxlan_vtep.rb +1 -0
- data/tests/test_vxlan_vtep_vni.rb +5 -1
- data/tests/test_yum.rb +7 -30
- data/tests/yum_package.yaml +20 -0
- metadata +13 -3
@@ -67,30 +67,6 @@ module Cisco
|
|
67
67
|
@set_args = @get_args.merge!(hash) unless hash.empty?
|
68
68
|
end
|
69
69
|
|
70
|
-
# extract value of property from probe
|
71
|
-
def extract_value(prop, prefix=nil)
|
72
|
-
prefix = prop if prefix.nil?
|
73
|
-
probe_match = probe_get
|
74
|
-
|
75
|
-
# matching probe not found
|
76
|
-
return nil if probe_match.nil? # no matching probe found
|
77
|
-
|
78
|
-
# property not defined for matching probe
|
79
|
-
return nil unless probe_match.names.include?(prop)
|
80
|
-
|
81
|
-
# extract and return value that follows prefix + <space>
|
82
|
-
regexp = Regexp.new("#{Regexp.escape(prefix)} (?<extracted>.*)")
|
83
|
-
value_match = regexp.match(probe_match[prop])
|
84
|
-
return nil if value_match.nil?
|
85
|
-
value_match[:extracted]
|
86
|
-
end
|
87
|
-
|
88
|
-
# prepend property name prefix/keyword to value
|
89
|
-
def attach_prefix(val, prop, prefix=nil)
|
90
|
-
prefix = prop.to_s if prefix.nil?
|
91
|
-
@set_args[prop] = val.to_s.empty? ? val : "#{prefix} #{val}"
|
92
|
-
end
|
93
|
-
|
94
70
|
# probe configuration is all done in a single line (like below)
|
95
71
|
# probe tcp port 32 frequency 10 timeout 5 retry-down-count 3 ...
|
96
72
|
# probe udp port 23 frequency 10 timeout 5 retry-down-count 3 ...
|
@@ -113,7 +89,7 @@ module Cisco
|
|
113
89
|
end
|
114
90
|
|
115
91
|
def probe_control
|
116
|
-
val = extract_value('control')
|
92
|
+
val = Utils.extract_value(probe_get, 'control')
|
117
93
|
return default_probe_control if val.nil?
|
118
94
|
val == 'enable' ? true : default_probe_control
|
119
95
|
end
|
@@ -131,21 +107,21 @@ module Cisco
|
|
131
107
|
end
|
132
108
|
|
133
109
|
def probe_dns_host
|
134
|
-
extract_value('dns_host', 'host')
|
110
|
+
Utils.extract_value(probe_get, 'dns_host', 'host')
|
135
111
|
end
|
136
112
|
|
137
113
|
def probe_dns_host=(dns_host)
|
138
|
-
attach_prefix(dns_host, :dns_host, 'host')
|
114
|
+
@set_args[:dns_host] = Utils.attach_prefix(dns_host, :dns_host, 'host')
|
139
115
|
end
|
140
116
|
|
141
117
|
def probe_frequency
|
142
|
-
val = extract_value('frequency')
|
118
|
+
val = Utils.extract_value(probe_get, 'frequency')
|
143
119
|
return default_probe_frequency if val.nil?
|
144
120
|
val.to_i
|
145
121
|
end
|
146
122
|
|
147
123
|
def probe_frequency=(frequency)
|
148
|
-
attach_prefix(frequency, :frequency)
|
124
|
+
@set_args[:frequency] = Utils.attach_prefix(frequency, :frequency)
|
149
125
|
end
|
150
126
|
|
151
127
|
def default_probe_frequency
|
@@ -153,22 +129,24 @@ module Cisco
|
|
153
129
|
end
|
154
130
|
|
155
131
|
def probe_port
|
156
|
-
val = extract_value('port')
|
132
|
+
val = Utils.extract_value(probe_get, 'port')
|
157
133
|
val.to_i unless val.nil?
|
158
134
|
end
|
159
135
|
|
160
136
|
def probe_port=(port)
|
161
|
-
attach_prefix(port, :port)
|
137
|
+
@set_args[:port] = Utils.attach_prefix(port, :port)
|
162
138
|
end
|
163
139
|
|
164
140
|
def probe_retry_down
|
165
|
-
val = extract_value('retry_down', 'retry-down-count')
|
141
|
+
val = Utils.extract_value(probe_get, 'retry_down', 'retry-down-count')
|
166
142
|
return default_probe_retry_down if val.nil?
|
167
143
|
val.to_i
|
168
144
|
end
|
169
145
|
|
170
146
|
def probe_retry_down=(rdc)
|
171
|
-
attach_prefix(rdc,
|
147
|
+
@set_args[:retry_down_count] = Utils.attach_prefix(rdc,
|
148
|
+
:retry_down_count,
|
149
|
+
'retry-down-count')
|
172
150
|
end
|
173
151
|
|
174
152
|
def default_probe_retry_down
|
@@ -176,13 +154,15 @@ module Cisco
|
|
176
154
|
end
|
177
155
|
|
178
156
|
def probe_retry_up
|
179
|
-
val = extract_value('retry_up', 'retry-up-count')
|
157
|
+
val = Utils.extract_value(probe_get, 'retry_up', 'retry-up-count')
|
180
158
|
return default_probe_retry_up if val.nil?
|
181
159
|
val.to_i
|
182
160
|
end
|
183
161
|
|
184
162
|
def probe_retry_up=(ruc)
|
185
|
-
attach_prefix(ruc,
|
163
|
+
@set_args[:retry_up_count] = Utils.attach_prefix(ruc,
|
164
|
+
:retry_up_count,
|
165
|
+
'retry-up-count')
|
186
166
|
end
|
187
167
|
|
188
168
|
def default_probe_retry_up
|
@@ -190,13 +170,13 @@ module Cisco
|
|
190
170
|
end
|
191
171
|
|
192
172
|
def probe_timeout
|
193
|
-
val = extract_value('timeout')
|
173
|
+
val = Utils.extract_value(probe_get, 'timeout')
|
194
174
|
return default_probe_timeout if val.nil?
|
195
175
|
val.to_i
|
196
176
|
end
|
197
177
|
|
198
178
|
def probe_timeout=(timeout)
|
199
|
-
attach_prefix(timeout, :timeout)
|
179
|
+
@set_args[:timeout] = Utils.attach_prefix(timeout, :timeout)
|
200
180
|
end
|
201
181
|
|
202
182
|
def default_probe_timeout
|
@@ -80,30 +80,6 @@ module Cisco
|
|
80
80
|
@set_args = @get_args.merge!(hash) unless hash.empty?
|
81
81
|
end
|
82
82
|
|
83
|
-
# extract value of property from load-balance
|
84
|
-
def extract_value(prop, prefix=nil)
|
85
|
-
prefix = prop if prefix.nil?
|
86
|
-
lb_match = lb_get
|
87
|
-
|
88
|
-
# matching lb not found
|
89
|
-
return nil if lb_match.nil? # no matching lb found
|
90
|
-
|
91
|
-
# property not defined for matching lb
|
92
|
-
return nil unless lb_match.names.include?(prop)
|
93
|
-
|
94
|
-
# extract and return value that follows prefix + <space>
|
95
|
-
regexp = Regexp.new("#{Regexp.escape(prefix)} (?<extracted>.*)")
|
96
|
-
value_match = regexp.match(lb_match[prop])
|
97
|
-
return nil if value_match.nil?
|
98
|
-
value_match[:extracted]
|
99
|
-
end
|
100
|
-
|
101
|
-
# prepend property name prefix/keyword to value
|
102
|
-
def attach_prefix(val, prop, prefix=nil)
|
103
|
-
prefix = prop.to_s if prefix.nil?
|
104
|
-
@set_args[prop] = val.to_s.empty? ? val : "#{prefix} #{val}"
|
105
|
-
end
|
106
|
-
|
107
83
|
def access_list
|
108
84
|
config_get('itd_service', 'access_list', @get_args)
|
109
85
|
end
|
@@ -270,13 +246,13 @@ module Cisco
|
|
270
246
|
end
|
271
247
|
|
272
248
|
def load_bal_buckets
|
273
|
-
val = extract_value('buckets')
|
249
|
+
val = Utils.extract_value(lb_get, 'buckets')
|
274
250
|
return default_load_bal_buckets if val.nil?
|
275
251
|
val.to_i
|
276
252
|
end
|
277
253
|
|
278
254
|
def load_bal_buckets=(buckets)
|
279
|
-
attach_prefix(buckets, :buckets)
|
255
|
+
@set_args[:buckets] = Utils.attach_prefix(buckets, :buckets)
|
280
256
|
end
|
281
257
|
|
282
258
|
def default_load_bal_buckets
|
@@ -284,13 +260,13 @@ module Cisco
|
|
284
260
|
end
|
285
261
|
|
286
262
|
def load_bal_mask_pos
|
287
|
-
val = extract_value('mask', 'mask-position')
|
263
|
+
val = Utils.extract_value(lb_get, 'mask', 'mask-position')
|
288
264
|
return default_load_bal_mask_pos if val.nil?
|
289
265
|
val.to_i
|
290
266
|
end
|
291
267
|
|
292
268
|
def load_bal_mask_pos=(mask)
|
293
|
-
attach_prefix(mask, :mask, 'mask-position')
|
269
|
+
@set_args[:mask] = Utils.attach_prefix(mask, :mask, 'mask-position')
|
294
270
|
end
|
295
271
|
|
296
272
|
def default_load_bal_mask_pos
|
@@ -313,13 +289,14 @@ module Cisco
|
|
313
289
|
end
|
314
290
|
|
315
291
|
def load_bal_method_bundle_select
|
316
|
-
val = extract_value('bundle_select', 'method')
|
292
|
+
val = Utils.extract_value(lb_get, 'bundle_select', 'method')
|
317
293
|
return default_load_bal_method_bundle_select if val.nil?
|
318
294
|
val
|
319
295
|
end
|
320
296
|
|
321
297
|
def load_bal_method_bundle_select=(bs)
|
322
|
-
|
298
|
+
@set_args[:bundle_select] =
|
299
|
+
Utils.attach_prefix(bs, :bundle_select, 'method')
|
323
300
|
end
|
324
301
|
|
325
302
|
def default_load_bal_method_bundle_select
|
@@ -342,13 +319,13 @@ module Cisco
|
|
342
319
|
end
|
343
320
|
|
344
321
|
def load_bal_method_start_port
|
345
|
-
val = extract_value('start_port', 'range')
|
322
|
+
val = Utils.extract_value(lb_get, 'start_port', 'range')
|
346
323
|
return default_load_bal_method_start_port if val.nil?
|
347
324
|
val.to_i
|
348
325
|
end
|
349
326
|
|
350
327
|
def load_bal_method_start_port=(start)
|
351
|
-
attach_prefix(start, :start_port, 'range')
|
328
|
+
@set_args[:start_port] = Utils.attach_prefix(start, :start_port, 'range')
|
352
329
|
end
|
353
330
|
|
354
331
|
def default_load_bal_method_start_port
|
@@ -4,7 +4,7 @@
|
|
4
4
|
#
|
5
5
|
# December 2014, Glenn F. Matthews
|
6
6
|
#
|
7
|
-
# Copyright (c) 2014-
|
7
|
+
# Copyright (c) 2014-2017 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.
|
@@ -107,18 +107,22 @@ module Cisco
|
|
107
107
|
return value unless ref.hash['drill_down']
|
108
108
|
|
109
109
|
row_key = ref.hash['get_value'][0][/^\S+/]
|
110
|
-
|
110
|
+
|
111
|
+
# Escape special characters if any in row_index and add
|
112
|
+
# anchors for exact match.
|
113
|
+
row_index = Regexp.escape(ref.hash['get_value'][0][/\S+$/])
|
114
|
+
row_index = "^#{row_index}$"
|
115
|
+
|
111
116
|
data_key = ref.hash['get_value'][1]
|
112
117
|
regexp_filter = nil
|
113
118
|
if ref.hash['get_value'][2]
|
114
119
|
regexp_filter = Regexp.new ref.hash['get_value'][2][1..-2]
|
115
120
|
end
|
116
|
-
|
117
121
|
# Get the value using the row_key, row_index and data_key
|
118
122
|
value = value.is_a?(Hash) ? [value] : value
|
119
123
|
data = nil
|
120
124
|
value.each do |row|
|
121
|
-
data = row[data_key] if row[row_key].to_s
|
125
|
+
data = row[data_key] if row[row_key].to_s[/#{row_index}/]
|
122
126
|
end
|
123
127
|
return value if data.nil?
|
124
128
|
if regexp_filter
|
@@ -431,5 +435,9 @@ module Cisco
|
|
431
435
|
def system
|
432
436
|
config_get('show_version', 'system_image')
|
433
437
|
end
|
438
|
+
|
439
|
+
def os_version_get(feature, property)
|
440
|
+
@cmd_ref.lookup(feature, property).os_version
|
441
|
+
end
|
434
442
|
end
|
435
443
|
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'
|
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
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# Jonathan Tripathy et al., September 2015
|
4
4
|
#
|
5
|
-
# Copyright (c) 2014-
|
5
|
+
# Copyright (c) 2014-2017 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.
|
@@ -41,6 +41,24 @@ module Cisco
|
|
41
41
|
name == other.name
|
42
42
|
end
|
43
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
|
+
|
44
62
|
def source_interface
|
45
63
|
source_interface = config_get('ntp_config', 'source_interface')
|
46
64
|
source_interface = source_interface.downcase \
|
@@ -2,7 +2,7 @@
|
|
2
2
|
#
|
3
3
|
# Jonathan Tripathy et al., September 2015
|
4
4
|
#
|
5
|
-
# Copyright (c) 2014-
|
5
|
+
# Copyright (c) 2014-2017 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.
|
@@ -18,43 +18,43 @@
|
|
18
18
|
|
19
19
|
require_relative 'node'
|
20
20
|
require_relative 'interface'
|
21
|
+
require 'resolv'
|
21
22
|
|
22
23
|
module Cisco
|
23
24
|
# NtpServer - node utility class for NTP Server configuration management
|
24
25
|
class NtpServer < NodeUtil
|
25
|
-
|
26
|
-
@ntpserver_id = ntpserver_id.to_s
|
27
|
-
@ntpserver_prefer = prefer
|
26
|
+
attr_reader :key, :maxpoll, :minpoll, :prefer, :vrf
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
28
|
+
def initialize(opts, instantiate=true)
|
29
|
+
@ntpserver_id = opts['name']
|
30
|
+
@key = opts['key']
|
31
|
+
@minpoll = opts['minpoll']
|
32
|
+
@maxpoll = opts['maxpoll']
|
33
|
+
@prefer = opts['prefer'].nil? ? false : true
|
34
|
+
@vrf = opts['vrf'].nil? ? 'default' : opts['vrf']
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
raise ArgumentError,
|
38
|
-
'Invalid value (Name is not a valid single IPv4/IPv6 address)'
|
39
|
-
end
|
36
|
+
hostname_regex = /^(?=.{1,255}$)[0-9A-Za-z]
|
37
|
+
(?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?
|
38
|
+
(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/x
|
40
39
|
|
41
|
-
unless @
|
42
|
-
@
|
43
|
-
|
44
|
-
|
40
|
+
unless @ntpserver_id =~ Resolv::AddressRegex ||
|
41
|
+
@ntpserver_id =~ hostname_regex
|
42
|
+
fail ArgumentError,
|
43
|
+
"Invalid value '#{@ntpserver_id}' \
|
44
|
+
(Must be valid IPv4/IPv6 address or hostname)"
|
45
45
|
end
|
46
|
+
|
46
47
|
create if instantiate
|
47
48
|
end
|
48
49
|
|
49
50
|
def self.ntpservers
|
51
|
+
keys = %w(name prefer vrf key minpoll maxpoll)
|
50
52
|
hash = {}
|
51
53
|
ntpservers_list = config_get('ntp_server', 'server')
|
52
54
|
return hash if ntpservers_list.empty?
|
53
55
|
|
54
|
-
preferred_servers = config_get('ntp_server', 'prefer')
|
55
|
-
|
56
56
|
ntpservers_list.each do |id|
|
57
|
-
hash[id] = NtpServer.new(
|
57
|
+
hash[id[0]] = NtpServer.new(Hash[keys.zip(id)], false)
|
58
58
|
end
|
59
59
|
|
60
60
|
hash
|
@@ -66,20 +66,21 @@ module Cisco
|
|
66
66
|
|
67
67
|
def create
|
68
68
|
config_set('ntp_server', 'server', state: '', ip: @ntpserver_id,
|
69
|
-
prefer: @
|
69
|
+
prefer: (['true', true].include? @prefer) ? 'prefer' : '',
|
70
|
+
vrf: @vrf ? "use-vrf #{@vrf}" : '',
|
71
|
+
key: @key ? "key #{@key}" : '',
|
72
|
+
minpoll: @minpoll ? "minpoll #{@minpoll}" : '',
|
73
|
+
maxpoll: @maxpoll ? "maxpoll #{@maxpoll}" : '')
|
70
74
|
end
|
71
75
|
|
72
76
|
def destroy
|
73
77
|
config_set('ntp_server', 'server',
|
74
|
-
state: 'no', ip: @ntpserver_id, prefer: ''
|
78
|
+
state: 'no', ip: @ntpserver_id, prefer: '', vrf: '',
|
79
|
+
key: '', minpoll: '', maxpoll: '')
|
75
80
|
end
|
76
81
|
|
77
82
|
def name
|
78
83
|
@ntpserver_id
|
79
84
|
end
|
80
|
-
|
81
|
-
def prefer
|
82
|
-
@ntpserver_prefer
|
83
|
-
end
|
84
85
|
end # class
|
85
86
|
end # module
|