cisco_node_utils 1.7.0 → 1.8.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 +36 -0
- data/CONTRIBUTING.md +2 -2
- data/README.md +2 -1
- data/cisco_node_utils.gemspec +1 -0
- data/docs/README-develop-node-utils-APIs.md +2 -1
- data/lib/cisco_node_utils/aaa_authentication_login_service.rb +2 -2
- data/lib/cisco_node_utils/ace.rb +2 -0
- data/lib/cisco_node_utils/bgp.rb +34 -91
- data/lib/cisco_node_utils/bridge_domain.rb +8 -13
- data/lib/cisco_node_utils/client/nxapi/client.rb +10 -3
- data/lib/cisco_node_utils/cmd_ref/DEPRECATED.yaml +12 -12
- data/lib/cisco_node_utils/cmd_ref/README_YAML.md +2 -1
- data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +1 -0
- data/lib/cisco_node_utils/cmd_ref/bfd_global.yaml +3 -3
- data/lib/cisco_node_utils/cmd_ref/bgp.yaml +5 -15
- data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +1 -0
- data/lib/cisco_node_utils/cmd_ref/bridge_domain.yaml +14 -36
- 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 -3
- data/lib/cisco_node_utils/cmd_ref/encapsulation.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/feature.yaml +3 -3
- data/lib/cisco_node_utils/cmd_ref/interface.yaml +25 -15
- data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +5 -0
- data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +6 -0
- data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/inventory.yaml +9 -0
- 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/object_group.yaml +32 -0
- data/lib/cisco_node_utils/cmd_ref/ospf.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +9 -7
- data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +7 -0
- data/lib/cisco_node_utils/cmd_ref/route_map.yaml +26 -25
- data/lib/cisco_node_utils/cmd_ref/show_version.yaml +11 -3
- data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +4 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +5 -1
- data/lib/cisco_node_utils/cmd_ref/stp_global.yaml +8 -8
- data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +3 -2
- data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +21 -1
- data/lib/cisco_node_utils/cmd_ref/tacacs_global.yaml +7 -0
- data/lib/cisco_node_utils/cmd_ref/vdc.yaml +1 -1
- data/lib/cisco_node_utils/cmd_ref/vlan.yaml +5 -4
- data/lib/cisco_node_utils/cmd_ref/vpc.yaml +9 -9
- data/lib/cisco_node_utils/cmd_ref/vrf.yaml +1 -0
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +1 -0
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +3 -5
- data/lib/cisco_node_utils/command_reference.rb +11 -1
- data/lib/cisco_node_utils/interface.rb +46 -8
- data/lib/cisco_node_utils/interface_ospf.rb +2 -2
- data/lib/cisco_node_utils/interface_portchannel.rb +2 -2
- data/lib/cisco_node_utils/node.rb +9 -0
- data/lib/cisco_node_utils/ntp_auth_key.rb +1 -1
- 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/portchannel_global.rb +2 -2
- data/lib/cisco_node_utils/radius_global.rb +25 -1
- data/lib/cisco_node_utils/router_ospf.rb +3 -3
- data/lib/cisco_node_utils/syslog_server.rb +38 -42
- data/lib/cisco_node_utils/syslog_settings.rb +74 -3
- data/lib/cisco_node_utils/tacacs_global.rb +47 -14
- data/lib/cisco_node_utils/tacacs_server.rb +1 -5
- data/lib/cisco_node_utils/version.rb +1 -1
- data/lib/cisco_node_utils/vpc.rb +1 -4
- data/lib/cisco_node_utils/vtp.rb +4 -2
- data/spec/schema.yaml +3 -0
- data/tests/ciscotest.rb +16 -9
- data/tests/test_ace.rb +2 -0
- data/tests/test_bgp_af.rb +10 -2
- data/tests/test_bgp_neighbor_af.rb +6 -2
- data/tests/test_bridge_domain.rb +7 -0
- data/tests/test_feature.rb +2 -2
- data/tests/test_interface.rb +30 -4
- data/tests/test_node_ext.rb +2 -2
- data/tests/test_object_group.rb +122 -0
- data/tests/test_platform.rb +1 -1
- data/tests/test_portchannel_global.rb +1 -0
- data/tests/test_radius_global.rb +22 -2
- data/tests/test_route_map.rb +11 -8
- data/tests/test_router_bgp.rb +7 -132
- data/tests/test_router_ospf_area.rb +6 -6
- data/tests/test_snmpuser.rb +19 -11
- data/tests/test_syslog_server.rb +11 -31
- data/tests/test_syslog_settings.rb +46 -5
- data/tests/test_tacacs_global.rb +42 -18
- data/tests/test_vpc.rb +3 -0
- data/tests/test_vxlan_vtep_vni.rb +0 -3
- data/tests/yum_package.yaml +5 -0
- metadata +21 -3
@@ -1,6 +1,6 @@
|
|
1
1
|
# March 2015, Alex Hunsberger
|
2
2
|
#
|
3
|
-
# Copyright (c) 2015-
|
3
|
+
# Copyright (c) 2015-2017 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.
|
@@ -53,7 +53,7 @@ module Cisco
|
|
53
53
|
fail TypeError unless ospf_name.is_a?(String) || ospf_name.nil?
|
54
54
|
ints = {}
|
55
55
|
|
56
|
-
intf_list = config_get('
|
56
|
+
intf_list = config_get('interface_ospf', 'all_interfaces')
|
57
57
|
return ints if intf_list.nil?
|
58
58
|
intf_list.each do |name|
|
59
59
|
match = config_get('interface_ospf', 'area', name)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# December 2015, Sai Chintalapudi
|
2
2
|
#
|
3
|
-
# Copyright (c) 2015-
|
3
|
+
# Copyright (c) 2015-2017 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.
|
@@ -38,7 +38,7 @@ module Cisco
|
|
38
38
|
|
39
39
|
def self.interfaces
|
40
40
|
hash = {}
|
41
|
-
intf_list = config_get('
|
41
|
+
intf_list = config_get('interface_portchannel', 'all_interfaces')
|
42
42
|
return hash if intf_list.nil?
|
43
43
|
|
44
44
|
intf_list.each do |id|
|
@@ -372,6 +372,15 @@ module Cisco
|
|
372
372
|
return prod.concat('-F') unless prod[/-F/]
|
373
373
|
end
|
374
374
|
end
|
375
|
+
when /N3K/
|
376
|
+
if @cmd_ref
|
377
|
+
ver = os_version
|
378
|
+
else
|
379
|
+
ver = get(command: 'show version',
|
380
|
+
data_format: :nxapi_structured)['kickstart_ver_str']
|
381
|
+
end
|
382
|
+
# Append -F for fretta platform.
|
383
|
+
return prod.concat('-F') if ver[/7.0\(3\)F/] && !prod[/-F/]
|
375
384
|
end
|
376
385
|
prod
|
377
386
|
end
|
@@ -16,7 +16,7 @@
|
|
16
16
|
# See the License for the specific language governing permissions and
|
17
17
|
# limitations under the License.
|
18
18
|
|
19
|
-
require_relative '
|
19
|
+
require_relative 'node_util'
|
20
20
|
|
21
21
|
module Cisco
|
22
22
|
# NtpAuthKey - node utility class for NTP authentication-key management
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#
|
2
|
+
# May 2017, Sai Chintalapudi
|
3
|
+
#
|
4
|
+
# Copyright (c) 2017 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 'acl'
|
20
|
+
|
21
|
+
module Cisco
|
22
|
+
# node_utils class for object_group
|
23
|
+
class ObjectGroup < NodeUtil
|
24
|
+
attr_reader :afi, :type, :grp_name
|
25
|
+
|
26
|
+
def initialize(afi, type, name, instantiate=true)
|
27
|
+
fail TypeError unless name.is_a?(String)
|
28
|
+
fail ArgumentError unless type[/address|port/]
|
29
|
+
@afi = Acl.afi_cli(afi)
|
30
|
+
@type = type
|
31
|
+
@grp_name = name
|
32
|
+
|
33
|
+
set_args_keys_default
|
34
|
+
create if instantiate
|
35
|
+
end
|
36
|
+
|
37
|
+
# Helper method to delete @set_args hash keys
|
38
|
+
def set_args_keys_default
|
39
|
+
@set_args = { afi: @afi, type: @type, grp_name: @grp_name }
|
40
|
+
@get_args = @set_args
|
41
|
+
end
|
42
|
+
|
43
|
+
# rubocop:disable Style/AccessorMethodName
|
44
|
+
def set_args_keys(hash={})
|
45
|
+
set_args_keys_default
|
46
|
+
@set_args = @get_args.merge!(hash) unless hash.empty?
|
47
|
+
end
|
48
|
+
|
49
|
+
def create
|
50
|
+
config_set('object_group', 'create', @set_args)
|
51
|
+
end
|
52
|
+
|
53
|
+
def destroy
|
54
|
+
config_set('object_group', 'destroy', @set_args)
|
55
|
+
end
|
56
|
+
|
57
|
+
def ==(other)
|
58
|
+
grp_name == other.grp_name && afi == other.afi && type == other.type
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.object_groups
|
62
|
+
hash = {}
|
63
|
+
grps = config_get('object_group', 'all_object_groups')
|
64
|
+
return hash if grps.nil?
|
65
|
+
grps.each do |afi, type, name|
|
66
|
+
lafi = afi
|
67
|
+
lafi = 'ipv4' if afi == 'ip'
|
68
|
+
hash[lafi] ||= {}
|
69
|
+
hash[lafi][type] ||= {}
|
70
|
+
hash[lafi][type][name] = ObjectGroup.new(lafi, type, name, false)
|
71
|
+
end
|
72
|
+
hash
|
73
|
+
end
|
74
|
+
end # class
|
75
|
+
end # module
|
@@ -0,0 +1,143 @@
|
|
1
|
+
#
|
2
|
+
# May 2017, Sai Chintalapudi
|
3
|
+
#
|
4
|
+
# Copyright (c) 2017 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 'acl'
|
20
|
+
require_relative 'object_group'
|
21
|
+
|
22
|
+
module Cisco
|
23
|
+
# node_utils class for object_group_entry
|
24
|
+
class ObjectGroupEntry < NodeUtil
|
25
|
+
attr_reader :afi, :type, :grp_name
|
26
|
+
|
27
|
+
def initialize(afi, type, name, seqno)
|
28
|
+
fail TypeError unless name.is_a?(String)
|
29
|
+
fail ArgumentError unless type[/address|port/]
|
30
|
+
@afi = Acl.afi_cli(afi)
|
31
|
+
@type = type
|
32
|
+
@grp_name = name
|
33
|
+
@seqno = seqno
|
34
|
+
og = ObjectGroup.object_groups[afi.to_s][type.to_s][name.to_s]
|
35
|
+
fail "ObjectGroup #{afi} #{type} #{name} does not exist" if
|
36
|
+
og.nil?
|
37
|
+
set_args_keys_default
|
38
|
+
end
|
39
|
+
|
40
|
+
# Helper method to delete @set_args hash keys
|
41
|
+
def set_args_keys_default
|
42
|
+
@set_args = { afi: @afi, type: @type, grp_name: @grp_name, seqno: @seqno }
|
43
|
+
@get_args = @set_args
|
44
|
+
end
|
45
|
+
|
46
|
+
# rubocop:disable Style/AccessorMethodName
|
47
|
+
def set_args_keys(hash={})
|
48
|
+
set_args_keys_default
|
49
|
+
@set_args = @get_args.merge!(hash) unless hash.empty?
|
50
|
+
end
|
51
|
+
|
52
|
+
def destroy
|
53
|
+
config_set('object_group', 'entry_destroy', @set_args)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.object_group_entries
|
57
|
+
hash = {}
|
58
|
+
grps = config_get('object_group', 'all_object_groups')
|
59
|
+
return hash if grps.nil?
|
60
|
+
grps.each do |afi, type, name|
|
61
|
+
lafi = afi
|
62
|
+
lafi = 'ipv4' if afi == 'ip'
|
63
|
+
hash[lafi] ||= {}
|
64
|
+
hash[lafi][type] ||= {}
|
65
|
+
hash[lafi][type][name] ||= {}
|
66
|
+
entries = config_get('object_group', 'all_entries',
|
67
|
+
afi: Acl.afi_cli(lafi),
|
68
|
+
type: type,
|
69
|
+
grp_name: name)
|
70
|
+
next if entries.nil?
|
71
|
+
entries.each do |seqno|
|
72
|
+
hash[lafi][type][name][seqno] =
|
73
|
+
ObjectGroupEntry.new(lafi, type, name, seqno)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
hash
|
77
|
+
end
|
78
|
+
|
79
|
+
def entry_get
|
80
|
+
str = config_get('object_group', 'entry', @get_args)
|
81
|
+
return nil if str.nil?
|
82
|
+
str = str.strip
|
83
|
+
|
84
|
+
# rubocop:disable Metrics/LineLength
|
85
|
+
regexp = Regexp.new('(?<seqno>\d+)'\
|
86
|
+
' *(?<address>host \S+|[:\.0-9a-fA-F]+ [:\.0-9a-fA-F]+|[:\.0-9a-fA-F]+\/\d+)?'\
|
87
|
+
' *(?<port>range \S+ \S+|(lt|eq|gt|neq) \S+)?')
|
88
|
+
# rubocop:enable Metrics/LineLength
|
89
|
+
regexp.match(str)
|
90
|
+
end
|
91
|
+
|
92
|
+
def entry_set(attrs)
|
93
|
+
if attrs.empty?
|
94
|
+
attrs[:state] = 'no'
|
95
|
+
else
|
96
|
+
destroy if seqno
|
97
|
+
attrs[:state] = ''
|
98
|
+
end
|
99
|
+
set_args_keys_default
|
100
|
+
set_args_keys(attrs)
|
101
|
+
[:address,
|
102
|
+
:port,
|
103
|
+
].each do |p|
|
104
|
+
attrs[p] = '' if attrs[p].nil?
|
105
|
+
send(p.to_s + '=', attrs[p])
|
106
|
+
end
|
107
|
+
@get_args = @set_args
|
108
|
+
config_set('object_group', 'entry', @set_args)
|
109
|
+
end
|
110
|
+
|
111
|
+
# PROPERTIES
|
112
|
+
# ----------
|
113
|
+
def seqno
|
114
|
+
match = entry_get
|
115
|
+
return nil if match.nil?
|
116
|
+
match.names.include?('seqno') ? match[:seqno] : nil
|
117
|
+
end
|
118
|
+
|
119
|
+
def address
|
120
|
+
match = entry_get
|
121
|
+
return nil if match.nil?
|
122
|
+
addr = match[:address]
|
123
|
+
return nil if addr.nil?
|
124
|
+
# Normalize addr. Some platforms zero_pad ipv6 addrs.
|
125
|
+
addr.gsub!(/^0*/, '').gsub!(/:0*/, ':')
|
126
|
+
addr
|
127
|
+
end
|
128
|
+
|
129
|
+
def address=(address)
|
130
|
+
@set_args[:address] = address
|
131
|
+
end
|
132
|
+
|
133
|
+
def port
|
134
|
+
match = entry_get
|
135
|
+
return nil if match.nil?
|
136
|
+
match.names.include?('port') ? match[:port] : nil
|
137
|
+
end
|
138
|
+
|
139
|
+
def port=(port)
|
140
|
+
@set_args[:port] = port
|
141
|
+
end
|
142
|
+
end # class
|
143
|
+
end # module
|
@@ -113,7 +113,7 @@ module Cisco
|
|
113
113
|
_parse_ethernet_params(hash, params)
|
114
114
|
when :asymmetric # n7k
|
115
115
|
_parse_asymmetric_params(hash, params, line)
|
116
|
-
when :no_hash # n9k-f
|
116
|
+
when :no_hash # n9k-f or n3k-f
|
117
117
|
_parse_no_hash_params(hash, params)
|
118
118
|
when :symmetry # n9k
|
119
119
|
_parse_symmetry_params(hash, params, line)
|
@@ -213,7 +213,7 @@ module Cisco
|
|
213
213
|
# port-channel load-balance dst ip-l4port rotate 4 asymmetric
|
214
214
|
config_set('portchannel_global', 'port_channel_load_balance',
|
215
215
|
bselect, bhash, 'rotate', rot.to_s, asym, '')
|
216
|
-
when :no_hash # n9k-f
|
216
|
+
when :no_hash # n9k-f or n3k-f
|
217
217
|
# port-channel load-balance dst ip-l4port rotate 4
|
218
218
|
rot_str = rot.zero? ? '' : 'rotate'
|
219
219
|
rot_val = rot.zero? ? '' : rot.to_s
|
@@ -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.
|
@@ -137,5 +137,29 @@ module Cisco
|
|
137
137
|
key: "#{value}")
|
138
138
|
end
|
139
139
|
end
|
140
|
+
|
141
|
+
# Get default source interface
|
142
|
+
def default_source_interface
|
143
|
+
config_get_default('radius_global', 'source_interface')
|
144
|
+
end
|
145
|
+
|
146
|
+
# Set source interface
|
147
|
+
def source_interface=(name)
|
148
|
+
if name
|
149
|
+
config_set(
|
150
|
+
'radius_global', 'source_interface',
|
151
|
+
state: '', source_interface: name)
|
152
|
+
else
|
153
|
+
config_set(
|
154
|
+
'radius_global', 'source_interface',
|
155
|
+
state: 'no', source_interface: '')
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# Get source interface
|
160
|
+
def source_interface
|
161
|
+
i = config_get('radius_global', 'source_interface')
|
162
|
+
i.nil? ? default_source_interface : i.downcase
|
163
|
+
end
|
140
164
|
end # class
|
141
165
|
end # module
|
@@ -38,9 +38,9 @@ module Cisco
|
|
38
38
|
hash[name] = RouterOspf.new(name, false)
|
39
39
|
end
|
40
40
|
return hash
|
41
|
-
rescue Cisco::CliError
|
42
|
-
# cmd will
|
43
|
-
raise
|
41
|
+
rescue Cisco::CliError
|
42
|
+
# cmd will error when feature 'ospf' is not enabled
|
43
|
+
raise if Feature.ospf_enabled?
|
44
44
|
return {}
|
45
45
|
end
|
46
46
|
|
@@ -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.
|
@@ -17,11 +17,12 @@
|
|
17
17
|
# limitations under the License.
|
18
18
|
|
19
19
|
require_relative 'node_util'
|
20
|
+
require 'resolv'
|
20
21
|
|
21
22
|
module Cisco
|
22
|
-
#
|
23
|
+
# SyslogServer - node utility class for syslog server configuration management
|
23
24
|
class SyslogServer < NodeUtil
|
24
|
-
attr_reader :name, :level, :vrf
|
25
|
+
attr_reader :name, :level, :port, :vrf, :severity_level
|
25
26
|
|
26
27
|
LEVEL_TO_NUM = { 'emergencies' => 0,
|
27
28
|
'alerts' => 1,
|
@@ -33,45 +34,38 @@ module Cisco
|
|
33
34
|
'debugging' => 7 }.freeze
|
34
35
|
NUM_TO_LEVEL = LEVEL_TO_NUM.invert.freeze
|
35
36
|
|
36
|
-
def initialize(
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
37
|
+
def initialize(opts, instantiate=true)
|
38
|
+
@name = opts['name']
|
39
|
+
@level = opts['level'] || opts['severity_level']
|
40
|
+
@port = opts['port']
|
41
|
+
@vrf = opts['vrf']
|
42
|
+
@severity_level = opts['severity_level'] || opts['level']
|
43
|
+
|
44
|
+
hostname_regex = /^(?=.{1,255}$)[0-9A-Za-z]
|
45
|
+
(?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?
|
46
|
+
(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/x
|
47
|
+
|
48
|
+
unless @name =~ Resolv::AddressRegex ||
|
49
|
+
@name =~ hostname_regex
|
50
|
+
fail ArgumentError,
|
51
|
+
"Invalid value '#{@name}' \
|
52
|
+
(Must be valid IPv4/IPv6 address or hostname)"
|
53
|
+
end
|
49
54
|
|
50
55
|
create if instantiate
|
51
56
|
end
|
52
57
|
|
53
58
|
def self.syslogservers
|
59
|
+
keys = %w(name level port vrf severity_level)
|
54
60
|
hash = {}
|
55
61
|
syslogservers_list = config_get('syslog_server', 'server')
|
56
62
|
return hash if syslogservers_list.nil?
|
57
63
|
|
58
64
|
syslogservers_list.each do |id|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
rescue
|
64
|
-
next
|
65
|
-
end
|
66
|
-
|
67
|
-
level = config_get('syslog_server', 'level', id)
|
68
|
-
level = level[0] if level.is_a?(Array)
|
69
|
-
level = LEVEL_TO_NUM[level] if platform == :ios_xr
|
70
|
-
|
71
|
-
vrf = config_get('syslog_server', 'vrf', id)
|
72
|
-
vrf = vrf[0] if vrf.is_a?(Array)
|
73
|
-
|
74
|
-
hash[id] = SyslogServer.new(id, level, vrf, false)
|
65
|
+
value_hash = Hash[keys.zip(id)]
|
66
|
+
value_hash['severity_level'] = value_hash['level']
|
67
|
+
value_hash['vrf'] = 'default' if value_hash['vrf'].nil?
|
68
|
+
hash[id[0]] = SyslogServer.new(value_hash, false)
|
75
69
|
end
|
76
70
|
|
77
71
|
hash
|
@@ -92,17 +86,18 @@ module Cisco
|
|
92
86
|
config_set('syslog_server',
|
93
87
|
'server',
|
94
88
|
state: '',
|
95
|
-
ip:
|
96
|
-
level: level
|
97
|
-
vrf: vrf
|
89
|
+
ip: @name,
|
90
|
+
level: @level ? "severity #{NUM_TO_LEVEL[@level]}" : '',
|
91
|
+
vrf: @vrf ? "vrf #{@vrf}" : '',
|
98
92
|
)
|
99
93
|
else
|
100
94
|
config_set('syslog_server',
|
101
95
|
'server',
|
102
96
|
state: '',
|
103
|
-
ip:
|
104
|
-
level: level
|
105
|
-
|
97
|
+
ip: @name,
|
98
|
+
level: @level ? "#{@level}" : '',
|
99
|
+
port: @port ? "port #{@port}" : '',
|
100
|
+
vrf: @vrf ? "use-vrf #{@vrf}" : '',
|
106
101
|
)
|
107
102
|
end
|
108
103
|
end
|
@@ -113,9 +108,9 @@ module Cisco
|
|
113
108
|
config_set('syslog_server',
|
114
109
|
'server',
|
115
110
|
state: 'no',
|
116
|
-
ip:
|
111
|
+
ip: @name,
|
117
112
|
level: '',
|
118
|
-
vrf: vrf
|
113
|
+
vrf: @vrf ? "vrf #{@vrf}" : '',
|
119
114
|
)
|
120
115
|
else
|
121
116
|
warn("#{name} is configured multiple times on the device" \
|
@@ -125,7 +120,7 @@ module Cisco
|
|
125
120
|
config_set('syslog_server',
|
126
121
|
'server',
|
127
122
|
state: 'no',
|
128
|
-
ip:
|
123
|
+
ip: @name,
|
129
124
|
level: '',
|
130
125
|
vrf: "vrf #{dup}",
|
131
126
|
)
|
@@ -135,8 +130,9 @@ module Cisco
|
|
135
130
|
config_set('syslog_server',
|
136
131
|
'server',
|
137
132
|
state: 'no',
|
138
|
-
ip:
|
133
|
+
ip: @name,
|
139
134
|
level: '',
|
135
|
+
port: '',
|
140
136
|
vrf: '',
|
141
137
|
)
|
142
138
|
end
|