cisco_node_utils 1.4.1 → 1.5.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/CHANGELOG.md +30 -0
- data/README.md +8 -7
- data/docs/README-maintainers.md +0 -1
- data/lib/cisco_node_utils/aaa_authentication_login_service.rb +2 -2
- data/lib/cisco_node_utils/bgp.rb +2 -2
- data/lib/cisco_node_utils/cisco_cmn_utils.rb +16 -0
- data/lib/cisco_node_utils/client/utils.rb +7 -1
- data/lib/cisco_node_utils/cmd_ref/DEPRECATED.yaml +12 -12
- data/lib/cisco_node_utils/cmd_ref/README_YAML.md +35 -7
- data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/bfd_global.yaml +4 -4
- data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/bridge_domain.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/bridge_domain_vni.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/dhcp_relay_global.yaml +5 -5
- data/lib/cisco_node_utils/cmd_ref/encapsulation.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +5 -5
- data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/feature.yaml +8 -3
- data/lib/cisco_node_utils/cmd_ref/hsrp_global.yaml +25 -0
- data/lib/cisco_node_utils/cmd_ref/interface.yaml +65 -14
- data/lib/cisco_node_utils/cmd_ref/interface_hsrp_group.yaml +117 -0
- data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/inventory.yaml +4 -8
- data/lib/cisco_node_utils/cmd_ref/itd_device_group.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/itd_service.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/ospf.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/pim.yaml +6 -0
- data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +9 -9
- data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/stp_global.yaml +8 -8
- data/lib/cisco_node_utils/cmd_ref/vdc.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/vlan.yaml +16 -8
- data/lib/cisco_node_utils/cmd_ref/vpc.yaml +11 -11
- data/lib/cisco_node_utils/cmd_ref/vrf.yaml +2 -1
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +1 -1
- data/lib/cisco_node_utils/command_reference.rb +8 -1
- data/lib/cisco_node_utils/domain_name.rb +17 -2
- data/lib/cisco_node_utils/feature.rb +14 -0
- data/lib/cisco_node_utils/hsrp_global.rb +97 -0
- data/lib/cisco_node_utils/interface.rb +146 -0
- data/lib/cisco_node_utils/interface_hsrp_group.rb +544 -0
- data/lib/cisco_node_utils/node.rb +93 -4
- data/lib/cisco_node_utils/pim.rb +17 -0
- data/lib/cisco_node_utils/portchannel_global.rb +2 -2
- data/lib/cisco_node_utils/version.rb +1 -1
- data/lib/cisco_node_utils/vlan.rb +2 -5
- data/lib/cisco_node_utils/yum.rb +11 -6
- data/spec/schema.yaml +3 -3
- data/tests/ciscotest.rb +25 -4
- data/tests/cmd_config.yaml +0 -2
- data/tests/test_bgp_af.rb +13 -2
- data/tests/test_feature.rb +5 -0
- data/tests/test_hsrp_global.rb +79 -0
- data/tests/test_interface.rb +23 -0
- data/tests/test_interface_hsrp.rb +134 -0
- data/tests/test_interface_hsrp_group.rb +582 -0
- data/tests/test_node_ext.rb +7 -1
- data/tests/test_pim.rb +27 -3
- data/tests/test_platform.rb +1 -1
- data/tests/test_radius_global.rb +4 -5
- data/tests/test_radius_server.rb +16 -11
- data/tests/test_router_bgp.rb +11 -6
- data/tests/test_router_ospf_area.rb +6 -6
- data/tests/test_tacacs_server.rb +2 -2
- data/tests/test_tacacs_server_host.rb +2 -2
- data/tests/test_vlan.rb +14 -0
- data/tests/test_yum.rb +2 -2
- data/tests/yum_package.yaml +4 -0
- metadata +10 -3
@@ -119,6 +119,20 @@ module Cisco
|
|
119
119
|
config_get('feature', 'fex')
|
120
120
|
end
|
121
121
|
|
122
|
+
# ---------------------------
|
123
|
+
def self.hsrp_enable
|
124
|
+
return if hsrp_enabled?
|
125
|
+
config_set('feature', 'hsrp')
|
126
|
+
end
|
127
|
+
|
128
|
+
def self.hsrp_enabled?
|
129
|
+
config_get('feature', 'hsrp')
|
130
|
+
rescue Cisco::CliError => e
|
131
|
+
# cmd will syntax reject when feature is not enabled.
|
132
|
+
raise unless e.clierror =~ /Syntax error/
|
133
|
+
return false
|
134
|
+
end
|
135
|
+
|
122
136
|
# ---------------------------
|
123
137
|
def self.itd_enable
|
124
138
|
return if itd_enabled?
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# October 2016, Sai Chintalapudi
|
2
|
+
#
|
3
|
+
# Copyright (c) 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_util'
|
18
|
+
|
19
|
+
module Cisco
|
20
|
+
# node_utils class for hsrp_global
|
21
|
+
class HsrpGlobal < NodeUtil
|
22
|
+
def initialize(instantiate=true)
|
23
|
+
Feature.hsrp_enable if instantiate
|
24
|
+
set_args_keys_default
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.globals
|
28
|
+
hash = {}
|
29
|
+
hash['default'] = HsrpGlobal.new(false) if Feature.hsrp_enabled?
|
30
|
+
hash
|
31
|
+
end
|
32
|
+
|
33
|
+
# Helper method to delete @set_args hash keys
|
34
|
+
def set_args_keys_default
|
35
|
+
@set_args = {}
|
36
|
+
@get_args = @set_args
|
37
|
+
end
|
38
|
+
|
39
|
+
# rubocop:disable Style/AccessorMethodName
|
40
|
+
def set_args_keys(hash={})
|
41
|
+
set_args_keys_default
|
42
|
+
@set_args = @get_args.merge!(hash) unless hash.empty?
|
43
|
+
end
|
44
|
+
|
45
|
+
def destroy
|
46
|
+
return unless Feature.hsrp_enabled?
|
47
|
+
[:bfd_all_intf,
|
48
|
+
:extended_hold,
|
49
|
+
].each do |prop|
|
50
|
+
send("#{prop}=", send("default_#{prop}")) if send prop
|
51
|
+
end
|
52
|
+
set_args_keys_default
|
53
|
+
end
|
54
|
+
|
55
|
+
########################################################
|
56
|
+
# PROPERTIES #
|
57
|
+
########################################################
|
58
|
+
|
59
|
+
def bfd_all_intf
|
60
|
+
config_get('hsrp_global', 'bfd_all_intf')
|
61
|
+
end
|
62
|
+
|
63
|
+
def bfd_all_intf=(val)
|
64
|
+
state = val ? '' : 'no'
|
65
|
+
set_args_keys(state: state)
|
66
|
+
Feature.bfd_enable if val
|
67
|
+
config_set('hsrp_global', 'bfd_all_intf', @set_args)
|
68
|
+
end
|
69
|
+
|
70
|
+
def default_bfd_all_intf
|
71
|
+
config_get_default('hsrp_global', 'bfd_all_intf')
|
72
|
+
end
|
73
|
+
|
74
|
+
# CLI can be either of the following or none
|
75
|
+
# hsrp timers extended-hold (in this case, the time is 10)
|
76
|
+
# hsrp timers extended-hold <time>
|
77
|
+
def extended_hold
|
78
|
+
hold = config_get('hsrp_global', 'extended_hold', @get_args)
|
79
|
+
return default_extended_hold unless hold
|
80
|
+
arr = hold.split('hsrp timers extended-hold')
|
81
|
+
return config_get('hsrp_global', 'extended_hold_enable', @get_args) if
|
82
|
+
arr.empty?
|
83
|
+
arr[1].strip
|
84
|
+
end
|
85
|
+
|
86
|
+
def extended_hold=(val)
|
87
|
+
state = val ? '' : 'no'
|
88
|
+
time = val ? val : ''
|
89
|
+
set_args_keys(state: state, time: time)
|
90
|
+
config_set('hsrp_global', 'extended_hold', @set_args)
|
91
|
+
end
|
92
|
+
|
93
|
+
def default_extended_hold
|
94
|
+
config_get_default('hsrp_global', 'extended_hold')
|
95
|
+
end
|
96
|
+
end # class
|
97
|
+
end # module
|
@@ -266,6 +266,135 @@ module Cisco
|
|
266
266
|
config_get_default('interface', 'fabric_forwarding_anycast_gateway')
|
267
267
|
end
|
268
268
|
|
269
|
+
def hsrp_bfd
|
270
|
+
config_get('interface', 'hsrp_bfd', name: @name)
|
271
|
+
end
|
272
|
+
|
273
|
+
def hsrp_bfd=(val)
|
274
|
+
state = val ? '' : 'no'
|
275
|
+
if val
|
276
|
+
Feature.hsrp_enable
|
277
|
+
Feature.bfd_enable
|
278
|
+
end
|
279
|
+
config_set('interface', 'hsrp_bfd', name: @name, state: state)
|
280
|
+
end
|
281
|
+
|
282
|
+
def default_hsrp_bfd
|
283
|
+
config_get_default('interface', 'hsrp_bfd')
|
284
|
+
end
|
285
|
+
|
286
|
+
# hsrp delay minimum and reload are in the same CLI
|
287
|
+
# hsrp delay minimum 0 reload 0
|
288
|
+
def hsrp_delay
|
289
|
+
match = config_get('interface', 'hsrp_delay', name: @name)
|
290
|
+
match.nil? ? default_hsrp_delay : match.collect(&:to_i)
|
291
|
+
end
|
292
|
+
|
293
|
+
def default_hsrp_delay
|
294
|
+
[default_hsrp_delay_minimum, default_hsrp_delay_reload]
|
295
|
+
end
|
296
|
+
|
297
|
+
def hsrp_delay_minimum
|
298
|
+
minimum, _reload = hsrp_delay
|
299
|
+
minimum.nil? ? default_hsrp_delay_minimum : minimum
|
300
|
+
end
|
301
|
+
|
302
|
+
# hsrp delay minimum and reload are in the same CLI
|
303
|
+
# but both can be set independent of each other
|
304
|
+
def hsrp_delay_minimum=(val)
|
305
|
+
Feature.hsrp_enable if val
|
306
|
+
config_set('interface', 'hsrp_delay', name: @name,
|
307
|
+
minimum: 'minimum', min: val, reload: '', rel: '')
|
308
|
+
end
|
309
|
+
|
310
|
+
def default_hsrp_delay_minimum
|
311
|
+
config_get_default('interface', 'hsrp_delay_minimum')
|
312
|
+
end
|
313
|
+
|
314
|
+
def hsrp_delay_reload
|
315
|
+
_minimum, reload = hsrp_delay
|
316
|
+
reload.nil? ? default_hsrp_delay_reload : reload
|
317
|
+
end
|
318
|
+
|
319
|
+
# hsrp delay minimum and reload are in the same CLI
|
320
|
+
# but both can be set independent of each other
|
321
|
+
def hsrp_delay_reload=(val)
|
322
|
+
Feature.hsrp_enable if val
|
323
|
+
config_set('interface', 'hsrp_delay', name: @name,
|
324
|
+
minimum: '', min: '', reload: 'reload', rel: val)
|
325
|
+
end
|
326
|
+
|
327
|
+
def default_hsrp_delay_reload
|
328
|
+
config_get_default('interface', 'hsrp_delay_reload')
|
329
|
+
end
|
330
|
+
|
331
|
+
def hsrp_mac_refresh
|
332
|
+
config_get('interface', 'hsrp_mac_refresh', name: @name)
|
333
|
+
end
|
334
|
+
|
335
|
+
def hsrp_mac_refresh=(val)
|
336
|
+
state = val ? '' : 'no'
|
337
|
+
time = val ? val : ''
|
338
|
+
Feature.hsrp_enable if val
|
339
|
+
config_set('interface', 'hsrp_mac_refresh', name: @name,
|
340
|
+
state: state, timeout: time)
|
341
|
+
end
|
342
|
+
|
343
|
+
def default_hsrp_mac_refresh
|
344
|
+
config_get_default('interface', 'hsrp_mac_refresh')
|
345
|
+
end
|
346
|
+
|
347
|
+
def hsrp_use_bia
|
348
|
+
match = config_get('interface', 'hsrp_use_bia', name: @name)
|
349
|
+
return default_hsrp_use_bia unless match
|
350
|
+
match.include?('scope') ? :use_bia_intf : :use_bia
|
351
|
+
end
|
352
|
+
|
353
|
+
def hsrp_use_bia=(val)
|
354
|
+
# Return early if device already set to the correct value
|
355
|
+
return if val == hsrp_use_bia
|
356
|
+
# need to reset before set
|
357
|
+
if val
|
358
|
+
Feature.hsrp_enable
|
359
|
+
if val == :use_bia
|
360
|
+
config_set('interface', 'hsrp_use_bia', name: name,
|
361
|
+
state: 'no', scope: ' scope interface')
|
362
|
+
config_set('interface', 'hsrp_use_bia', name: name,
|
363
|
+
state: '', scope: '')
|
364
|
+
else
|
365
|
+
config_set('interface', 'hsrp_use_bia', name: name,
|
366
|
+
state: 'no', scope: '')
|
367
|
+
config_set('interface', 'hsrp_use_bia', name: name,
|
368
|
+
state: '', scope: ' scope interface')
|
369
|
+
end
|
370
|
+
else
|
371
|
+
if hsrp_use_bia == :use_bia
|
372
|
+
config_set('interface', 'hsrp_use_bia', name: name,
|
373
|
+
state: 'no', scope: '')
|
374
|
+
else
|
375
|
+
config_set('interface', 'hsrp_use_bia', name: name,
|
376
|
+
state: 'no', scope: ' scope interface')
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
def default_hsrp_use_bia
|
382
|
+
config_get_default('interface', 'hsrp_use_bia')
|
383
|
+
end
|
384
|
+
|
385
|
+
def hsrp_version
|
386
|
+
config_get('interface', 'hsrp_version', name: @name)
|
387
|
+
end
|
388
|
+
|
389
|
+
def hsrp_version=(val)
|
390
|
+
Feature.hsrp_enable if val
|
391
|
+
config_set('interface', 'hsrp_version', name: name, ver: val)
|
392
|
+
end
|
393
|
+
|
394
|
+
def default_hsrp_version
|
395
|
+
config_get_default('interface', 'hsrp_version')
|
396
|
+
end
|
397
|
+
|
269
398
|
def ipv4_acl_in
|
270
399
|
config_get('interface', 'ipv4_acl_in', name: @name)
|
271
400
|
end
|
@@ -791,6 +920,23 @@ module Cisco
|
|
791
920
|
config_get_default('interface', lookup)
|
792
921
|
end
|
793
922
|
|
923
|
+
def pim_bfd
|
924
|
+
config_get('interface', 'pim_bfd', name: @name)
|
925
|
+
end
|
926
|
+
|
927
|
+
def pim_bfd=(val)
|
928
|
+
state = val ? '' : 'no'
|
929
|
+
if val
|
930
|
+
Feature.pim_enable
|
931
|
+
Feature.bfd_enable
|
932
|
+
end
|
933
|
+
config_set('interface', 'pim_bfd', name: @name, state: state)
|
934
|
+
end
|
935
|
+
|
936
|
+
def default_pim_bfd
|
937
|
+
config_get_default('interface', 'pim_bfd')
|
938
|
+
end
|
939
|
+
|
794
940
|
def storm_control_broadcast
|
795
941
|
config_get('interface', 'storm_control_broadcast', name: @name)
|
796
942
|
end
|
@@ -0,0 +1,544 @@
|
|
1
|
+
#
|
2
|
+
# October 2016, Sai Chintalapudi
|
3
|
+
#
|
4
|
+
# Copyright (c) 2016 Cisco and/or its affiliates.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
|
18
|
+
require_relative 'node_util'
|
19
|
+
require_relative 'interface'
|
20
|
+
|
21
|
+
module Cisco
|
22
|
+
# node_utils class for interface_hsrp_group
|
23
|
+
class InterfaceHsrpGroup < NodeUtil
|
24
|
+
attr_reader :name, :group, :iptype
|
25
|
+
|
26
|
+
def initialize(interface, group_id, ip_type, instantiate=true)
|
27
|
+
fail TypeError unless interface.is_a?(String)
|
28
|
+
fail ArgumentError unless ip_type[/ipv4|ipv6/]
|
29
|
+
@name = interface.downcase
|
30
|
+
@group = group_id
|
31
|
+
@iptype = ip_type
|
32
|
+
|
33
|
+
set_args_keys_default
|
34
|
+
create if instantiate
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.groups
|
38
|
+
hash = {}
|
39
|
+
return hash unless Feature.hsrp_enabled?
|
40
|
+
Interface.interfaces.each do|intf, _obj|
|
41
|
+
groups = config_get('interface_hsrp_group', 'groups', name: intf)
|
42
|
+
next if groups.nil?
|
43
|
+
hash[intf] = {}
|
44
|
+
groups.each do |id, type|
|
45
|
+
iptype = type
|
46
|
+
iptype = 'ipv4' if type.nil?
|
47
|
+
hash[intf][id] ||= {}
|
48
|
+
hash[intf][id][iptype] =
|
49
|
+
InterfaceHsrpGroup.new(intf, id, iptype, false)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
hash
|
53
|
+
end
|
54
|
+
|
55
|
+
# Helper method to delete @set_args hash keys
|
56
|
+
def set_args_keys_default
|
57
|
+
@set_args = { name: @name, group: @group, iptype: iptype }
|
58
|
+
@set_args[:iptype] = '' if @iptype == 'ipv4'
|
59
|
+
@get_args = @set_args
|
60
|
+
end
|
61
|
+
|
62
|
+
# rubocop:disable Style/AccessorMethodName
|
63
|
+
def set_args_keys(hash={})
|
64
|
+
set_args_keys_default
|
65
|
+
@set_args = @get_args.merge!(hash) unless hash.empty?
|
66
|
+
end
|
67
|
+
|
68
|
+
# Create one interface hsrp group instance
|
69
|
+
def create
|
70
|
+
Feature.hsrp_enable
|
71
|
+
set_args_keys(state: '')
|
72
|
+
config_set('interface_hsrp_group', 'groups', @set_args)
|
73
|
+
end
|
74
|
+
|
75
|
+
def destroy
|
76
|
+
return unless Feature.hsrp_enabled?
|
77
|
+
# for ipv4 types, 'no' cmd needs the type to be specified
|
78
|
+
# explicitly if another ipv6 group exists with the same
|
79
|
+
# group id
|
80
|
+
set_args_keys(state: 'no', iptype: @iptype)
|
81
|
+
config_set('interface_hsrp_group', 'groups', @set_args)
|
82
|
+
end
|
83
|
+
|
84
|
+
########################################################
|
85
|
+
# PROPERTIES #
|
86
|
+
########################################################
|
87
|
+
|
88
|
+
# This CLI is very complicated, it can take many forms
|
89
|
+
# authentication text Test
|
90
|
+
# authentication md5 key-chain abcd
|
91
|
+
# authentication md5 key-string 7 => 7 is key-string
|
92
|
+
# authentication md5 key-string 7 12345678901234567890
|
93
|
+
# authentication md5 key-string ABCXYZ => enctype is 0
|
94
|
+
# authentication md5 key-string ABCXYZ compatibility
|
95
|
+
# authentication md5 key-string ABCXYZ compatibility timeout 22
|
96
|
+
# authentication md5 key-string ABCXYZ timeout 22
|
97
|
+
# authentication md5 key-string 7 12345678901234567890 timeout 22
|
98
|
+
# authentication md5 key-string 7 123456789 compatibility timeout 22
|
99
|
+
def authentication
|
100
|
+
hash = {}
|
101
|
+
hash[:auth_type] = default_authentication_auth_type
|
102
|
+
hash[:key_type] = default_authentication_key_type
|
103
|
+
hash[:enc_type] = default_authentication_enc_type
|
104
|
+
hash[:password] = default_authentication_string
|
105
|
+
hash[:compat] = default_authentication_compatibility
|
106
|
+
hash[:timeout] = default_authentication_timeout
|
107
|
+
str = config_get('interface_hsrp_group', 'authentication', @get_args)
|
108
|
+
return hash if str.nil?
|
109
|
+
regexp = Regexp.new('(?<authtype>text|md5)'\
|
110
|
+
' *(?<keytype>key-chain|key-string|\S+)'\
|
111
|
+
' *(?<enctype>7|\S+)?'\
|
112
|
+
' *(?<keystring>\S+)?')
|
113
|
+
params = regexp.match(str)
|
114
|
+
if params[:authtype] == 'text'
|
115
|
+
hash[:password] = params[:keytype]
|
116
|
+
else
|
117
|
+
hash[:auth_type] = 'md5'
|
118
|
+
hash[:key_type] = params[:keytype]
|
119
|
+
if hash[:key_type] == 'key-chain'
|
120
|
+
hash[:password] = params[:enctype]
|
121
|
+
else
|
122
|
+
if params[:enctype] == '7' && params[:keystring].nil?
|
123
|
+
hash[:password] = '7'
|
124
|
+
elsif params[:enctype] == '7' && !params[:keystring].nil?
|
125
|
+
hash[:enc_type] = '7'
|
126
|
+
hash[:password] = params[:keystring]
|
127
|
+
else
|
128
|
+
hash[:password] = params[:enctype]
|
129
|
+
end
|
130
|
+
# get rid of password from str just in case the password is
|
131
|
+
# compatibility or timeout
|
132
|
+
str.sub!(hash[:password], '')
|
133
|
+
hash[:compat] = true if str.include?('compatibility')
|
134
|
+
hash[:timeout] = str.split.last.to_i if str.include?('timeout')
|
135
|
+
end
|
136
|
+
end
|
137
|
+
hash
|
138
|
+
end
|
139
|
+
|
140
|
+
def authentication_auth_type
|
141
|
+
authentication[:auth_type]
|
142
|
+
end
|
143
|
+
|
144
|
+
def authentication_auth_type=(val)
|
145
|
+
@set_args[:authtype] = val
|
146
|
+
@set_args[:authtype] = 'text' if val.to_s == 'cleartext'
|
147
|
+
end
|
148
|
+
|
149
|
+
def default_authentication_auth_type
|
150
|
+
config_get_default('interface_hsrp_group', 'authentication_auth_type')
|
151
|
+
end
|
152
|
+
|
153
|
+
def authentication_key_type
|
154
|
+
authentication[:key_type]
|
155
|
+
end
|
156
|
+
|
157
|
+
def authentication_key_type=(val)
|
158
|
+
@set_args[:keytype] = val.to_s
|
159
|
+
end
|
160
|
+
|
161
|
+
def default_authentication_key_type
|
162
|
+
config_get_default('interface_hsrp_group', 'authentication_key_type')
|
163
|
+
end
|
164
|
+
|
165
|
+
def authentication_enc_type
|
166
|
+
authentication[:enc_type]
|
167
|
+
end
|
168
|
+
|
169
|
+
def authentication_enc_type=(val)
|
170
|
+
@set_args[:enctype] = val
|
171
|
+
end
|
172
|
+
|
173
|
+
def default_authentication_enc_type
|
174
|
+
config_get_default('interface_hsrp_group', 'authentication_enc_type')
|
175
|
+
end
|
176
|
+
|
177
|
+
def authentication_string
|
178
|
+
authentication[:password]
|
179
|
+
end
|
180
|
+
|
181
|
+
def authentication_string=(val)
|
182
|
+
@set_args[:passwd] = val
|
183
|
+
end
|
184
|
+
|
185
|
+
def default_authentication_string
|
186
|
+
config_get_default('interface_hsrp_group', 'authentication_string')
|
187
|
+
end
|
188
|
+
|
189
|
+
def authentication_compatibility
|
190
|
+
authentication[:compat]
|
191
|
+
end
|
192
|
+
|
193
|
+
def authentication_compatibility=(val)
|
194
|
+
@set_args[:compatible] = val ? 'compatibility' : ''
|
195
|
+
end
|
196
|
+
|
197
|
+
def default_authentication_compatibility
|
198
|
+
config_get_default('interface_hsrp_group', 'authentication_compatibility')
|
199
|
+
end
|
200
|
+
|
201
|
+
def authentication_timeout
|
202
|
+
authentication[:timeout]
|
203
|
+
end
|
204
|
+
|
205
|
+
def authentication_timeout=(val)
|
206
|
+
@set_args[:tval] = val
|
207
|
+
@set_args[:timeout] = 'timeout'
|
208
|
+
end
|
209
|
+
|
210
|
+
def default_authentication_timeout
|
211
|
+
config_get_default('interface_hsrp_group', 'authentication_timeout')
|
212
|
+
end
|
213
|
+
|
214
|
+
def authentication_set(attrs)
|
215
|
+
set_args_keys_default
|
216
|
+
# reset the authentication first
|
217
|
+
@set_args[:state] = 'no'
|
218
|
+
@set_args[:passwd] = ''
|
219
|
+
@set_args[:authtype] = @set_args[:keytype] = @set_args[:enctype] = ''
|
220
|
+
@set_args[:compatible] = @set_args[:timeout] = @set_args[:tval] = ''
|
221
|
+
config_set('interface_hsrp_group', 'authentication', @set_args)
|
222
|
+
set_args_keys(attrs)
|
223
|
+
[:authentication_auth_type,
|
224
|
+
:authentication_key_type,
|
225
|
+
:authentication_enc_type,
|
226
|
+
:authentication_string,
|
227
|
+
:authentication_compatibility,
|
228
|
+
:authentication_timeout,
|
229
|
+
].each do |p|
|
230
|
+
send(p.to_s + '=', attrs[p]) unless attrs[p].nil?
|
231
|
+
end
|
232
|
+
return if @set_args[:passwd] == default_authentication_string
|
233
|
+
@set_args[:state] = ''
|
234
|
+
if @set_args[:authtype] == 'text'
|
235
|
+
@set_args[:keytype] = @set_args[:enctype] = ''
|
236
|
+
@set_args[:compatible] = @set_args[:timeout] = @set_args[:tval] = ''
|
237
|
+
elsif @set_args[:keytype] == default_authentication_key_type
|
238
|
+
@set_args[:enctype] = @set_args[:compatible] = ''
|
239
|
+
@set_args[:timeout] = @set_args[:tval] = ''
|
240
|
+
end
|
241
|
+
config_set('interface_hsrp_group', 'authentication', @set_args)
|
242
|
+
end
|
243
|
+
|
244
|
+
def ipv4_enable
|
245
|
+
return default_ipv4_enable if @iptype == 'ipv6'
|
246
|
+
ip = config_get('interface_hsrp_group', 'ipv4_vip', @get_args)
|
247
|
+
ip.empty? ? false : true
|
248
|
+
end
|
249
|
+
|
250
|
+
def default_ipv4_enable
|
251
|
+
config_get_default('interface_hsrp_group', 'ipv4_enable')
|
252
|
+
end
|
253
|
+
|
254
|
+
def ipv4_vip
|
255
|
+
return default_ipv4_vip if @iptype == 'ipv6'
|
256
|
+
ip = config_get('interface_hsrp_group', 'ipv4_vip', @get_args)
|
257
|
+
return default_ipv4_vip unless ip
|
258
|
+
arr = ip.split
|
259
|
+
arr[1] ? arr[1] : default_ipv4_vip
|
260
|
+
end
|
261
|
+
|
262
|
+
def ipv4_vip_set(ipenable, vip)
|
263
|
+
return if @iptype == 'ipv6'
|
264
|
+
# reset it first
|
265
|
+
set_args_keys(state: 'no', vip: '')
|
266
|
+
config_set('interface_hsrp_group', 'ipv4_vip', @set_args)
|
267
|
+
return unless ipenable
|
268
|
+
vip = vip ? vip : ''
|
269
|
+
set_args_keys(state: '', vip: vip)
|
270
|
+
config_set('interface_hsrp_group', 'ipv4_vip', @set_args)
|
271
|
+
end
|
272
|
+
|
273
|
+
def default_ipv4_vip
|
274
|
+
config_get_default('interface_hsrp_group', 'ipv4_vip')
|
275
|
+
end
|
276
|
+
|
277
|
+
def ipv6_autoconfig
|
278
|
+
config_get('interface_hsrp_group', 'ipv6_autoconfig', @get_args)
|
279
|
+
end
|
280
|
+
|
281
|
+
def ipv6_autoconfig=(val)
|
282
|
+
state = val ? '' : 'no'
|
283
|
+
set_args_keys(state: state)
|
284
|
+
config_set('interface_hsrp_group', 'ipv6_autoconfig', @set_args)
|
285
|
+
end
|
286
|
+
|
287
|
+
def default_ipv6_autoconfig
|
288
|
+
config_get_default('interface_hsrp_group', 'ipv6_autoconfig')
|
289
|
+
end
|
290
|
+
|
291
|
+
def ipv6_vip
|
292
|
+
return default_ipv6_vip if @iptype == 'ipv4'
|
293
|
+
list = config_get('interface_hsrp_group', 'ipv6_vip', @get_args)
|
294
|
+
# remove autoconfig from the list
|
295
|
+
list.delete('autoconfig')
|
296
|
+
list
|
297
|
+
end
|
298
|
+
|
299
|
+
def ipv6_vip=(list)
|
300
|
+
# reset the current list
|
301
|
+
cur = ipv6_vip
|
302
|
+
cur.each do |addr|
|
303
|
+
state = 'no'
|
304
|
+
vip = addr
|
305
|
+
set_args_keys(state: state, vip: vip)
|
306
|
+
config_set('interface_hsrp_group', 'ipv6_vip', @set_args)
|
307
|
+
end
|
308
|
+
list.each do |addr|
|
309
|
+
state = ''
|
310
|
+
vip = addr
|
311
|
+
set_args_keys(state: state, vip: vip)
|
312
|
+
config_set('interface_hsrp_group', 'ipv6_vip', @set_args)
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
def default_ipv6_vip
|
317
|
+
config_get_default('interface_hsrp_group', 'ipv6_vip')
|
318
|
+
end
|
319
|
+
|
320
|
+
# CLI returns mac_addr in xxxx.xxxx.xxxx format
|
321
|
+
# so convert it to xx:xx:xx:xx:xx:xx format
|
322
|
+
def mac_addr
|
323
|
+
mac = config_get('interface_hsrp_group', 'mac_addr', @get_args)
|
324
|
+
return default_mac_addr unless mac
|
325
|
+
mac.tr('.', '').scan(/.{1,2}/).join(':')
|
326
|
+
end
|
327
|
+
|
328
|
+
# CLI expects mac_addr to be in xxxx.xxxx.xxxx format
|
329
|
+
# so convert from xx:xx:xx:xx:xx:xx format
|
330
|
+
def mac_addr=(val)
|
331
|
+
state = val ? '' : 'no'
|
332
|
+
mac = val ? val.tr(':', '').scan(/.{1,4}/).join('.') : ''
|
333
|
+
set_args_keys(state: state, mac: mac)
|
334
|
+
config_set('interface_hsrp_group', 'mac_addr', @set_args)
|
335
|
+
end
|
336
|
+
|
337
|
+
def default_mac_addr
|
338
|
+
config_get_default('interface_hsrp_group', 'mac_addr')
|
339
|
+
end
|
340
|
+
|
341
|
+
def group_name
|
342
|
+
config_get('interface_hsrp_group', 'group_name', @get_args)
|
343
|
+
end
|
344
|
+
|
345
|
+
def group_name=(val)
|
346
|
+
state = val ? '' : 'no'
|
347
|
+
word = val ? val : ''
|
348
|
+
set_args_keys(state: state, word: word)
|
349
|
+
config_set('interface_hsrp_group', 'group_name', @set_args)
|
350
|
+
end
|
351
|
+
|
352
|
+
def default_group_name
|
353
|
+
config_get_default('interface_hsrp_group', 'group_name')
|
354
|
+
end
|
355
|
+
|
356
|
+
# The CLI can take forms like:
|
357
|
+
# preempt
|
358
|
+
# preempt delay minimum 3 reload 10 sync 15
|
359
|
+
def preempt_get
|
360
|
+
hash = {}
|
361
|
+
hash[:preempt] = default_preempt
|
362
|
+
hash[:minimum] = default_preempt_delay_minimum
|
363
|
+
hash[:reload] = default_preempt_delay_reload
|
364
|
+
hash[:sync] = default_preempt_delay_sync
|
365
|
+
arr = config_get('interface_hsrp_group', 'preempt', @get_args)
|
366
|
+
if arr
|
367
|
+
hash[:preempt] = true
|
368
|
+
hash[:minimum] = arr[0]
|
369
|
+
hash[:reload] = arr[1]
|
370
|
+
hash[:sync] = arr[2]
|
371
|
+
end
|
372
|
+
hash
|
373
|
+
end
|
374
|
+
|
375
|
+
def preempt
|
376
|
+
preempt_get[:preempt]
|
377
|
+
end
|
378
|
+
|
379
|
+
def preempt_delay_minimum
|
380
|
+
preempt_get[:minimum].to_i
|
381
|
+
end
|
382
|
+
|
383
|
+
def preempt_delay_reload
|
384
|
+
preempt_get[:reload].to_i
|
385
|
+
end
|
386
|
+
|
387
|
+
def preempt_delay_sync
|
388
|
+
preempt_get[:sync].to_i
|
389
|
+
end
|
390
|
+
|
391
|
+
def preempt_set(pree, min, rel, sy)
|
392
|
+
if pree
|
393
|
+
set_args_keys(state: '', delay: 'delay', minimum: 'minimum',
|
394
|
+
minval: min, reload: 'reload', relval: rel,
|
395
|
+
sync: 'sync', syncval: sy)
|
396
|
+
else
|
397
|
+
set_args_keys(state: 'no', delay: '', minimum: '', minval: '',
|
398
|
+
reload: '', relval: '', sync: '', syncval: '')
|
399
|
+
end
|
400
|
+
config_set('interface_hsrp_group', 'preempt', @set_args)
|
401
|
+
end
|
402
|
+
|
403
|
+
def default_preempt
|
404
|
+
config_get_default('interface_hsrp_group', 'preempt')
|
405
|
+
end
|
406
|
+
|
407
|
+
def default_preempt_delay_minimum
|
408
|
+
config_get_default('interface_hsrp_group', 'preempt_delay_minimum')
|
409
|
+
end
|
410
|
+
|
411
|
+
def default_preempt_delay_reload
|
412
|
+
config_get_default('interface_hsrp_group', 'preempt_delay_reload')
|
413
|
+
end
|
414
|
+
|
415
|
+
def default_preempt_delay_sync
|
416
|
+
config_get_default('interface_hsrp_group', 'preempt_delay_sync')
|
417
|
+
end
|
418
|
+
|
419
|
+
# This CLI can take forms like:
|
420
|
+
# priority 10
|
421
|
+
# priority 50 forwarding-threshold lower 10 upper 49
|
422
|
+
def priority_level_get
|
423
|
+
hash = {}
|
424
|
+
hash[:priority] = default_priority
|
425
|
+
hash[:lower] = default_priority_forward_thresh_lower
|
426
|
+
hash[:upper] = default_priority_forward_thresh_upper
|
427
|
+
arr = config_get('interface_hsrp_group', 'priority_level', @get_args)
|
428
|
+
if arr
|
429
|
+
hash[:priority] = arr[0].to_i
|
430
|
+
hash[:lower] = arr[1].to_i if arr[1]
|
431
|
+
hash[:upper] = arr[2].to_i if arr[2]
|
432
|
+
end
|
433
|
+
hash
|
434
|
+
end
|
435
|
+
|
436
|
+
def priority
|
437
|
+
priority_level_get[:priority]
|
438
|
+
end
|
439
|
+
|
440
|
+
def default_priority
|
441
|
+
config_get_default('interface_hsrp_group', 'priority')
|
442
|
+
end
|
443
|
+
|
444
|
+
def priority_forward_thresh_lower
|
445
|
+
priority_level_get[:lower]
|
446
|
+
end
|
447
|
+
|
448
|
+
def default_priority_forward_thresh_lower
|
449
|
+
config_get_default('interface_hsrp_group',
|
450
|
+
'priority_forward_thresh_lower')
|
451
|
+
end
|
452
|
+
|
453
|
+
def priority_forward_thresh_upper
|
454
|
+
priority_level_get[:upper]
|
455
|
+
end
|
456
|
+
|
457
|
+
def default_priority_forward_thresh_upper
|
458
|
+
config_get_default('interface_hsrp_group',
|
459
|
+
'priority_forward_thresh_upper')
|
460
|
+
end
|
461
|
+
|
462
|
+
def priority_level_set(pri, lower, upper)
|
463
|
+
if pri && !lower.to_s.empty? && !upper.to_s.empty?
|
464
|
+
set_args_keys(state: '', pri: pri,
|
465
|
+
forward: 'forwarding-threshold lower',
|
466
|
+
lval: lower, upper: 'upper', uval: upper)
|
467
|
+
elsif pri
|
468
|
+
set_args_keys(state: '', pri: pri,
|
469
|
+
forward: '', lval: '', upper: '', uval: '')
|
470
|
+
else
|
471
|
+
set_args_keys(state: 'no', pri: pri, forward: '', lval: '',
|
472
|
+
upper: '', uval: '')
|
473
|
+
end
|
474
|
+
config_set('interface_hsrp_group', 'priority_level', @set_args)
|
475
|
+
end
|
476
|
+
|
477
|
+
# This CLI can take forms like:
|
478
|
+
# timers 1 3
|
479
|
+
# timers msec 300 3
|
480
|
+
# timers msec 750 msec 2500
|
481
|
+
def timers_get
|
482
|
+
hash = {}
|
483
|
+
hash[:hello] = default_timers_hello
|
484
|
+
hash[:mshello] = default_timers_hello_msec
|
485
|
+
hash[:hold] = default_timers_hold
|
486
|
+
hash[:mshold] = default_timers_hold_msec
|
487
|
+
str = config_get('interface_hsrp_group', 'timers', @get_args)
|
488
|
+
return hash if str.nil?
|
489
|
+
regexp = Regexp.new('(?<msec1>msec)?'\
|
490
|
+
' *(?<he>\d+) *(?<msec2>msec)? *(?<ho>\d+)')
|
491
|
+
params = regexp.match(str)
|
492
|
+
hash[:mshello] = true if params[:msec1]
|
493
|
+
hash[:mshold] = true if params[:msec2]
|
494
|
+
hash[:hello] = params[:he].to_i
|
495
|
+
hash[:hold] = params[:ho].to_i
|
496
|
+
hash
|
497
|
+
end
|
498
|
+
|
499
|
+
def timers_hello
|
500
|
+
timers_get[:hello]
|
501
|
+
end
|
502
|
+
|
503
|
+
def timers_hello_msec
|
504
|
+
timers_get[:mshello]
|
505
|
+
end
|
506
|
+
|
507
|
+
def default_timers_hello
|
508
|
+
config_get_default('interface_hsrp_group', 'timers_hello')
|
509
|
+
end
|
510
|
+
|
511
|
+
def default_timers_hello_msec
|
512
|
+
config_get_default('interface_hsrp_group', 'timers_hello_msec')
|
513
|
+
end
|
514
|
+
|
515
|
+
def timers_hold
|
516
|
+
timers_get[:hold]
|
517
|
+
end
|
518
|
+
|
519
|
+
def timers_hold_msec
|
520
|
+
timers_get[:mshold]
|
521
|
+
end
|
522
|
+
|
523
|
+
def default_timers_hold_msec
|
524
|
+
config_get_default('interface_hsrp_group', 'timers_hold_msec')
|
525
|
+
end
|
526
|
+
|
527
|
+
def default_timers_hold
|
528
|
+
config_get_default('interface_hsrp_group', 'timers_hold')
|
529
|
+
end
|
530
|
+
|
531
|
+
def timers_set(mshello, hello, mshold, hold)
|
532
|
+
if hello && hold
|
533
|
+
msechello = mshello ? 'msec' : ''
|
534
|
+
msechold = mshold ? 'msec' : ''
|
535
|
+
set_args_keys(state: '', mshello: msechello,
|
536
|
+
hello: hello, mshold: msechold, hold: hold)
|
537
|
+
else
|
538
|
+
set_args_keys(state: 'no', mshello: '', hello: '',
|
539
|
+
mshold: '', hold: '')
|
540
|
+
end
|
541
|
+
config_set('interface_hsrp_group', 'timers', @set_args)
|
542
|
+
end
|
543
|
+
end # class
|
544
|
+
end # module
|