cisco_node_utils 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +81 -1
- data/.travis.yml +9 -0
- data/CHANGELOG.md +72 -6
- data/CONTRIBUTING.md +32 -7
- data/README.md +70 -7
- data/Rakefile +17 -0
- data/bin/check_metric_limits.rb +109 -0
- data/bin/git/hooks/commit-msg/enforce_style +81 -0
- data/bin/git/hooks/hook_lib +108 -0
- data/bin/git/hooks/hooks-wrapper +38 -0
- data/bin/git/hooks/post-flow-hotfix-start/update-version +24 -0
- data/bin/git/hooks/post-flow-release-finish/update-version +29 -0
- data/bin/git/hooks/post-flow-release-start/update-version +19 -0
- data/bin/git/hooks/post-merge/update-hooks +6 -0
- data/bin/git/hooks/post-rewrite/update-hooks +6 -0
- data/bin/git/hooks/pre-commit/rubocop +20 -0
- data/bin/git/hooks/pre-commit/validate-diffs +31 -0
- data/bin/git/hooks/pre-push/check-changelog +24 -0
- data/bin/git/hooks/pre-push/rubocop +7 -0
- data/bin/git/update-hooks +65 -0
- data/cisco_node_utils.gemspec +9 -3
- data/docs/README-develop-best-practices.md +404 -0
- data/docs/README-develop-node-utils-APIs.md +215 -365
- data/docs/README-maintainers.md +33 -3
- data/docs/template-router.rb +89 -91
- data/docs/template-test_router.rb +52 -55
- data/lib/.rubocop.yml +18 -0
- data/lib/cisco_node_utils.rb +2 -19
- data/lib/cisco_node_utils/README_YAML.md +1 -9
- data/lib/cisco_node_utils/bgp.rb +664 -0
- data/lib/cisco_node_utils/bgp_af.rb +530 -0
- data/lib/cisco_node_utils/bgp_neighbor.rb +425 -0
- data/lib/cisco_node_utils/bgp_neighbor_af.rb +709 -0
- data/lib/cisco_node_utils/cisco_cmn_utils.rb +59 -25
- data/lib/cisco_node_utils/command_reference.rb +72 -74
- data/lib/cisco_node_utils/command_reference_common.yaml +174 -9
- data/lib/cisco_node_utils/command_reference_common_bgp.yaml +535 -0
- data/lib/cisco_node_utils/command_reference_n7k.yaml +4 -0
- data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -9
- data/lib/cisco_node_utils/configparser_lib.rb +152 -147
- data/lib/cisco_node_utils/dns_domain.rb +79 -0
- data/lib/cisco_node_utils/domain_name.rb +71 -0
- data/lib/cisco_node_utils/interface.rb +167 -161
- data/lib/cisco_node_utils/interface_ospf.rb +78 -81
- data/lib/cisco_node_utils/name_server.rb +64 -0
- data/lib/cisco_node_utils/node.rb +154 -198
- data/lib/cisco_node_utils/node_util.rb +61 -0
- data/lib/cisco_node_utils/ntp_config.rb +65 -0
- data/lib/cisco_node_utils/ntp_server.rb +76 -0
- data/lib/cisco_node_utils/platform.rb +174 -165
- data/lib/cisco_node_utils/radius_global.rb +146 -0
- data/lib/cisco_node_utils/radius_server.rb +295 -0
- data/lib/cisco_node_utils/router_ospf.rb +59 -63
- data/lib/cisco_node_utils/router_ospf_vrf.rb +226 -210
- data/lib/cisco_node_utils/snmpcommunity.rb +52 -58
- data/lib/cisco_node_utils/snmpgroup.rb +22 -23
- data/lib/cisco_node_utils/snmpserver.rb +99 -103
- data/lib/cisco_node_utils/snmpuser.rb +294 -274
- data/lib/cisco_node_utils/syslog_server.rb +92 -0
- data/lib/cisco_node_utils/syslog_settings.rb +69 -0
- data/lib/cisco_node_utils/tacacs_server.rb +137 -133
- data/lib/cisco_node_utils/tacacs_server_host.rb +84 -87
- data/lib/cisco_node_utils/version.rb +2 -1
- data/lib/cisco_node_utils/vlan.rb +28 -31
- data/lib/cisco_node_utils/vrf.rb +80 -0
- data/lib/cisco_node_utils/vtp.rb +100 -97
- data/lib/cisco_node_utils/yum.rb +15 -17
- data/tests/.rubocop.yml +15 -0
- data/tests/basetest.rb +81 -36
- data/tests/ciscotest.rb +38 -78
- data/{lib/cisco_node_utils → tests}/platform_info.rb +12 -8
- data/{lib/cisco_node_utils → tests}/platform_info.yaml +1 -1
- data/tests/test_bgp_af.rb +920 -0
- data/tests/test_bgp_neighbor.rb +403 -0
- data/tests/test_bgp_neighbor_af.rb +589 -0
- data/tests/test_command_config.rb +65 -62
- data/tests/test_command_reference.rb +31 -45
- data/tests/test_dns_domain.rb +113 -0
- data/tests/test_domain_name.rb +86 -0
- data/tests/test_interface.rb +424 -548
- data/tests/test_interface_ospf.rb +248 -432
- data/tests/test_interface_svi.rb +56 -79
- data/tests/test_interface_switchport.rb +196 -272
- data/tests/test_name_server.rb +85 -0
- data/tests/test_node.rb +7 -6
- data/tests/test_node_ext.rb +133 -186
- data/tests/test_ntp_config.rb +49 -0
- data/tests/test_ntp_server.rb +74 -0
- data/tests/test_platform.rb +58 -37
- data/tests/test_radius_global.rb +78 -0
- data/tests/test_radius_server.rb +185 -0
- data/tests/test_router_bgp.rb +838 -0
- data/tests/test_router_ospf.rb +49 -80
- data/tests/test_router_ospf_vrf.rb +274 -392
- data/tests/test_snmpcommunity.rb +128 -172
- data/tests/test_snmpgroup.rb +12 -14
- data/tests/test_snmpserver.rb +160 -189
- data/tests/test_snmpuser.rb +568 -717
- data/tests/test_syslog_server.rb +88 -0
- data/tests/test_syslog_settings.rb +54 -0
- data/tests/test_tacacs_server.rb +113 -148
- data/tests/test_tacacs_server_host.rb +108 -161
- data/tests/test_vlan.rb +63 -79
- data/tests/test_vrf.rb +92 -0
- data/tests/test_vtp.rb +108 -126
- data/tests/test_yum.rb +47 -41
- metadata +92 -56
- data/.rubocop_todo.yml +0 -293
- data/docs/.rubocop.yml +0 -13
- data/docs/template-feature.rb +0 -45
- data/docs/template-test_feature.rb +0 -51
- data/tests/test_all_cisco.rb +0 -46
@@ -1,5 +1,3 @@
|
|
1
|
-
# TacacsServerHost class
|
2
|
-
#
|
3
1
|
# Alex Hunsberger, March 2015
|
4
2
|
#
|
5
3
|
# Copyright (c) 2015 Cisco and/or its affiliates.
|
@@ -16,113 +14,112 @@
|
|
16
14
|
# See the License for the specific language governing permissions and
|
17
15
|
# limitations under the License.
|
18
16
|
|
19
|
-
|
20
|
-
|
17
|
+
require_relative 'node_util'
|
18
|
+
require_relative 'tacacs_server'
|
21
19
|
|
22
20
|
module Cisco
|
23
|
-
class
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
# feature Tacacs+ must be enabled to create a host
|
21
|
+
# TacacsServerHost - node utility class for TACACS+ server host config
|
22
|
+
class TacacsServerHost < NodeUtil
|
23
|
+
attr_reader :name
|
24
|
+
@hosts = {}
|
25
|
+
|
26
|
+
def initialize(name, create=true)
|
27
|
+
fail TypeError unless name.is_a? String
|
28
|
+
fail ArgumentError if name.empty?
|
29
|
+
@name = name
|
30
|
+
return unless create
|
31
|
+
# 'feature tacacs+' must be enabled to create a host
|
35
32
|
TacacsServer.new.enable unless TacacsServer.enabled
|
36
|
-
|
33
|
+
config_set('tacacs_server_host', 'host', '', name)
|
37
34
|
end
|
38
|
-
end
|
39
35
|
|
40
|
-
|
41
|
-
|
36
|
+
def self.hosts
|
37
|
+
@hosts = {}
|
42
38
|
|
43
|
-
|
39
|
+
return @hosts unless TacacsServer.enabled
|
44
40
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
41
|
+
hosts = config_get('tacacs_server_host', 'hosts')
|
42
|
+
unless hosts.nil?
|
43
|
+
hosts = [hosts] if hosts.is_a?(Hash)
|
44
|
+
hosts.each do |name|
|
45
|
+
@hosts[name] = TacacsServerHost.new(name, false) if @hosts[name].nil?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
@hosts
|
51
49
|
end
|
52
|
-
@@hosts
|
53
|
-
end
|
54
50
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
51
|
+
def destroy
|
52
|
+
config_set('tacacs_server_host', 'host', 'no', @name)
|
53
|
+
end
|
59
54
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
55
|
+
def port
|
56
|
+
p = config_get('tacacs_server_host', 'port', @name)
|
57
|
+
fail "unable to retrieve port information for #{@name}" if p.nil?
|
58
|
+
p.first.to_i
|
59
|
+
end
|
65
60
|
|
66
|
-
|
67
|
-
|
68
|
-
|
61
|
+
def port=(n)
|
62
|
+
config_set('tacacs_server_host', 'port', @name, n.to_i)
|
63
|
+
end
|
69
64
|
|
70
|
-
|
71
|
-
|
72
|
-
|
65
|
+
def self.default_port
|
66
|
+
config_get_default('tacacs_server_host', 'port')
|
67
|
+
end
|
73
68
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
69
|
+
def encryption_type
|
70
|
+
type = config_get('tacacs_server_host', 'encryption_type', @name)
|
71
|
+
type.nil? ? TACACS_SERVER_ENC_UNKNOWN : type.first.to_i
|
72
|
+
end
|
78
73
|
|
79
|
-
|
80
|
-
|
81
|
-
|
74
|
+
def self.default_encryption_type
|
75
|
+
TacacsServer.default_encryption_type
|
76
|
+
end
|
82
77
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
78
|
+
def encryption_password
|
79
|
+
pass = config_get('tacacs_server_host', 'encryption_password', @name)
|
80
|
+
pass.nil? ? TacacsServerHost.default_encryption_password : pass.first
|
81
|
+
end
|
87
82
|
|
88
|
-
|
89
|
-
|
90
|
-
|
83
|
+
def self.default_encryption_password
|
84
|
+
config_get_default('tacacs_server_host', 'encryption_password')
|
85
|
+
end
|
91
86
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
87
|
+
def encryption_key_set(enctype, password)
|
88
|
+
fail TypeError unless enctype.is_a? Fixnum
|
89
|
+
fail ArgumentError if password && ![TACACS_SERVER_ENC_NONE,
|
90
|
+
TACACS_SERVER_ENC_CISCO_TYPE_7,
|
91
|
+
TACACS_SERVER_ENC_UNKNOWN,
|
92
|
+
].include?(enctype)
|
93
|
+
# if enctype is TACACS_SERVER_ENC_UNKNOWN, we'll unset the key
|
94
|
+
if enctype == TACACS_SERVER_ENC_UNKNOWN
|
95
|
+
# if current encryption type is not TACACS_SERVER_ENC_UNKNOWN, we need
|
96
|
+
# to unset the key value. Otherwise, the box is not configured with key,
|
97
|
+
# thus we don't need to do anything
|
98
|
+
if encryption_type != TACACS_SERVER_ENC_UNKNOWN
|
99
|
+
config_set('tacacs_server_host', 'encryption', 'no', @name,
|
100
|
+
encryption_type,
|
101
|
+
encryption_password)
|
102
|
+
end
|
103
|
+
else
|
104
|
+
config_set('tacacs_server_host', 'encryption',
|
105
|
+
'', @name, enctype, password)
|
106
106
|
end
|
107
|
-
else
|
108
|
-
@@node.config_set("tacacs_server_host", "encryption", "", @name, enctype, password)
|
109
107
|
end
|
110
|
-
end
|
111
108
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
109
|
+
def timeout
|
110
|
+
t = config_get('tacacs_server_host', 'timeout', @name)
|
111
|
+
t.nil? ? TacacsServerHost.default_timeout : t.first.to_i
|
112
|
+
end
|
116
113
|
|
117
|
-
|
118
|
-
|
119
|
-
|
114
|
+
def timeout=(t)
|
115
|
+
fail TypeError unless t.is_a? Fixnum
|
116
|
+
return if t == timeout
|
120
117
|
|
121
|
-
|
122
|
-
|
118
|
+
config_set('tacacs_server_host', 'timeout', '', @name, t)
|
119
|
+
end
|
123
120
|
|
124
|
-
|
125
|
-
|
121
|
+
def self.default_timeout
|
122
|
+
config_get_default('tacacs_server_host', 'timeout')
|
123
|
+
end
|
126
124
|
end
|
127
125
|
end
|
128
|
-
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# VLAN provider class
|
2
|
-
#
|
3
1
|
# Jie Yang, November 2014
|
4
2
|
#
|
5
3
|
# Copyright (c) 2014-2015 Cisco and/or its affiliates.
|
@@ -16,29 +14,28 @@
|
|
16
14
|
# See the License for the specific language governing permissions and
|
17
15
|
# limitations under the License.
|
18
16
|
|
19
|
-
|
20
|
-
|
17
|
+
require_relative 'node_util'
|
18
|
+
require_relative 'interface'
|
21
19
|
|
20
|
+
# Add some Vlan-specific constants to the Cisco namespace
|
22
21
|
module Cisco
|
23
22
|
VLAN_NAME_SIZE = 33
|
24
23
|
|
25
|
-
class
|
24
|
+
# Vlan - node utility class for VLAN configuration management
|
25
|
+
class Vlan < NodeUtil
|
26
26
|
attr_reader :name, :vlan_id
|
27
27
|
|
28
|
-
@@node = Node.instance
|
29
|
-
raise TypeError if @@node.nil?
|
30
|
-
|
31
28
|
def initialize(vlan_id, instantiate=true)
|
32
29
|
@vlan_id = vlan_id.to_s
|
33
|
-
|
34
|
-
|
30
|
+
fail ArgumentError,
|
31
|
+
'Invalid value(non-numeric Vlan id)' unless @vlan_id[/^\d+$/]
|
35
32
|
|
36
33
|
create if instantiate
|
37
34
|
end
|
38
35
|
|
39
|
-
def
|
36
|
+
def self.vlans
|
40
37
|
hash = {}
|
41
|
-
vlan_list =
|
38
|
+
vlan_list = config_get('vlan', 'all_vlans')
|
42
39
|
return hash if vlan_list.nil?
|
43
40
|
|
44
41
|
vlan_list.each do |id|
|
@@ -48,11 +45,11 @@ module Cisco
|
|
48
45
|
end
|
49
46
|
|
50
47
|
def create
|
51
|
-
|
48
|
+
config_set('vlan', 'create', @vlan_id)
|
52
49
|
end
|
53
50
|
|
54
51
|
def destroy
|
55
|
-
|
52
|
+
config_set('vlan', 'destroy', @vlan_id)
|
56
53
|
end
|
57
54
|
|
58
55
|
def cli_error_check(result)
|
@@ -60,21 +57,21 @@ module Cisco
|
|
60
57
|
# instead just displays a STDOUT error message; thus NXAPI does not detect
|
61
58
|
# the failure and we must catch it by inspecting the "body" hash entry
|
62
59
|
# returned by NXAPI. This vlan cli behavior is unlikely to change.
|
63
|
-
|
60
|
+
fail result[2]['body'] unless result[2]['body'].empty?
|
64
61
|
end
|
65
62
|
|
66
63
|
def vlan_name
|
67
|
-
result =
|
64
|
+
result = config_get('vlan', 'name', @vlan_id)
|
68
65
|
return default_vlan_name if result.nil?
|
69
66
|
result.shift
|
70
67
|
end
|
71
68
|
|
72
69
|
def vlan_name=(str)
|
73
|
-
|
70
|
+
fail TypeError unless str.is_a?(String)
|
74
71
|
if str.empty?
|
75
|
-
result =
|
72
|
+
result = config_set('vlan', 'name', @vlan_id, 'no', '')
|
76
73
|
else
|
77
|
-
result =
|
74
|
+
result = config_set('vlan', 'name', @vlan_id, '', str)
|
78
75
|
end
|
79
76
|
cli_error_check(result)
|
80
77
|
rescue CliError => e
|
@@ -82,26 +79,26 @@ module Cisco
|
|
82
79
|
end
|
83
80
|
|
84
81
|
def default_vlan_name
|
85
|
-
|
82
|
+
sprintf('VLAN%04d', @vlan_id)
|
86
83
|
end
|
87
84
|
|
88
85
|
def state
|
89
|
-
result =
|
86
|
+
result = config_get('vlan', 'state', @vlan_id)
|
90
87
|
return default_state if result.nil?
|
91
88
|
case result.first
|
92
89
|
when /act/
|
93
|
-
return
|
90
|
+
return 'active'
|
94
91
|
when /sus/
|
95
|
-
return
|
92
|
+
return 'suspend'
|
96
93
|
end
|
97
94
|
end
|
98
95
|
|
99
96
|
def state=(str)
|
100
97
|
str = str.to_s
|
101
98
|
if str.empty?
|
102
|
-
result =
|
99
|
+
result = config_set('vlan', 'state', @vlan_id, 'no', '')
|
103
100
|
else
|
104
|
-
result =
|
101
|
+
result = config_set('vlan', 'state', @vlan_id, '', str)
|
105
102
|
end
|
106
103
|
cli_error_check(result)
|
107
104
|
rescue CliError => e
|
@@ -109,26 +106,26 @@ module Cisco
|
|
109
106
|
end
|
110
107
|
|
111
108
|
def default_state
|
112
|
-
|
109
|
+
config_get_default('vlan', 'state')
|
113
110
|
end
|
114
111
|
|
115
112
|
def shutdown
|
116
|
-
result =
|
113
|
+
result = config_get('vlan', 'shutdown', @vlan_id)
|
117
114
|
return default_shutdown if result.nil?
|
118
|
-
#
|
115
|
+
# Valid result is either: "active"(aka no shutdown) or "shutdown"
|
119
116
|
result.first[/shut/] ? true : false
|
120
117
|
end
|
121
118
|
|
122
119
|
def shutdown=(val)
|
123
|
-
no_cmd = (val) ?
|
124
|
-
result =
|
120
|
+
no_cmd = (val) ? '' : 'no'
|
121
|
+
result = config_set('vlan', 'shutdown', @vlan_id, no_cmd)
|
125
122
|
cli_error_check(result)
|
126
123
|
rescue CliError => e
|
127
124
|
raise "[vlan #{@vlan_id}] '#{e.command}' : #{e.clierror}"
|
128
125
|
end
|
129
126
|
|
130
127
|
def default_shutdown
|
131
|
-
|
128
|
+
config_get_default('vlan', 'shutdown')
|
132
129
|
end
|
133
130
|
|
134
131
|
def add_interface(interface)
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# VRF provider class
|
2
|
+
#
|
3
|
+
# Jie Yang, July 2015
|
4
|
+
#
|
5
|
+
# Copyright (c) 2015 Cisco and/or its affiliates.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
|
19
|
+
require_relative 'node_util'
|
20
|
+
|
21
|
+
module Cisco
|
22
|
+
# Vrf - node utility class for VRF configuration management
|
23
|
+
class Vrf < NodeUtil
|
24
|
+
attr_reader :name
|
25
|
+
|
26
|
+
def initialize(name, instantiate=true)
|
27
|
+
fail TypeError unless name.is_a?(String)
|
28
|
+
@name = name.downcase.strip
|
29
|
+
@args = { vrf: @name }
|
30
|
+
create if instantiate
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.vrfs
|
34
|
+
hash = {}
|
35
|
+
vrf_list = config_get('vrf', 'all_vrfs')
|
36
|
+
return hash if vrf_list.nil?
|
37
|
+
|
38
|
+
vrf_list.each do |id|
|
39
|
+
id = id.downcase.strip
|
40
|
+
hash[id] = Vrf.new(id, false)
|
41
|
+
end
|
42
|
+
hash
|
43
|
+
end
|
44
|
+
|
45
|
+
def create
|
46
|
+
config_set('vrf', 'create', @args)
|
47
|
+
end
|
48
|
+
|
49
|
+
def destroy
|
50
|
+
config_set('vrf', 'destroy', @args)
|
51
|
+
end
|
52
|
+
|
53
|
+
def description
|
54
|
+
desc = config_get('vrf', 'description', @args)
|
55
|
+
return '' if desc.nil?
|
56
|
+
desc.shift.strip
|
57
|
+
end
|
58
|
+
|
59
|
+
def description=(desc)
|
60
|
+
fail TypeError unless desc.is_a?(String)
|
61
|
+
desc.strip!
|
62
|
+
no_cmd = desc.empty? ? 'no' : ''
|
63
|
+
config_set('vrf', 'description', vrf: @name, state: no_cmd, desc: desc)
|
64
|
+
rescue Cisco::CliError => e
|
65
|
+
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
|
66
|
+
end
|
67
|
+
|
68
|
+
def shutdown
|
69
|
+
result = config_get('vrf', 'shutdown', @args)
|
70
|
+
result ? true : false
|
71
|
+
end
|
72
|
+
|
73
|
+
def shutdown=(val)
|
74
|
+
no_cmd = (val) ? '' : 'no'
|
75
|
+
config_set('vrf', 'shutdown', vrf: @name, state: no_cmd)
|
76
|
+
rescue Cisco::CliError => e
|
77
|
+
raise "[vrf #{@name}] '#{e.command}' : #{e.clierror}"
|
78
|
+
end
|
79
|
+
end # class
|
80
|
+
end # module
|
data/lib/cisco_node_utils/vtp.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# VTP provider class
|
2
|
-
#
|
3
1
|
# Mike Wiebe, November 2014
|
4
2
|
#
|
5
3
|
# Copyright (c) 2014-2015 Cisco and/or its affiliates.
|
@@ -16,121 +14,126 @@
|
|
16
14
|
# See the License for the specific language governing permissions and
|
17
15
|
# limitations under the License.
|
18
16
|
|
19
|
-
|
17
|
+
require_relative 'node_util'
|
20
18
|
|
21
19
|
module Cisco
|
22
|
-
class
|
23
|
-
|
24
|
-
|
25
|
-
MAX_VTP_DOMAIN_NAME_SIZE = 32
|
26
|
-
MAX_VTP_PASSWORD_SIZE = 64
|
20
|
+
# Vtp - node utility class for VTP configuration management
|
21
|
+
class Vtp < NodeUtil
|
22
|
+
attr_reader :name
|
27
23
|
|
28
|
-
|
24
|
+
MAX_VTP_DOMAIN_NAME_SIZE = 32
|
25
|
+
MAX_VTP_PASSWORD_SIZE = 64
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
# Constructor for Vtp
|
28
|
+
def initialize(instantiate=true)
|
29
|
+
enable if instantiate && !Vtp.enabled
|
30
|
+
end
|
34
31
|
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
def self.enabled
|
33
|
+
!config_get('vtp', 'feature').nil?
|
34
|
+
end
|
38
35
|
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
def enable
|
37
|
+
config_set('vtp', 'feature', '')
|
38
|
+
end
|
42
39
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
40
|
+
# Disable vtp feature
|
41
|
+
def destroy
|
42
|
+
config_set('vtp', 'feature', 'no')
|
43
|
+
end
|
47
44
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
45
|
+
# Get vtp domain name
|
46
|
+
def self.domain
|
47
|
+
enabled ? config_get('vtp', 'domain') : ''
|
48
|
+
end
|
52
49
|
|
53
|
-
|
54
|
-
|
55
|
-
|
50
|
+
def domain
|
51
|
+
Vtp.domain
|
52
|
+
end
|
56
53
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
54
|
+
# Set vtp domain name
|
55
|
+
def domain=(d)
|
56
|
+
fail ArgumentError unless d && d.is_a?(String) &&
|
57
|
+
d.length.between?(1, MAX_VTP_DOMAIN_NAME_SIZE)
|
58
|
+
enable unless Vtp.enabled
|
59
|
+
begin
|
60
|
+
config_set('vtp', 'domain', d)
|
61
|
+
rescue Cisco::CliError => e
|
62
|
+
# cmd will syntax reject when setting name to same name
|
63
|
+
raise unless e.clierror =~ /ERROR: Domain name already set to /
|
64
|
+
end
|
67
65
|
end
|
68
|
-
end
|
69
66
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
67
|
+
# Get vtp password
|
68
|
+
def password
|
69
|
+
# Unfortunately nxapi returns "\\" when the password is not set
|
70
|
+
password = config_get('vtp', 'password') if Vtp.enabled
|
71
|
+
return '' if password.nil? || password == '\\'
|
72
|
+
password
|
73
|
+
end
|
77
74
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
75
|
+
# Set vtp password
|
76
|
+
def password=(password)
|
77
|
+
fail TypeError if password.nil?
|
78
|
+
fail TypeError unless password.is_a? String
|
79
|
+
fail ArgumentError if password.length > MAX_VTP_PASSWORD_SIZE
|
80
|
+
enable unless Vtp.enabled
|
81
|
+
begin
|
82
|
+
if password == default_password
|
83
|
+
config_set('vtp', 'password', 'no', '')
|
84
|
+
else
|
85
|
+
config_set('vtp', 'password', '', password)
|
86
|
+
end
|
87
|
+
rescue Cisco::CliError => e
|
88
|
+
raise unless e.clierror =~ /password cannot be set for NULL domain/
|
89
|
+
unless password == default_password
|
90
|
+
raise 'Setting VTP password requires first setting VTP domain'
|
91
|
+
end
|
92
|
+
end
|
91
93
|
end
|
92
|
-
end
|
93
94
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
95
|
+
# Get default vtp password
|
96
|
+
def default_password
|
97
|
+
config_get_default('vtp', 'password')
|
98
|
+
end
|
98
99
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
100
|
+
# Get vtp filename
|
101
|
+
def filename
|
102
|
+
match = config_get('vtp', 'filename')
|
103
|
+
match.nil? ? default_filename : match.first
|
104
|
+
end
|
104
105
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
106
|
+
# Set vtp filename
|
107
|
+
def filename=(uri)
|
108
|
+
fail TypeError if uri.nil?
|
109
|
+
enable unless Vtp.enabled
|
110
|
+
if uri.empty?
|
111
|
+
config_set('vtp', 'filename', 'no', '')
|
112
|
+
else
|
113
|
+
config_set('vtp', 'filename', '', uri)
|
114
|
+
end
|
115
|
+
end
|
113
116
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
117
|
+
# Get default vtp filename
|
118
|
+
def default_filename
|
119
|
+
config_get_default('vtp', 'filename')
|
120
|
+
end
|
118
121
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
122
|
+
# Get vtp version
|
123
|
+
def version
|
124
|
+
match = config_get('vtp', 'version') if Vtp.enabled
|
125
|
+
match.nil? ? default_version : match.first.to_i
|
126
|
+
end
|
124
127
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
128
|
+
# Set vtp version
|
129
|
+
def version=(version)
|
130
|
+
enable unless Vtp.enabled
|
131
|
+
config_set('vtp', 'version', "#{version}")
|
132
|
+
end
|
130
133
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
+
# Get default vtp version
|
135
|
+
def default_version
|
136
|
+
config_get_default('vtp', 'version')
|
137
|
+
end
|
134
138
|
end
|
135
139
|
end
|
136
|
-
end
|