cisco_node_utils 1.0.1 → 1.1.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 +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,6 +1,3 @@
|
|
|
1
|
-
#
|
|
2
|
-
# NXAPI implementation of Interface class
|
|
3
|
-
#
|
|
4
1
|
# November 2015, Chris Van Heuveln
|
|
5
2
|
#
|
|
6
3
|
# Copyright (c) 2015 Cisco and/or its affiliates.
|
|
@@ -17,33 +14,33 @@
|
|
|
17
14
|
# See the License for the specific language governing permissions and
|
|
18
15
|
# limitations under the License.
|
|
19
16
|
|
|
20
|
-
|
|
17
|
+
require_relative 'node_util'
|
|
21
18
|
|
|
19
|
+
# Add some interface-specific constants to the Cisco namespace
|
|
22
20
|
module Cisco
|
|
23
21
|
IF_SWITCHPORT_MODE = {
|
|
24
|
-
:
|
|
25
|
-
:
|
|
26
|
-
:
|
|
27
|
-
:
|
|
28
|
-
:
|
|
22
|
+
disabled: '',
|
|
23
|
+
access: 'access',
|
|
24
|
+
trunk: 'trunk',
|
|
25
|
+
fex_fabric: 'fex-fabric',
|
|
26
|
+
tunnel: 'dot1q-tunnel',
|
|
29
27
|
}
|
|
30
28
|
|
|
31
|
-
class
|
|
29
|
+
# Interface - node utility class for general interface config management
|
|
30
|
+
class Interface < NodeUtil
|
|
32
31
|
attr_reader :name
|
|
33
32
|
|
|
34
|
-
@@node = Cisco::Node.instance
|
|
35
|
-
|
|
36
33
|
def initialize(name, instantiate=true)
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
fail TypeError unless name.is_a?(String)
|
|
35
|
+
fail ArgumentError unless name.length > 0
|
|
39
36
|
@name = name.downcase
|
|
40
37
|
|
|
41
38
|
create if instantiate
|
|
42
39
|
end
|
|
43
40
|
|
|
44
|
-
def
|
|
41
|
+
def self.interfaces
|
|
45
42
|
hash = {}
|
|
46
|
-
intf_list =
|
|
43
|
+
intf_list = config_get('interface', 'all_interfaces')
|
|
47
44
|
return hash if intf_list.nil?
|
|
48
45
|
|
|
49
46
|
intf_list.each do |id|
|
|
@@ -55,11 +52,11 @@ module Cisco
|
|
|
55
52
|
|
|
56
53
|
def create
|
|
57
54
|
feature_vlan_set(true) if @name[/vlan/i]
|
|
58
|
-
|
|
55
|
+
config_set('interface', 'create', @name)
|
|
59
56
|
end
|
|
60
57
|
|
|
61
58
|
def destroy
|
|
62
|
-
|
|
59
|
+
config_set('interface', 'destroy', @name)
|
|
63
60
|
end
|
|
64
61
|
|
|
65
62
|
########################################################
|
|
@@ -67,61 +64,65 @@ module Cisco
|
|
|
67
64
|
########################################################
|
|
68
65
|
|
|
69
66
|
def access_vlan
|
|
70
|
-
vlan =
|
|
67
|
+
vlan = config_get('interface', 'access_vlan', @name)
|
|
71
68
|
return default_access_vlan if vlan.nil?
|
|
72
69
|
vlan.shift.to_i
|
|
73
70
|
end
|
|
74
71
|
|
|
75
72
|
def access_vlan=(vlan)
|
|
76
|
-
|
|
73
|
+
config_set('interface', 'access_vlan', @name, vlan)
|
|
77
74
|
rescue Cisco::CliError => e
|
|
78
75
|
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
|
|
79
76
|
end
|
|
80
77
|
|
|
81
78
|
def default_access_vlan
|
|
82
|
-
|
|
79
|
+
config_get_default('interface', 'access_vlan')
|
|
83
80
|
end
|
|
84
81
|
|
|
85
82
|
def description
|
|
86
|
-
desc =
|
|
87
|
-
return
|
|
83
|
+
desc = config_get('interface', 'description', @name)
|
|
84
|
+
return '' if desc.nil?
|
|
88
85
|
desc.shift.strip
|
|
89
86
|
end
|
|
90
87
|
|
|
91
88
|
def description=(desc)
|
|
92
|
-
|
|
93
|
-
desc.empty?
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
fail TypeError unless desc.is_a?(String)
|
|
90
|
+
if desc.strip.empty?
|
|
91
|
+
config_set('interface', 'description', @name, 'no', '')
|
|
92
|
+
else
|
|
93
|
+
config_set('interface', 'description', @name, '', desc)
|
|
94
|
+
end
|
|
96
95
|
rescue Cisco::CliError => e
|
|
97
96
|
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
|
|
98
97
|
end
|
|
99
98
|
|
|
100
99
|
def default_description
|
|
101
|
-
|
|
100
|
+
config_get_default('interface', 'description')
|
|
102
101
|
end
|
|
103
102
|
|
|
104
103
|
def encapsulation_dot1q
|
|
105
|
-
val =
|
|
104
|
+
val = config_get('interface', 'encapsulation_dot1q', @name)
|
|
106
105
|
return default_encapsulation_dot1q if val.nil?
|
|
107
106
|
val.shift.strip.to_i
|
|
108
107
|
end
|
|
109
108
|
|
|
110
109
|
def encapsulation_dot1q=(val)
|
|
111
|
-
val.
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
if val.to_s.empty?
|
|
111
|
+
config_set('interface', 'encapsulation_dot1q', @name, 'no', '')
|
|
112
|
+
else
|
|
113
|
+
config_set('interface', 'encapsulation_dot1q', @name, '', val)
|
|
114
|
+
end
|
|
114
115
|
rescue Cisco::CliError => e
|
|
115
116
|
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
|
|
116
117
|
end
|
|
117
118
|
|
|
118
119
|
def default_encapsulation_dot1q
|
|
119
|
-
|
|
120
|
+
config_get_default('interface', 'encapsulation_dot1q')
|
|
120
121
|
end
|
|
121
122
|
|
|
122
123
|
def fex_feature
|
|
123
|
-
fex =
|
|
124
|
-
|
|
124
|
+
fex = config_get('fex', 'feature')
|
|
125
|
+
fail 'fex_feature not found' if fex.nil?
|
|
125
126
|
fex.shift.to_sym
|
|
126
127
|
end
|
|
127
128
|
|
|
@@ -131,32 +132,32 @@ module Cisco
|
|
|
131
132
|
|
|
132
133
|
case fex_set
|
|
133
134
|
when :enabled
|
|
134
|
-
|
|
135
|
-
|
|
135
|
+
config_set('fex', 'feature_install', '') if curr == :uninstalled
|
|
136
|
+
config_set('fex', 'feature', '')
|
|
136
137
|
when :disabled
|
|
137
|
-
|
|
138
|
+
config_set('fex', 'feature', 'no') if curr == :enabled
|
|
138
139
|
return
|
|
139
140
|
when :installed
|
|
140
|
-
|
|
141
|
+
config_set('fex', 'feature_install', '') if curr == :uninstalled
|
|
141
142
|
when :uninstalled
|
|
142
|
-
|
|
143
|
-
|
|
143
|
+
config_set('fex', 'feature', 'no') if curr == :enabled
|
|
144
|
+
config_set('fex', 'feature_install', 'no')
|
|
144
145
|
end
|
|
145
146
|
rescue Cisco::CliError => e
|
|
146
147
|
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
|
|
147
148
|
end
|
|
148
149
|
|
|
149
150
|
def ipv4_addr_mask
|
|
150
|
-
|
|
151
|
+
config_get('interface', 'ipv4_addr_mask', @name)
|
|
151
152
|
end
|
|
152
153
|
|
|
153
154
|
def ipv4_addr_mask_set(addr, mask)
|
|
154
155
|
check_switchport_disabled
|
|
155
|
-
if addr.nil?
|
|
156
|
-
|
|
156
|
+
if addr.nil? || addr == default_ipv4_address
|
|
157
|
+
config_set('interface', 'ipv4_addr_mask', @name, 'no', '')
|
|
157
158
|
else
|
|
158
|
-
|
|
159
|
-
|
|
159
|
+
config_set('interface', 'ipv4_addr_mask', @name, '',
|
|
160
|
+
"#{addr}/#{mask}")
|
|
160
161
|
end
|
|
161
162
|
rescue Cisco::CliError => e
|
|
162
163
|
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
|
|
@@ -165,116 +166,115 @@ module Cisco
|
|
|
165
166
|
def ipv4_address
|
|
166
167
|
val = ipv4_addr_mask
|
|
167
168
|
return default_ipv4_address if val.nil?
|
|
168
|
-
addr, mask
|
|
169
|
-
|
|
169
|
+
# val is [[addr, mask]] - we just want the addr
|
|
170
|
+
val.shift.first
|
|
170
171
|
end
|
|
171
172
|
|
|
172
173
|
def default_ipv4_address
|
|
173
|
-
|
|
174
|
+
config_get_default('interface', 'ipv4_address')
|
|
174
175
|
end
|
|
175
176
|
|
|
176
177
|
def ipv4_netmask_length
|
|
177
178
|
val = ipv4_addr_mask
|
|
178
179
|
return default_ipv4_netmask_length if val.nil?
|
|
179
|
-
addr, mask
|
|
180
|
-
|
|
180
|
+
# val is [[addr, mask]] - we just want the mask
|
|
181
|
+
val.shift.last.to_i
|
|
181
182
|
end
|
|
182
183
|
|
|
183
184
|
def default_ipv4_netmask_length
|
|
184
|
-
|
|
185
|
+
config_get_default('interface', 'ipv4_netmask_length')
|
|
185
186
|
end
|
|
186
187
|
|
|
187
188
|
def ipv4_proxy_arp
|
|
188
|
-
state =
|
|
189
|
+
state = config_get('interface', 'ipv4_proxy_arp', @name)
|
|
189
190
|
state.nil? ? false : true
|
|
190
191
|
end
|
|
191
192
|
|
|
192
193
|
def ipv4_proxy_arp=(proxy_arp)
|
|
193
194
|
check_switchport_disabled
|
|
194
|
-
no_cmd = (proxy_arp ?
|
|
195
|
-
|
|
195
|
+
no_cmd = (proxy_arp ? '' : 'no')
|
|
196
|
+
config_set('interface', 'ipv4_proxy_arp', @name, no_cmd)
|
|
196
197
|
end
|
|
197
198
|
|
|
198
199
|
def default_ipv4_proxy_arp
|
|
199
|
-
|
|
200
|
+
config_get_default('interface', 'ipv4_proxy_arp')
|
|
200
201
|
end
|
|
201
202
|
|
|
202
203
|
def ipv4_redirects_lookup_string
|
|
203
204
|
case @name
|
|
204
205
|
when /loopback/i
|
|
205
|
-
return
|
|
206
|
+
return 'ipv4_redirects_loopback'
|
|
206
207
|
else
|
|
207
|
-
return
|
|
208
|
+
return 'ipv4_redirects_other_interfaces'
|
|
208
209
|
end
|
|
209
210
|
end
|
|
210
211
|
|
|
211
212
|
def ipv4_redirects
|
|
212
213
|
begin
|
|
213
|
-
state =
|
|
214
|
-
|
|
214
|
+
state = config_get('interface',
|
|
215
|
+
ipv4_redirects_lookup_string, @name)
|
|
215
216
|
rescue IndexError
|
|
216
217
|
state = nil
|
|
217
218
|
end
|
|
218
219
|
# We return default state for the platform if the platform doesn't support
|
|
219
220
|
# the command
|
|
220
|
-
return default_ipv4_redirects if state.nil?
|
|
221
|
+
return default_ipv4_redirects if state.nil? || state.empty?
|
|
221
222
|
state.shift[/^ip redirects$/] ? true : false
|
|
222
223
|
end
|
|
223
224
|
|
|
224
225
|
def ipv4_redirects=(redirects)
|
|
225
226
|
check_switchport_disabled
|
|
226
|
-
no_cmd = (redirects ?
|
|
227
|
-
|
|
227
|
+
no_cmd = (redirects ? '' : 'no')
|
|
228
|
+
config_set('interface', ipv4_redirects_lookup_string, @name, no_cmd)
|
|
228
229
|
rescue IndexError
|
|
229
230
|
raise "ipv4 redirects not supported on #{@name}"
|
|
230
231
|
end
|
|
231
232
|
|
|
232
233
|
def default_ipv4_redirects
|
|
233
|
-
|
|
234
|
+
config_get_default('interface', ipv4_redirects_lookup_string)
|
|
234
235
|
end
|
|
235
236
|
|
|
236
237
|
def feature_lacp?
|
|
237
|
-
|
|
238
|
+
!config_get('interface', 'feature_lacp').nil?
|
|
238
239
|
end
|
|
239
240
|
|
|
240
241
|
def feature_lacp_set(val)
|
|
241
242
|
return if feature_lacp? == val
|
|
242
|
-
|
|
243
|
+
config_set('interface', 'feature_lacp', val ? '' : 'no')
|
|
243
244
|
end
|
|
244
245
|
|
|
245
246
|
def mtu
|
|
246
|
-
mtu =
|
|
247
|
+
mtu = config_get('interface', 'mtu', @name)
|
|
247
248
|
return default_mtu if mtu.nil?
|
|
248
249
|
mtu.shift.strip.to_i
|
|
249
250
|
end
|
|
250
251
|
|
|
251
|
-
def mtu=(
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
@@node.config_set("interface", "mtu", @name, "", mtu)
|
|
252
|
+
def mtu=(val)
|
|
253
|
+
check_switchport_disabled
|
|
254
|
+
config_set('interface', 'mtu', @name, '', val)
|
|
255
255
|
rescue Cisco::CliError => e
|
|
256
256
|
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
|
|
257
257
|
end
|
|
258
258
|
|
|
259
259
|
def default_mtu
|
|
260
|
-
|
|
260
|
+
config_get_default('interface', 'mtu')
|
|
261
261
|
end
|
|
262
262
|
|
|
263
263
|
def negotiate_auto_lookup_string
|
|
264
264
|
case @name
|
|
265
265
|
when /Ethernet/i
|
|
266
|
-
return
|
|
266
|
+
return 'negotiate_auto_ethernet'
|
|
267
267
|
when /port-channel/i # Ether-channel
|
|
268
|
-
return
|
|
268
|
+
return 'negotiate_auto_portchannel'
|
|
269
269
|
else
|
|
270
|
-
return
|
|
270
|
+
return 'negotiate_auto_other_interfaces'
|
|
271
271
|
end
|
|
272
272
|
end
|
|
273
273
|
|
|
274
274
|
def negotiate_auto
|
|
275
275
|
lookup = negotiate_auto_lookup_string
|
|
276
276
|
begin
|
|
277
|
-
state =
|
|
277
|
+
state = config_get('interface', lookup, @name)
|
|
278
278
|
rescue IndexError
|
|
279
279
|
# We return default state even if the config_get is not supported
|
|
280
280
|
# for this platform / interface type. This is done so that we can set
|
|
@@ -287,9 +287,9 @@ module Cisco
|
|
|
287
287
|
|
|
288
288
|
def negotiate_auto=(negotiate_auto)
|
|
289
289
|
lookup = negotiate_auto_lookup_string
|
|
290
|
-
no_cmd = (negotiate_auto ?
|
|
290
|
+
no_cmd = (negotiate_auto ? '' : 'no')
|
|
291
291
|
begin
|
|
292
|
-
|
|
292
|
+
config_set('interface', lookup, @name, no_cmd)
|
|
293
293
|
rescue Cisco::CliError => e
|
|
294
294
|
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
|
|
295
295
|
rescue IndexError
|
|
@@ -298,17 +298,17 @@ module Cisco
|
|
|
298
298
|
end
|
|
299
299
|
|
|
300
300
|
def default_negotiate_auto
|
|
301
|
-
|
|
301
|
+
config_get_default('interface', negotiate_auto_lookup_string)
|
|
302
302
|
end
|
|
303
303
|
|
|
304
304
|
def shutdown
|
|
305
|
-
state =
|
|
305
|
+
state = config_get('interface', 'shutdown', @name)
|
|
306
306
|
state ? true : false
|
|
307
307
|
end
|
|
308
308
|
|
|
309
309
|
def shutdown=(state)
|
|
310
|
-
no_cmd = (state ?
|
|
311
|
-
|
|
310
|
+
no_cmd = (state ? '' : 'no')
|
|
311
|
+
config_set('interface', 'shutdown', @name, no_cmd)
|
|
312
312
|
rescue Cisco::CliError => e
|
|
313
313
|
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
|
|
314
314
|
end
|
|
@@ -319,75 +319,75 @@ module Cisco
|
|
|
319
319
|
def_sw = system_default_switchport
|
|
320
320
|
def_shut = system_default_switchport_shutdown
|
|
321
321
|
|
|
322
|
-
if def_sw
|
|
323
|
-
lookup =
|
|
324
|
-
elsif def_sw
|
|
325
|
-
lookup =
|
|
326
|
-
elsif
|
|
327
|
-
lookup =
|
|
328
|
-
elsif
|
|
329
|
-
lookup =
|
|
322
|
+
if def_sw && def_shut
|
|
323
|
+
lookup = 'shutdown_ethernet_switchport_shutdown'
|
|
324
|
+
elsif def_sw && !def_shut
|
|
325
|
+
lookup = 'shutdown_ethernet_switchport_noshutdown'
|
|
326
|
+
elsif !def_sw && def_shut
|
|
327
|
+
lookup = 'shutdown_ethernet_noswitchport_shutdown'
|
|
328
|
+
elsif !def_sw && !def_shut
|
|
329
|
+
lookup = 'shutdown_ethernet_noswitchport_noshutdown'
|
|
330
330
|
else
|
|
331
|
-
|
|
331
|
+
fail "Error: def_sw #{def_sw}, def_shut #{def_shut}"
|
|
332
332
|
end
|
|
333
333
|
|
|
334
334
|
when /loopback/i
|
|
335
|
-
lookup =
|
|
335
|
+
lookup = 'shutdown_loopback'
|
|
336
336
|
|
|
337
|
-
when /port-channel/i
|
|
338
|
-
lookup =
|
|
337
|
+
when /port-channel/i # EtherChannel
|
|
338
|
+
lookup = 'shutdown_ether_channel'
|
|
339
339
|
|
|
340
340
|
when /Vlan/i
|
|
341
|
-
lookup =
|
|
341
|
+
lookup = 'shutdown_vlan'
|
|
342
342
|
|
|
343
343
|
else
|
|
344
|
-
lookup =
|
|
344
|
+
lookup = 'shutdown_unknown'
|
|
345
345
|
end
|
|
346
|
-
|
|
346
|
+
config_get_default('interface', lookup)
|
|
347
347
|
end
|
|
348
348
|
|
|
349
349
|
def switchport
|
|
350
350
|
# This is "switchport", not "switchport mode"
|
|
351
|
-
sw =
|
|
351
|
+
sw = config_get('interface', 'switchport', @name)
|
|
352
352
|
sw.nil? ? false : true
|
|
353
353
|
end
|
|
354
354
|
|
|
355
355
|
def switchport_enable(val=true)
|
|
356
|
-
|
|
356
|
+
config_set('interface', 'switchport', @name, val ? '' : 'no')
|
|
357
357
|
end
|
|
358
358
|
|
|
359
359
|
# switchport_autostate_exclude is exclusive to switchport interfaces
|
|
360
360
|
def switchport_autostate_exclude
|
|
361
|
-
|
|
362
|
-
|
|
361
|
+
!config_get('interface',
|
|
362
|
+
'switchport_autostate_exclude', @name).nil?
|
|
363
363
|
end
|
|
364
364
|
|
|
365
365
|
def switchport_autostate_exclude=(val)
|
|
366
366
|
# cannot configure autostate unless feature vlan is enabled
|
|
367
|
-
|
|
368
|
-
|
|
367
|
+
fail('switchport mode must be configured before ' \
|
|
368
|
+
'switchport autostate') unless switchport
|
|
369
369
|
feature_vlan_set(true)
|
|
370
|
-
|
|
371
|
-
|
|
370
|
+
config_set('interface', 'switchport_autostate_exclude',
|
|
371
|
+
@name, val ? '' : 'no')
|
|
372
372
|
end
|
|
373
373
|
|
|
374
374
|
def default_switchport_autostate_exclude
|
|
375
|
-
|
|
375
|
+
config_get_default('interface', 'switchport_autostate_exclude')
|
|
376
376
|
end
|
|
377
377
|
|
|
378
378
|
def switchport_mode_lookup_string
|
|
379
379
|
case @name
|
|
380
380
|
when /Ethernet/i
|
|
381
|
-
return
|
|
381
|
+
return 'switchport_mode_ethernet'
|
|
382
382
|
when /port-channel/i
|
|
383
|
-
return
|
|
383
|
+
return 'switchport_mode_port_channel'
|
|
384
384
|
else
|
|
385
|
-
return
|
|
385
|
+
return 'switchport_mode_other_interfaces'
|
|
386
386
|
end
|
|
387
387
|
end
|
|
388
388
|
|
|
389
389
|
def switchport_mode
|
|
390
|
-
mode =
|
|
390
|
+
mode = config_get('interface', switchport_mode_lookup_string, @name)
|
|
391
391
|
|
|
392
392
|
return mode.nil? ? :disabled : IF_SWITCHPORT_MODE.key(mode.shift)
|
|
393
393
|
|
|
@@ -404,8 +404,8 @@ module Cisco
|
|
|
404
404
|
if (:fex_fabric == mode_set)
|
|
405
405
|
fex_feature_set(:enabled) unless (:enabled == fex_feature)
|
|
406
406
|
end
|
|
407
|
-
|
|
408
|
-
|
|
407
|
+
config_set('interface', switchport_mode_lookup_string, @name, '',
|
|
408
|
+
IF_SWITCHPORT_MODE[mode_set])
|
|
409
409
|
|
|
410
410
|
rescue RuntimeError
|
|
411
411
|
raise "[#{@name}] switchport_mode is not supported on this interface"
|
|
@@ -416,18 +416,18 @@ module Cisco
|
|
|
416
416
|
# int e1/1
|
|
417
417
|
# switchport
|
|
418
418
|
# switchport mode [access|trunk|fex|...]
|
|
419
|
-
|
|
419
|
+
fail ArgumentError unless IF_SWITCHPORT_MODE.keys.include? mode_set
|
|
420
420
|
case mode_set
|
|
421
421
|
when :disabled
|
|
422
422
|
if switchport
|
|
423
423
|
# Note: turn off switchport command, not switchport mode
|
|
424
|
-
|
|
424
|
+
config_set('interface', 'switchport', @name, 'no')
|
|
425
425
|
end
|
|
426
426
|
|
|
427
427
|
when :default
|
|
428
428
|
if :disabled == default_switchport_mode
|
|
429
|
-
|
|
430
|
-
|
|
429
|
+
config_set('interface', switchport_mode_lookup_string,
|
|
430
|
+
@name, 'no', '')
|
|
431
431
|
else
|
|
432
432
|
switchport_enable_and_mode(mode_set)
|
|
433
433
|
end
|
|
@@ -443,104 +443,108 @@ module Cisco
|
|
|
443
443
|
def default_switchport_mode
|
|
444
444
|
return :disabled unless system_default_switchport
|
|
445
445
|
IF_SWITCHPORT_MODE.key(
|
|
446
|
-
|
|
446
|
+
config_get_default('interface', switchport_mode_lookup_string))
|
|
447
447
|
end
|
|
448
448
|
|
|
449
449
|
def switchport_trunk_allowed_vlan
|
|
450
|
-
val =
|
|
451
|
-
|
|
450
|
+
val = config_get(
|
|
451
|
+
'interface', 'switchport_trunk_allowed_vlan', @name)
|
|
452
452
|
return default_switchport_trunk_allowed_vlan if val.nil?
|
|
453
453
|
val.shift.strip
|
|
454
454
|
end
|
|
455
455
|
|
|
456
456
|
def switchport_trunk_allowed_vlan=(val)
|
|
457
|
-
val.nil?
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
457
|
+
if val.nil?
|
|
458
|
+
config_set(
|
|
459
|
+
'interface', 'switchport_trunk_allowed_vlan', @name, 'no', '')
|
|
460
|
+
else
|
|
461
|
+
config_set(
|
|
462
|
+
'interface', 'switchport_trunk_allowed_vlan', @name, '', val)
|
|
463
|
+
end
|
|
462
464
|
rescue Cisco::CliError => e
|
|
463
465
|
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
|
|
464
466
|
end
|
|
465
467
|
|
|
466
468
|
def default_switchport_trunk_allowed_vlan
|
|
467
|
-
|
|
469
|
+
config_get_default('interface', 'switchport_trunk_allowed_vlan')
|
|
468
470
|
end
|
|
469
471
|
|
|
470
472
|
def switchport_trunk_native_vlan
|
|
471
|
-
val =
|
|
472
|
-
|
|
473
|
+
val = config_get(
|
|
474
|
+
'interface', 'switchport_trunk_native_vlan', @name)
|
|
473
475
|
return default_switchport_trunk_native_vlan if val.nil?
|
|
474
476
|
val.shift.strip.to_i
|
|
475
477
|
end
|
|
476
478
|
|
|
477
479
|
def switchport_trunk_native_vlan=(val)
|
|
478
|
-
val.nil?
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
480
|
+
if val.nil?
|
|
481
|
+
config_set(
|
|
482
|
+
'interface', 'switchport_trunk_native_vlan', @name, 'no', '')
|
|
483
|
+
else
|
|
484
|
+
config_set(
|
|
485
|
+
'interface', 'switchport_trunk_native_vlan', @name, '', val)
|
|
486
|
+
end
|
|
483
487
|
rescue Cisco::CliError => e
|
|
484
488
|
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
|
|
485
489
|
end
|
|
486
490
|
|
|
487
491
|
def default_switchport_trunk_native_vlan
|
|
488
|
-
|
|
492
|
+
config_get_default('interface', 'switchport_trunk_native_vlan')
|
|
489
493
|
end
|
|
490
494
|
|
|
491
495
|
def system_default_switchport
|
|
492
496
|
# This command is a user-configurable system default.
|
|
493
|
-
sys_def =
|
|
497
|
+
sys_def = config_get('interface', 'system_default_switchport')
|
|
494
498
|
sys_def.nil? ? false : true
|
|
495
499
|
end
|
|
496
500
|
|
|
497
501
|
def system_default_switchport_shutdown
|
|
498
502
|
# This command is a user-configurable system default.
|
|
499
|
-
sys_def =
|
|
500
|
-
|
|
503
|
+
sys_def = config_get('interface',
|
|
504
|
+
'system_default_switchport_shutdown')
|
|
501
505
|
sys_def.nil? ? false : true
|
|
502
506
|
end
|
|
503
507
|
|
|
504
508
|
def system_default_svi_autostate
|
|
505
509
|
# This command is a user-configurable system default.
|
|
506
|
-
sys_def =
|
|
507
|
-
|
|
510
|
+
sys_def = config_get('interface',
|
|
511
|
+
'system_default_svi_autostate')
|
|
508
512
|
sys_def.nil? ? false : true
|
|
509
513
|
end
|
|
510
514
|
|
|
511
515
|
def switchport_vtp_mode_capable?
|
|
512
|
-
|
|
516
|
+
!switchport_mode.to_s.match(/(access|trunk)/).nil?
|
|
513
517
|
end
|
|
514
518
|
|
|
515
519
|
def switchport_vtp
|
|
516
520
|
return false unless switchport_vtp_mode_capable?
|
|
517
|
-
vtp =
|
|
521
|
+
vtp = config_get('interface', 'vtp', @name)
|
|
518
522
|
vtp.nil? ? false : true
|
|
519
523
|
end
|
|
520
524
|
|
|
521
525
|
def switchport_vtp=(vtp_set)
|
|
522
526
|
return false unless switchport_vtp_mode_capable?
|
|
523
|
-
no_cmd = (vtp_set) ?
|
|
524
|
-
|
|
527
|
+
no_cmd = (vtp_set) ? '' : 'no'
|
|
528
|
+
config_set('interface', 'vtp', @name, no_cmd)
|
|
525
529
|
rescue Cisco::CliError => e
|
|
526
530
|
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
|
|
527
531
|
end
|
|
528
532
|
|
|
529
533
|
def svi_cmd_allowed?(cmd)
|
|
530
|
-
|
|
534
|
+
fail "[#{@name}] Invalid interface type for command [#{cmd}]" unless
|
|
531
535
|
@name[/vlan/i]
|
|
532
536
|
end
|
|
533
537
|
|
|
534
538
|
# svi_autostate is exclusive to svi interfaces
|
|
535
539
|
def svi_autostate
|
|
536
540
|
return nil unless @name[/^vlan/i]
|
|
537
|
-
|
|
541
|
+
!config_get('interface', 'svi_autostate', @name).nil?
|
|
538
542
|
end
|
|
539
543
|
|
|
540
544
|
def svi_autostate=(val)
|
|
541
545
|
check_switchport_disabled
|
|
542
546
|
svi_cmd_allowed?('autostate')
|
|
543
|
-
|
|
547
|
+
config_set('interface', 'svi_autostate', @name, val ? '' : 'no')
|
|
544
548
|
end
|
|
545
549
|
|
|
546
550
|
def default_svi_autostate
|
|
@@ -548,60 +552,62 @@ module Cisco
|
|
|
548
552
|
end
|
|
549
553
|
|
|
550
554
|
def feature_vlan?
|
|
551
|
-
|
|
555
|
+
!config_get('interface', 'feature_vlan').nil?
|
|
552
556
|
end
|
|
553
557
|
|
|
554
558
|
def feature_vlan_set(val)
|
|
555
559
|
return if feature_vlan? == val
|
|
556
|
-
|
|
560
|
+
config_set('interface', 'feature_vlan', val ? '' : 'no')
|
|
557
561
|
end
|
|
558
562
|
|
|
559
563
|
# svi_management is exclusive to svi interfaces
|
|
560
564
|
def svi_management
|
|
561
565
|
return nil unless @name[/^vlan/i]
|
|
562
|
-
|
|
566
|
+
!config_get('interface', 'svi_management', @name).nil?
|
|
563
567
|
end
|
|
564
568
|
|
|
565
569
|
def svi_management=(val)
|
|
566
570
|
check_switchport_disabled
|
|
567
571
|
svi_cmd_allowed?('management')
|
|
568
|
-
|
|
572
|
+
config_set('interface', 'svi_management', @name, val ? '' : 'no')
|
|
569
573
|
end
|
|
570
574
|
|
|
571
575
|
def default_svi_management
|
|
572
|
-
|
|
576
|
+
config_get_default('interface', 'svi_management')
|
|
573
577
|
end
|
|
574
578
|
|
|
575
579
|
def default_switchport_vtp
|
|
576
|
-
|
|
580
|
+
config_get_default('interface', 'vtp')
|
|
577
581
|
end
|
|
578
582
|
|
|
579
583
|
def switchport_vtp_feature?
|
|
580
|
-
|
|
584
|
+
config_get('vtp', 'feature')
|
|
581
585
|
end
|
|
582
586
|
|
|
583
587
|
def check_switchport_disabled
|
|
584
|
-
|
|
585
|
-
|
|
588
|
+
fail "#{caller[0][/`.*'/][1..-2]} cannot be set unless switchport mode" \
|
|
589
|
+
' is disabled' unless switchport_mode == :disabled
|
|
586
590
|
end
|
|
587
591
|
|
|
588
592
|
def vrf
|
|
589
|
-
vrf =
|
|
590
|
-
return
|
|
593
|
+
vrf = config_get('interface', 'vrf', @name)
|
|
594
|
+
return '' if vrf.nil?
|
|
591
595
|
vrf.shift.strip
|
|
592
596
|
end
|
|
593
597
|
|
|
594
598
|
def vrf=(vrf)
|
|
595
|
-
|
|
596
|
-
vrf.empty?
|
|
597
|
-
|
|
598
|
-
|
|
599
|
+
fail TypeError unless vrf.is_a?(String)
|
|
600
|
+
if vrf.empty?
|
|
601
|
+
config_set('interface', 'vrf', @name, 'no', '')
|
|
602
|
+
else
|
|
603
|
+
config_set('interface', 'vrf', @name, '', vrf)
|
|
604
|
+
end
|
|
599
605
|
rescue Cisco::CliError => e
|
|
600
606
|
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
|
|
601
607
|
end
|
|
602
608
|
|
|
603
609
|
def default_vrf
|
|
604
|
-
|
|
610
|
+
config_get_default('interface', 'vrf')
|
|
605
611
|
end
|
|
606
612
|
end # Class
|
|
607
613
|
end # Module
|