Class: Cisco::Interface
Overview
Interface - node utility class for general interface config management
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from NodeUtil
config_get, #config_get, config_get_default, #config_get_default, #config_set, config_set, #node, node, #show
Constructor Details
#initialize(name, instantiate = true) ⇒ Interface
Returns a new instance of Interface.
39
40
41
42
43
44
45
|
# File 'lib/cisco_node_utils/interface.rb', line 39
def initialize(name, instantiate=true)
fail TypeError unless name.is_a?(String)
fail ArgumentError unless name.length > 0
@name = name.downcase
create if instantiate
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
37
38
39
|
# File 'lib/cisco_node_utils/interface.rb', line 37
def name
@name
end
|
Class Method Details
.interfaces ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/cisco_node_utils/interface.rb', line 47
def self.interfaces
hash = {}
intf_list = config_get('interface', 'all_interfaces')
return hash if intf_list.nil?
intf_list.each do |id|
id = id.downcase
hash[id] = Interface.new(id, false)
end
hash
end
|
Instance Method Details
#access_vlan ⇒ Object
72
73
74
|
# File 'lib/cisco_node_utils/interface.rb', line 72
def access_vlan
config_get('interface', 'access_vlan', @name)
end
|
#access_vlan=(vlan) ⇒ Object
76
77
78
79
80
|
# File 'lib/cisco_node_utils/interface.rb', line 76
def access_vlan=(vlan)
config_set('interface', 'access_vlan', @name, vlan)
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end
|
#check_switchport_disabled ⇒ Object
851
852
853
854
|
# File 'lib/cisco_node_utils/interface.rb', line 851
def check_switchport_disabled
fail "#{caller[0][/`.*'/][1..-2]} cannot be set unless switchport mode" \
' is disabled' unless switchport_mode == :disabled
end
|
#create ⇒ Object
59
60
61
62
|
# File 'lib/cisco_node_utils/interface.rb', line 59
def create
feature_vlan_set(true) if @name[/vlan/i]
config_set('interface', 'create', @name)
end
|
#default_access_vlan ⇒ Object
160
161
162
|
# File 'lib/cisco_node_utils/interface.rb', line 160
def default_access_vlan
config_get_default('interface', 'access_vlan')
end
|
#default_description ⇒ Object
179
180
181
|
# File 'lib/cisco_node_utils/interface.rb', line 179
def default_description
config_get_default('interface', 'description')
end
|
#default_duplex ⇒ Object
471
472
473
|
# File 'lib/cisco_node_utils/interface.rb', line 471
def default_duplex
config_get_default('interface', 'duplex')
end
|
#default_encapsulation_dot1q ⇒ Object
197
198
199
|
# File 'lib/cisco_node_utils/interface.rb', line 197
def default_encapsulation_dot1q
config_get_default('interface', 'encapsulation_dot1q')
end
|
#default_fabric_forwarding_anycast_gateway ⇒ Object
230
231
232
|
# File 'lib/cisco_node_utils/interface.rb', line 230
def default_fabric_forwarding_anycast_gateway
config_get_default('interface', 'fabric_forwarding_anycast_gateway')
end
|
#default_ipv4_acl_in ⇒ Object
98
99
100
|
# File 'lib/cisco_node_utils/interface.rb', line 98
def default_ipv4_acl_in
config_get_default('interface', 'ipv4_acl_in')
end
|
#default_ipv4_acl_out ⇒ Object
118
119
120
|
# File 'lib/cisco_node_utils/interface.rb', line 118
def default_ipv4_acl_out
config_get_default('interface', 'ipv4_acl_out')
end
|
#default_ipv4_address ⇒ Object
323
324
325
|
# File 'lib/cisco_node_utils/interface.rb', line 323
def default_ipv4_address
config_get_default('interface', 'ipv4_address')
end
|
#default_ipv4_address_secondary ⇒ Object
327
328
329
|
# File 'lib/cisco_node_utils/interface.rb', line 327
def default_ipv4_address_secondary
default_ipv4_address
end
|
#default_ipv4_arp_timeout ⇒ Object
359
360
361
|
# File 'lib/cisco_node_utils/interface.rb', line 359
def default_ipv4_arp_timeout
config_get_default('interface', ipv4_arp_timeout_lookup_string)
end
|
#default_ipv4_netmask_length ⇒ Object
331
332
333
|
# File 'lib/cisco_node_utils/interface.rb', line 331
def default_ipv4_netmask_length
config_get_default('interface', 'ipv4_netmask_length')
end
|
#default_ipv4_netmask_length_secondary ⇒ Object
335
336
337
|
# File 'lib/cisco_node_utils/interface.rb', line 335
def default_ipv4_netmask_length_secondary
default_ipv4_netmask_length
end
|
#default_ipv4_pim_sparse_mode ⇒ Object
376
377
378
|
# File 'lib/cisco_node_utils/interface.rb', line 376
def default_ipv4_pim_sparse_mode
config_get_default('interface', 'ipv4_pim_sparse_mode')
end
|
#default_ipv4_proxy_arp ⇒ Object
390
391
392
|
# File 'lib/cisco_node_utils/interface.rb', line 390
def default_ipv4_proxy_arp
config_get_default('interface', 'ipv4_proxy_arp')
end
|
#default_ipv4_redirects ⇒ Object
413
414
415
|
# File 'lib/cisco_node_utils/interface.rb', line 413
def default_ipv4_redirects
config_get_default('interface', ipv4_redirects_lookup_string)
end
|
#default_ipv6_acl_in ⇒ Object
137
138
139
|
# File 'lib/cisco_node_utils/interface.rb', line 137
def default_ipv6_acl_in
config_get_default('interface', 'ipv6_acl_in')
end
|
#default_ipv6_acl_out ⇒ Object
156
157
158
|
# File 'lib/cisco_node_utils/interface.rb', line 156
def default_ipv6_acl_out
config_get_default('interface', 'ipv6_acl_out')
end
|
#default_mtu ⇒ Object
437
438
439
|
# File 'lib/cisco_node_utils/interface.rb', line 437
def default_mtu
config_get_default('interface', 'mtu')
end
|
#default_negotiate_auto ⇒ Object
496
497
498
|
# File 'lib/cisco_node_utils/interface.rb', line 496
def default_negotiate_auto
config_get_default('interface', negotiate_auto_lookup_string)
end
|
#default_shutdown ⇒ Object
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
|
# File 'lib/cisco_node_utils/interface.rb', line 511
def default_shutdown
case @name
when /Ethernet/i
def_sw = system_default_switchport
def_shut = system_default_switchport_shutdown
if def_sw && def_shut
lookup = 'shutdown_ethernet_switchport_shutdown'
elsif def_sw && !def_shut
lookup = 'shutdown_ethernet_switchport_noshutdown'
elsif !def_sw && def_shut
lookup = 'shutdown_ethernet_noswitchport_shutdown'
elsif !def_sw && !def_shut
lookup = 'shutdown_ethernet_noswitchport_noshutdown'
else
fail "Error: def_sw #{def_sw}, def_shut #{def_shut}"
end
when /loopback/i
lookup = 'shutdown_loopback'
when /port-channel/i lookup = 'shutdown_ether_channel'
when /Vlan/i
lookup = 'shutdown_vlan'
else
lookup = 'shutdown_unknown'
end
config_get_default('interface', lookup)
end
|
#default_speed ⇒ Object
454
455
456
|
# File 'lib/cisco_node_utils/interface.rb', line 454
def default_speed
config_get_default('interface', 'speed')
end
|
#default_svi_autostate ⇒ Object
814
815
816
|
# File 'lib/cisco_node_utils/interface.rb', line 814
def default_svi_autostate
system_default_svi_autostate
end
|
#default_svi_management ⇒ Object
839
840
841
|
# File 'lib/cisco_node_utils/interface.rb', line 839
def default_svi_management
config_get_default('interface', 'svi_management')
end
|
#default_switchport_autostate_exclude ⇒ Object
568
569
570
|
# File 'lib/cisco_node_utils/interface.rb', line 568
def default_switchport_autostate_exclude
config_get_default('interface', 'switchport_autostate_exclude')
end
|
#default_switchport_mode ⇒ Object
639
640
641
642
643
|
# File 'lib/cisco_node_utils/interface.rb', line 639
def default_switchport_mode
return :disabled unless system_default_switchport
IF_SWITCHPORT_MODE.key(
config_get_default('interface', switchport_mode_lookup_string))
end
|
#default_switchport_trunk_allowed_vlan ⇒ Object
661
662
663
|
# File 'lib/cisco_node_utils/interface.rb', line 661
def default_switchport_trunk_allowed_vlan
config_get_default('interface', 'switchport_trunk_allowed_vlan')
end
|
#default_switchport_trunk_native_vlan ⇒ Object
743
744
745
|
# File 'lib/cisco_node_utils/interface.rb', line 743
def default_switchport_trunk_native_vlan
config_get_default('interface', 'switchport_trunk_native_vlan')
end
|
#default_switchport_vtp ⇒ Object
843
844
845
|
# File 'lib/cisco_node_utils/interface.rb', line 843
def default_switchport_vtp
config_get_default('interface', 'vtp')
end
|
#default_vlan_mapping ⇒ Object
Getter: Builds an array of vlan_mapping commands currently on the device.
cli: switchport vlan mapping 2 200
switchport vlan mapping 4 400
array: [[‘2’, ‘200’], [‘4’, ‘400’]]
696
697
698
|
# File 'lib/cisco_node_utils/interface.rb', line 696
def default_vlan_mapping
config_get_default('interface', 'vlan_mapping')
end
|
#default_vlan_mapping_enable ⇒ Object
cli: switchport vlan mapping enable
730
731
732
|
# File 'lib/cisco_node_utils/interface.rb', line 730
def default_vlan_mapping_enable
config_get_default('interface', 'vlan_mapping_enable')
end
|
#default_vpc_id ⇒ Object
870
871
872
|
# File 'lib/cisco_node_utils/interface.rb', line 870
def default_vpc_id
config_get_default('interface', 'vpc_id')
end
|
#default_vpc_peer_link ⇒ Object
883
884
885
|
# File 'lib/cisco_node_utils/interface.rb', line 883
def default_vpc_peer_link
config_get_default('interface', 'vpc_peer_link')
end
|
#default_vrf ⇒ Object
902
903
904
|
# File 'lib/cisco_node_utils/interface.rb', line 902
def default_vrf
config_get_default('interface', 'vrf')
end
|
#description ⇒ Object
164
165
166
|
# File 'lib/cisco_node_utils/interface.rb', line 164
def description
config_get('interface', 'description', @name)
end
|
#description=(desc) ⇒ Object
168
169
170
171
172
173
174
175
176
177
|
# File 'lib/cisco_node_utils/interface.rb', line 168
def description=(desc)
fail TypeError unless desc.is_a?(String)
if desc.strip.empty?
config_set('interface', 'description', @name, 'no', '')
else
config_set('interface', 'description', @name, '', desc)
end
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end
|
#destroy ⇒ Object
64
65
66
|
# File 'lib/cisco_node_utils/interface.rb', line 64
def destroy
config_set('interface', 'destroy', @name)
end
|
#duplex ⇒ Object
458
459
460
|
# File 'lib/cisco_node_utils/interface.rb', line 458
def duplex
config_get('interface', 'duplex', @name)
end
|
#duplex=(val) ⇒ Object
462
463
464
465
466
467
468
469
|
# File 'lib/cisco_node_utils/interface.rb', line 462
def duplex=(val)
if node.product_id =~ /C31\d\d/
fail 'Changing interface duplex is not permitted on this platform'
end
config_set('interface', 'duplex', @name, val)
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end
|
#encapsulation_dot1q ⇒ Object
183
184
185
|
# File 'lib/cisco_node_utils/interface.rb', line 183
def encapsulation_dot1q
config_get('interface', 'encapsulation_dot1q', @name)
end
|
#encapsulation_dot1q=(val) ⇒ Object
187
188
189
190
191
192
193
194
195
|
# File 'lib/cisco_node_utils/interface.rb', line 187
def encapsulation_dot1q=(val)
if val.to_s.empty?
config_set('interface', 'encapsulation_dot1q', @name, 'no', '')
else
config_set('interface', 'encapsulation_dot1q', @name, '', val)
end
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end
|
#fabric_forwarding_anycast_gateway ⇒ Object
209
210
211
|
# File 'lib/cisco_node_utils/interface.rb', line 209
def fabric_forwarding_anycast_gateway
config_get('interface', 'fabric_forwarding_anycast_gateway', @name)
end
|
#fabric_forwarding_anycast_gateway=(state) ⇒ Object
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
# File 'lib/cisco_node_utils/interface.rb', line 213
def fabric_forwarding_anycast_gateway=(state)
no_cmd = (state ? '' : 'no')
config_set('interface',
'fabric_forwarding_anycast_gateway', @name, no_cmd)
fail if fabric_forwarding_anycast_gateway.to_s != state.to_s
rescue Cisco::CliError => e
info = "[#{@name}] '#{e.command}' : #{e.clierror}"
raise "#{info} 'fabric_forwarding_anycast_gateway' can only be " \
'configured on a vlan interface' unless /vlan/.match(@name)
anycast_gateway_mac = OverlayGlobal.new.anycast_gateway_mac
if anycast_gateway_mac.nil? || anycast_gateway_mac.empty?
raise "#{info} Anycast gateway mac must be configured " \
'before configuring forwarding mode under interface'
end
raise info
end
|
#fabricpath_feature ⇒ Object
#fabricpath_feature_set(fabricpath_set) ⇒ Object
#feature_lacp? ⇒ Boolean
417
418
419
|
# File 'lib/cisco_node_utils/interface.rb', line 417
def feature_lacp?
config_get('interface', 'feature_lacp')
end
|
#feature_lacp_set(val) ⇒ Object
421
422
423
424
|
# File 'lib/cisco_node_utils/interface.rb', line 421
def feature_lacp_set(val)
return if feature_lacp? == val
config_set('interface', 'feature_lacp', val ? '' : 'no')
end
|
#feature_vlan? ⇒ Boolean
818
819
820
|
# File 'lib/cisco_node_utils/interface.rb', line 818
def feature_vlan?
config_get('interface', 'feature_vlan')
end
|
#feature_vlan_set(val) ⇒ Object
822
823
824
825
|
# File 'lib/cisco_node_utils/interface.rb', line 822
def feature_vlan_set(val)
return if feature_vlan? == val
config_set('interface', 'feature_vlan', val ? '' : 'no')
end
|
#fex_feature ⇒ Object
234
235
236
237
238
|
# File 'lib/cisco_node_utils/interface.rb', line 234
def fex_feature
fex = config_get('fex', 'feature')
fail 'fex_feature not found' if fex.nil?
fex.to_sym
end
|
#fex_feature_set(fex_set) ⇒ Object
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
# File 'lib/cisco_node_utils/interface.rb', line 240
def fex_feature_set(fex_set)
curr = fex_feature
return if curr == fex_set
case fex_set
when :enabled
config_set('fex', 'feature_install', '') if curr == :uninstalled
config_set('fex', 'feature', '')
when :disabled
config_set('fex', 'feature', 'no') if curr == :enabled
return
when :installed
config_set('fex', 'feature_install', '') if curr == :uninstalled
when :uninstalled
config_set('fex', 'feature', 'no') if curr == :enabled
config_set('fex', 'feature_install', 'no')
end
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end
|
#ipv4_acl_in ⇒ Object
82
83
84
|
# File 'lib/cisco_node_utils/interface.rb', line 82
def ipv4_acl_in
config_get('interface', 'ipv4_acl_in', @name)
end
|
#ipv4_acl_in=(val) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/cisco_node_utils/interface.rb', line 86
def ipv4_acl_in=(val)
if val != ''
state = ''
else
state = 'no'
val = ipv4_acl_in
end
return unless val && val != ''
config_set('interface', 'ipv4_acl_in', @name, state, val)
end
|
#ipv4_acl_out ⇒ Object
102
103
104
|
# File 'lib/cisco_node_utils/interface.rb', line 102
def ipv4_acl_out
config_get('interface', 'ipv4_acl_out', @name)
end
|
#ipv4_acl_out=(val) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
|
# File 'lib/cisco_node_utils/interface.rb', line 106
def ipv4_acl_out=(val)
if val != ''
state = ''
else
state = 'no'
val = ipv4_acl_out
end
return unless val && val != ''
config_set('interface', 'ipv4_acl_out', @name, state, val)
end
|
#ipv4_addr_mask ⇒ Object
283
284
285
|
# File 'lib/cisco_node_utils/interface.rb', line 283
def ipv4_addr_mask
config_get('interface', 'ipv4_addr_mask', @name)
end
|
#ipv4_addr_mask_set(addr, mask, secondary = false) ⇒ Object
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
# File 'lib/cisco_node_utils/interface.rb', line 261
def ipv4_addr_mask_set(addr, mask, secondary=false)
check_switchport_disabled
sec = secondary ? 'secondary' : ''
if addr.nil? || addr == default_ipv4_address
state = 'no'
if secondary
return if ipv4_address_secondary == default_ipv4_address_secondary
am = "#{ipv4_address_secondary}/#{ipv4_netmask_length_secondary}"
else
return if ipv4_address == default_ipv4_address
am = "#{ipv4_address}/#{ipv4_netmask_length}"
end
else
state = ''
am = "#{addr}/#{mask}"
end
config_set('interface', 'ipv4_addr_mask', @name, state, am, sec)
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end
|
#ipv4_address ⇒ Object
307
308
309
|
# File 'lib/cisco_node_utils/interface.rb', line 307
def ipv4_address
select_ipv4_attribute(:v4_addr)
end
|
#ipv4_address_secondary ⇒ Object
311
312
313
|
# File 'lib/cisco_node_utils/interface.rb', line 311
def ipv4_address_secondary
select_ipv4_attribute(:v4_addr_secondary)
end
|
#ipv4_arp_timeout ⇒ Object
348
349
350
|
# File 'lib/cisco_node_utils/interface.rb', line 348
def ipv4_arp_timeout
config_get('interface', ipv4_arp_timeout_lookup_string, @name)
end
|
#ipv4_arp_timeout=(timeout) ⇒ Object
352
353
354
355
356
357
|
# File 'lib/cisco_node_utils/interface.rb', line 352
def ipv4_arp_timeout=(timeout)
fail "'ipv4 arp timeout' can ony be configured on a vlan interface" unless
/vlan/.match(@name)
state = (timeout == default_ipv4_arp_timeout) ? 'no' : ''
config_set('interface', 'ipv4_arp_timeout', @name, state, timeout)
end
|
#ipv4_arp_timeout_lookup_string ⇒ Object
339
340
341
342
343
344
345
346
|
# File 'lib/cisco_node_utils/interface.rb', line 339
def ipv4_arp_timeout_lookup_string
case @name
when /vlan/i
return 'ipv4_arp_timeout'
else
return 'ipv4_arp_timeout_non_vlan_interfaces'
end
end
|
#ipv4_netmask_length ⇒ Object
315
316
317
|
# File 'lib/cisco_node_utils/interface.rb', line 315
def ipv4_netmask_length
select_ipv4_attribute(:v4_mask)
end
|
#ipv4_netmask_length_secondary ⇒ Object
319
320
321
|
# File 'lib/cisco_node_utils/interface.rb', line 319
def ipv4_netmask_length_secondary
select_ipv4_attribute(:v4_mask_secondary)
end
|
#ipv4_pim_sparse_mode ⇒ Object
363
364
365
|
# File 'lib/cisco_node_utils/interface.rb', line 363
def ipv4_pim_sparse_mode
config_get('interface', 'ipv4_pim_sparse_mode', @name)
end
|
#ipv4_pim_sparse_mode=(state) ⇒ Object
367
368
369
370
371
372
373
374
|
# File 'lib/cisco_node_utils/interface.rb', line 367
def ipv4_pim_sparse_mode=(state)
check_switchport_disabled
Pim.feature_enable unless Pim.feature_enabled
config_set('interface', 'ipv4_pim_sparse_mode', @name,
state ? '' : 'no')
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end
|
#ipv4_proxy_arp ⇒ Object
380
381
382
|
# File 'lib/cisco_node_utils/interface.rb', line 380
def ipv4_proxy_arp
config_get('interface', 'ipv4_proxy_arp', @name)
end
|
#ipv4_proxy_arp=(proxy_arp) ⇒ Object
384
385
386
387
388
|
# File 'lib/cisco_node_utils/interface.rb', line 384
def ipv4_proxy_arp=(proxy_arp)
check_switchport_disabled
no_cmd = (proxy_arp ? '' : 'no')
config_set('interface', 'ipv4_proxy_arp', @name, no_cmd)
end
|
#ipv4_redirects ⇒ Object
403
404
405
|
# File 'lib/cisco_node_utils/interface.rb', line 403
def ipv4_redirects
config_get('interface', ipv4_redirects_lookup_string, @name)
end
|
#ipv4_redirects=(redirects) ⇒ Object
407
408
409
410
411
|
# File 'lib/cisco_node_utils/interface.rb', line 407
def ipv4_redirects=(redirects)
check_switchport_disabled
no_cmd = (redirects ? '' : 'no')
config_set('interface', ipv4_redirects_lookup_string, @name, no_cmd)
end
|
#ipv4_redirects_lookup_string ⇒ Object
394
395
396
397
398
399
400
401
|
# File 'lib/cisco_node_utils/interface.rb', line 394
def ipv4_redirects_lookup_string
case @name
when /loopback/i
return 'ipv4_redirects_loopback'
else
return 'ipv4_redirects_other_interfaces'
end
end
|
#ipv6_acl_in ⇒ Object
122
123
124
|
# File 'lib/cisco_node_utils/interface.rb', line 122
def ipv6_acl_in
config_get('interface', 'ipv6_acl_in', @name)
end
|
#ipv6_acl_in=(val) ⇒ Object
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/cisco_node_utils/interface.rb', line 126
def ipv6_acl_in=(val)
if val != ''
state = ''
else
state = 'no'
val = ipv6_acl_in
end
return unless val && val != ''
config_set('interface', 'ipv6_acl_in', @name, state, val)
end
|
#ipv6_acl_out ⇒ Object
141
142
143
|
# File 'lib/cisco_node_utils/interface.rb', line 141
def ipv6_acl_out
config_get('interface', 'ipv6_acl_out', @name)
end
|
#ipv6_acl_out=(val) ⇒ Object
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/cisco_node_utils/interface.rb', line 145
def ipv6_acl_out=(val)
if val != ''
state = ''
else
state = 'no'
val = ipv6_acl_out
end
return unless val && val != ''
config_set('interface', 'ipv6_acl_out', @name, state, val)
end
|
#mtu ⇒ Object
426
427
428
|
# File 'lib/cisco_node_utils/interface.rb', line 426
def mtu
config_get('interface', 'mtu', @name)
end
|
#mtu=(val) ⇒ Object
430
431
432
433
434
435
|
# File 'lib/cisco_node_utils/interface.rb', line 430
def mtu=(val)
check_switchport_disabled
config_set('interface', 'mtu', @name, '', val)
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end
|
#negotiate_auto ⇒ Object
486
487
488
|
# File 'lib/cisco_node_utils/interface.rb', line 486
def negotiate_auto
config_get('interface', negotiate_auto_lookup_string, @name)
end
|
#negotiate_auto=(negotiate_auto) ⇒ Object
490
491
492
493
494
|
# File 'lib/cisco_node_utils/interface.rb', line 490
def negotiate_auto=(negotiate_auto)
lookup = negotiate_auto_lookup_string
no_cmd = (negotiate_auto ? '' : 'no')
config_set('interface', lookup, @name, no_cmd)
end
|
#negotiate_auto_lookup_string ⇒ Object
475
476
477
478
479
480
481
482
483
484
|
# File 'lib/cisco_node_utils/interface.rb', line 475
def negotiate_auto_lookup_string
case @name
when /Ethernet/i
return 'negotiate_auto_ethernet'
when /port-channel/i return 'negotiate_auto_portchannel'
else
return 'negotiate_auto_other_interfaces'
end
end
|
#select_ipv4_attribute(attribute) ⇒ Object
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
# File 'lib/cisco_node_utils/interface.rb', line 287
def select_ipv4_attribute(attribute)
d = ipv4_addr_mask.flatten unless ipv4_addr_mask.nil?
case attribute
when :v4_addr
v = d.nil? ? default_ipv4_address : d[0]
when :v4_mask
v = d.nil? ? default_ipv4_netmask_length : d[1].to_i
when :v4_addr_secondary
v = (d.nil? || d.size < 4) ? default_ipv4_address : d[2]
when :v4_mask_secondary
if d.nil? || d.size < 4
v = default_ipv4_netmask_length
else
v = d[3][0, 2].to_i
end
end
v
end
|
#shutdown ⇒ Object
500
501
502
|
# File 'lib/cisco_node_utils/interface.rb', line 500
def shutdown
config_get('interface', 'shutdown', @name)
end
|
#shutdown=(state) ⇒ Object
504
505
506
507
508
509
|
# File 'lib/cisco_node_utils/interface.rb', line 504
def shutdown=(state)
no_cmd = (state ? '' : 'no')
config_set('interface', 'shutdown', @name, no_cmd)
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end
|
#speed ⇒ Object
441
442
443
|
# File 'lib/cisco_node_utils/interface.rb', line 441
def speed
config_get('interface', 'speed', @name)
end
|
#speed=(val) ⇒ Object
445
446
447
448
449
450
451
452
|
# File 'lib/cisco_node_utils/interface.rb', line 445
def speed=(val)
if node.product_id =~ /C31\d\d/
fail 'Changing interface speed is not permitted on this platform'
end
config_set('interface', 'speed', @name, val)
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end
|
#svi_autostate ⇒ Object
svi_autostate is exclusive to svi interfaces
803
804
805
806
|
# File 'lib/cisco_node_utils/interface.rb', line 803
def svi_autostate
return nil unless @name[/^vlan/i]
config_get('interface', 'svi_autostate', @name)
end
|
#svi_autostate=(val) ⇒ Object
808
809
810
811
812
|
# File 'lib/cisco_node_utils/interface.rb', line 808
def svi_autostate=(val)
check_switchport_disabled
svi_cmd_allowed?('autostate')
config_set('interface', 'svi_autostate', @name, val ? '' : 'no')
end
|
#svi_cmd_allowed?(cmd) ⇒ Boolean
797
798
799
800
|
# File 'lib/cisco_node_utils/interface.rb', line 797
def svi_cmd_allowed?(cmd)
fail "[#{@name}] Invalid interface type for command [#{cmd}]" unless
@name[/vlan/i]
end
|
#svi_management ⇒ Object
svi_management is exclusive to svi interfaces
828
829
830
831
|
# File 'lib/cisco_node_utils/interface.rb', line 828
def svi_management
return nil unless @name[/^vlan/i]
config_get('interface', 'svi_management', @name)
end
|
#svi_management=(val) ⇒ Object
833
834
835
836
837
|
# File 'lib/cisco_node_utils/interface.rb', line 833
def svi_management=(val)
check_switchport_disabled
svi_cmd_allowed?('management')
config_set('interface', 'svi_management', @name, val ? '' : 'no')
end
|
#switchport ⇒ Object
544
545
546
547
|
# File 'lib/cisco_node_utils/interface.rb', line 544
def switchport
config_get('interface', 'switchport', @name)
end
|
#switchport_autostate_exclude ⇒ Object
switchport_autostate_exclude is exclusive to switchport interfaces
554
555
556
557
|
# File 'lib/cisco_node_utils/interface.rb', line 554
def switchport_autostate_exclude
config_get('interface',
'switchport_autostate_exclude', @name)
end
|
#switchport_autostate_exclude=(val) ⇒ Object
559
560
561
562
563
564
565
566
|
# File 'lib/cisco_node_utils/interface.rb', line 559
def switchport_autostate_exclude=(val)
fail('switchport mode must be configured before ' \
'switchport autostate') unless switchport
feature_vlan_set(true)
config_set('interface', 'switchport_autostate_exclude',
@name, val ? '' : 'no')
end
|
#switchport_enable(val = true) ⇒ Object
549
550
551
|
# File 'lib/cisco_node_utils/interface.rb', line 549
def switchport_enable(val=true)
config_set('interface', 'switchport', @name, val ? '' : 'no')
end
|
#switchport_enable_and_mode(mode_set) ⇒ Object
595
596
597
598
599
600
601
602
603
604
605
606
607
608
|
# File 'lib/cisco_node_utils/interface.rb', line 595
def switchport_enable_and_mode(mode_set)
switchport_enable unless switchport
if :fabricpath == mode_set
fabricpath_feature_set(:enabled) unless :enabled == fabricpath_feature
elsif :fex_fabric == mode_set
fex_feature_set(:enabled) unless :enabled == fex_feature
end
config_set('interface', switchport_mode_lookup_string, @name, '',
IF_SWITCHPORT_MODE[mode_set])
rescue RuntimeError
raise "[#{@name}] switchport_mode is not supported on this interface"
end
|
#switchport_mode ⇒ Object
583
584
585
586
587
588
589
590
591
592
593
|
# File 'lib/cisco_node_utils/interface.rb', line 583
def switchport_mode
mode = config_get('interface', switchport_mode_lookup_string, @name)
return mode.nil? ? :disabled : IF_SWITCHPORT_MODE.key(mode)
rescue IndexError
return :disabled
end
|
#switchport_mode=(mode_set) ⇒ Object
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
|
# File 'lib/cisco_node_utils/interface.rb', line 610
def switchport_mode=(mode_set)
fail ArgumentError unless IF_SWITCHPORT_MODE.keys.include? mode_set
case mode_set
when :disabled
if switchport
config_set('interface', 'switchport', @name, 'no')
end
when :default
if :disabled == default_switchport_mode
config_set('interface', switchport_mode_lookup_string,
@name, 'no', '')
else
switchport_enable_and_mode(mode_set)
end
else
switchport_enable_and_mode(mode_set)
end
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end
|
#switchport_mode_lookup_string ⇒ Object
572
573
574
575
576
577
578
579
580
581
|
# File 'lib/cisco_node_utils/interface.rb', line 572
def switchport_mode_lookup_string
case @name
when /Ethernet/i
return 'switchport_mode_ethernet'
when /port-channel/i
return 'switchport_mode_port_channel'
else
return 'switchport_mode_other_interfaces'
end
end
|
#switchport_trunk_allowed_vlan ⇒ Object
645
646
647
|
# File 'lib/cisco_node_utils/interface.rb', line 645
def switchport_trunk_allowed_vlan
config_get('interface', 'switchport_trunk_allowed_vlan', @name)
end
|
#switchport_trunk_allowed_vlan=(val) ⇒ Object
649
650
651
652
653
654
655
656
657
658
659
|
# File 'lib/cisco_node_utils/interface.rb', line 649
def switchport_trunk_allowed_vlan=(val)
if val.nil?
config_set(
'interface', 'switchport_trunk_allowed_vlan', @name, 'no', '')
else
config_set(
'interface', 'switchport_trunk_allowed_vlan', @name, '', val)
end
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end
|
#switchport_trunk_native_vlan ⇒ Object
665
666
667
|
# File 'lib/cisco_node_utils/interface.rb', line 665
def switchport_trunk_native_vlan
config_get('interface', 'switchport_trunk_native_vlan', @name)
end
|
#switchport_trunk_native_vlan=(val) ⇒ Object
669
670
671
672
673
674
675
676
677
678
679
|
# File 'lib/cisco_node_utils/interface.rb', line 669
def switchport_trunk_native_vlan=(val)
if val.nil?
config_set(
'interface', 'switchport_trunk_native_vlan', @name, 'no', '')
else
config_set(
'interface', 'switchport_trunk_native_vlan', @name, '', val)
end
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end
|
#switchport_vtp ⇒ Object
784
785
786
787
|
# File 'lib/cisco_node_utils/interface.rb', line 784
def switchport_vtp
return false unless switchport_vtp_mode_capable?
config_get('interface', 'vtp', @name)
end
|
#switchport_vtp=(vtp_set) ⇒ Object
789
790
791
792
793
794
795
|
# File 'lib/cisco_node_utils/interface.rb', line 789
def switchport_vtp=(vtp_set)
return false unless switchport_vtp_mode_capable?
no_cmd = (vtp_set) ? '' : 'no'
config_set('interface', 'vtp', @name, no_cmd)
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end
|
#switchport_vtp_feature? ⇒ Boolean
847
848
849
|
# File 'lib/cisco_node_utils/interface.rb', line 847
def switchport_vtp_feature?
config_get('vtp', 'feature')
end
|
#switchport_vtp_mode_capable? ⇒ Boolean
780
781
782
|
# File 'lib/cisco_node_utils/interface.rb', line 780
def switchport_vtp_mode_capable?
!switchport_mode.to_s.match(/(access|trunk)/).nil?
end
|
#system_default_svi_autostate ⇒ Object
765
766
767
768
769
770
771
772
773
774
775
776
777
778
|
# File 'lib/cisco_node_utils/interface.rb', line 765
def system_default_svi_autostate
result = config_get('interface', 'system_default_svi_autostate')
/N7K/.match(node.product_id) ? !result : result
end
|
#system_default_switchport ⇒ Object
747
748
749
750
751
752
753
754
755
756
757
758
|
# File 'lib/cisco_node_utils/interface.rb', line 747
def system_default_switchport
val = config_get('interface', 'system_default_switchport')
return (val[0][/^no /] ? false : true) if val.is_a?(Array)
val
end
|
#system_default_switchport_shutdown ⇒ Object
760
761
762
763
|
# File 'lib/cisco_node_utils/interface.rb', line 760
def system_default_switchport_shutdown
config_get('interface', 'system_default_switchport_shutdown')
end
|
#vlan_mapping ⇒ Object
700
701
702
703
704
|
# File 'lib/cisco_node_utils/interface.rb', line 700
def vlan_mapping
match = config_get('interface', 'vlan_mapping', @name)
match.each(&:compact!) unless match.nil?
match
end
|
#vlan_mapping=(should_list) ⇒ Object
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
|
# File 'lib/cisco_node_utils/interface.rb', line 706
def vlan_mapping=(should_list)
Vni.feature_vni_enable unless Vni.feature_vni_enabled
delta_hash = Utils.delta_add_remove(should_list, vlan_mapping,
:updates_not_allowed)
return if delta_hash.values.flatten.empty?
[:remove, :add].each do |action|
CiscoLogger.debug("vlan_mapping delta #{@get_args}\n"\
"#{action}: #{delta_hash[action]}")
delta_hash[action].each do |original, translated|
state = (action == :add) ? '' : 'no'
config_set('interface', 'vlan_mapping', @name,
state, original, translated)
end
end
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end
|
#vlan_mapping_enable ⇒ Object
734
735
736
|
# File 'lib/cisco_node_utils/interface.rb', line 734
def vlan_mapping_enable
config_get('interface', 'vlan_mapping_enable', @name)
end
|
#vlan_mapping_enable=(state) ⇒ Object
738
739
740
741
|
# File 'lib/cisco_node_utils/interface.rb', line 738
def vlan_mapping_enable=(state)
config_set('interface', 'vlan_mapping_enable', @name,
state ? '' : 'no')
end
|
#vpc_id ⇒ Object
856
857
858
|
# File 'lib/cisco_node_utils/interface.rb', line 856
def vpc_id
config_get('interface', 'vpc_id', @name)
end
|
#vpc_id=(num) ⇒ Object
860
861
862
863
864
865
866
867
868
|
# File 'lib/cisco_node_utils/interface.rb', line 860
def vpc_id=(num)
if num
config_set('interface', 'vpc_id', @name, '', num)
else
num = vpc_id
config_set('interface', 'vpc_id', @name, 'no', num)
end
end
|
#vpc_peer_link ⇒ Object
874
875
876
|
# File 'lib/cisco_node_utils/interface.rb', line 874
def vpc_peer_link
config_get('interface', 'vpc_peer_link', @name)
end
|
#vpc_peer_link=(state) ⇒ Object
878
879
880
881
|
# File 'lib/cisco_node_utils/interface.rb', line 878
def vpc_peer_link=(state)
no_cmd = (state ? '' : 'no')
config_set('interface', 'vpc_peer_link', @name, no_cmd)
end
|
#vrf ⇒ Object
887
888
889
|
# File 'lib/cisco_node_utils/interface.rb', line 887
def vrf
config_get('interface', 'vrf', @name)
end
|
#vrf=(vrf) ⇒ Object
891
892
893
894
895
896
897
898
899
900
|
# File 'lib/cisco_node_utils/interface.rb', line 891
def vrf=(vrf)
fail TypeError unless vrf.is_a?(String)
if vrf.empty?
config_set('interface', 'vrf', @name, 'no', '')
else
config_set('interface', 'vrf', @name, '', vrf)
end
rescue Cisco::CliError => e
raise "[#{@name}] '#{e.command}' : #{e.clierror}"
end
|