Class: Cisco::Interface
Overview
Interface - node utility class for general interface config management
Constant Summary
collapse
- ETHERNET =
Regexp to match various Ethernet interface variants:
Ethernet
GigabitEthernet
TenGigE
HundredGigE
MgmtEth
Regexp.new('(Ethernet|GigE|MgmtEth)', Regexp::IGNORECASE)
- PORTCHANNEL =
Regexp to match various link bundle interface variants
Regexp.new('(port-channel|Bundle-Ether)', Regexp::IGNORECASE)
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#access_vlan ⇒ Object
For range based attributes, a new attribute purge will be added in future.
-
#access_vlan=(vlan) ⇒ Object
-
#check_switchport(status) ⇒ Object
-
#cli_error_check(result) ⇒ Object
Interface private vlan configuration properties private vlan mode (host, promisc, trunk promisc , trunk sec) private vlan mapping private vlan native vlan private vlan allow vlan.
-
#configure_private_vlan_host_property(property, should_list_new, is_list_new, pr_vlan) ⇒ Object
-
#configure_private_vlan_trunk_property(property, should_list_new, is_list, pr_vlan) ⇒ Object
-
#create ⇒ Object
-
#default_access_vlan ⇒ Object
-
#default_description ⇒ Object
-
#default_duplex ⇒ Object
-
#default_encapsulation_dot1q ⇒ Object
-
#default_fabric_forwarding_anycast_gateway ⇒ Object
-
#default_ipv4_acl_in ⇒ Object
-
#default_ipv4_acl_out ⇒ Object
-
#default_ipv4_address ⇒ Object
-
#default_ipv4_address_secondary ⇒ Object
-
#default_ipv4_arp_timeout ⇒ Object
-
#default_ipv4_forwarding ⇒ Object
-
#default_ipv4_netmask_length ⇒ Object
-
#default_ipv4_netmask_length_secondary ⇒ Object
-
#default_ipv4_pim_sparse_mode ⇒ Object
-
#default_ipv4_proxy_arp ⇒ Object
-
#default_ipv4_redirects ⇒ Object
-
#default_ipv6_acl_in ⇒ Object
-
#default_ipv6_acl_out ⇒ Object
-
#default_mtu ⇒ Object
-
#default_negotiate_auto ⇒ Object
-
#default_private_vlan_mapping ⇒ Object
-
#default_shutdown ⇒ Object
-
#default_speed ⇒ Object
-
#default_stp_bpdufilter ⇒ Object
-
#default_stp_bpduguard ⇒ Object
-
#default_stp_cost ⇒ Object
-
#default_stp_guard ⇒ Object
-
#default_stp_link_type ⇒ Object
-
#default_stp_mst_cost ⇒ Object
-
#default_stp_mst_port_priority ⇒ Object
-
#default_stp_port_priority ⇒ Object
-
#default_stp_port_type ⇒ Object
-
#default_stp_vlan_cost ⇒ Object
-
#default_stp_vlan_port_priority ⇒ Object
-
#default_svi_autostate ⇒ Object
-
#default_svi_management ⇒ Object
-
#default_switchport_autostate_exclude ⇒ Object
-
#default_switchport_mode ⇒ Object
-
#default_switchport_mode_private_vlan_host ⇒ Object
-
#default_switchport_mode_private_vlan_host_association ⇒ Object
-
#default_switchport_mode_private_vlan_host_promisc ⇒ Object
-
#default_switchport_mode_private_vlan_trunk_promiscuous ⇒ Object
-
#default_switchport_mode_private_vlan_trunk_secondary ⇒ Object
-
#default_switchport_private_vlan_association_trunk ⇒ Object
-
#default_switchport_private_vlan_mapping_trunk ⇒ Object
-
#default_switchport_private_vlan_trunk_allowed_vlan ⇒ Object
-
#default_switchport_private_vlan_trunk_native_vlan ⇒ Object
-
#default_switchport_trunk_allowed_vlan ⇒ Object
-
#default_switchport_trunk_native_vlan ⇒ Object
-
#default_switchport_vtp ⇒ Object
-
#default_vlan_mapping ⇒ Object
Getter: Builds an array of vlan_mapping commands currently on the device.
-
#default_vlan_mapping_enable ⇒ Object
cli: switchport vlan mapping enable.
-
#default_vpc_id ⇒ Object
-
#default_vpc_peer_link ⇒ Object
-
#default_vrf ⇒ Object
-
#description ⇒ Object
-
#description=(desc) ⇒ Object
-
#destroy ⇒ Object
-
#duplex ⇒ Object
-
#duplex=(val) ⇒ Object
-
#encapsulation_dot1q ⇒ Object
-
#encapsulation_dot1q=(val) ⇒ Object
-
#fabric_forwarding_anycast_gateway ⇒ Object
-
#fabric_forwarding_anycast_gateway=(state) ⇒ Object
-
#fabricpath_feature ⇒ Object
-
#fabricpath_feature_set(fabricpath_set) ⇒ Object
-
#feature_lacp? ⇒ Boolean
-
#feature_lacp_set(val) ⇒ Object
-
#feature_vlan? ⇒ Boolean
-
#feature_vlan_set(val) ⇒ Object
-
#initialize(name, instantiate = true) ⇒ Interface
constructor
A new instance of Interface.
-
#interf_vlan_list_delta(property, is_list, should_list) ⇒ Object
————————– interf_vlan_list_delta is a helper function for the private_vlan_mapping property.
-
#ipv4_acl_in ⇒ Object
-
#ipv4_acl_in=(val) ⇒ Object
-
#ipv4_acl_out ⇒ Object
-
#ipv4_acl_out=(val) ⇒ Object
-
#ipv4_addr_mask ⇒ Object
-
#ipv4_addr_mask_set(addr, mask, secondary = false) ⇒ Object
-
#ipv4_address ⇒ Object
-
#ipv4_address_secondary ⇒ Object
-
#ipv4_arp_timeout ⇒ Object
-
#ipv4_arp_timeout=(timeout) ⇒ Object
-
#ipv4_arp_timeout_lookup_string ⇒ Object
-
#ipv4_forwarding ⇒ Object
-
#ipv4_forwarding=(state) ⇒ Object
-
#ipv4_netmask_length ⇒ Object
-
#ipv4_netmask_length_secondary ⇒ Object
-
#ipv4_pim_sparse_mode ⇒ Object
-
#ipv4_pim_sparse_mode=(state) ⇒ Object
-
#ipv4_proxy_arp ⇒ Object
-
#ipv4_proxy_arp=(proxy_arp) ⇒ Object
-
#ipv4_redirects ⇒ Object
-
#ipv4_redirects=(redirects) ⇒ Object
-
#ipv4_redirects_lookup_string ⇒ Object
-
#ipv6_acl_in ⇒ Object
-
#ipv6_acl_in=(val) ⇒ Object
-
#ipv6_acl_out ⇒ Object
-
#ipv6_acl_out=(val) ⇒ Object
-
#mtu ⇒ Object
-
#mtu=(val) ⇒ Object
-
#mtu_lookup_string ⇒ Object
-
#negotiate_auto ⇒ Object
-
#negotiate_auto=(negotiate_auto) ⇒ Object
-
#negotiate_auto_lookup_string ⇒ Object
-
#prepare_array(is_list) ⇒ Object
This api is used by private vlan to prepare the input to the setter method.
-
#private_vlan_mapping ⇒ Object
-
#private_vlan_mapping=(vlans) ⇒ Object
-
#select_ipv4_attribute(attribute) ⇒ Object
-
#set_range_based_params(list, param_name) ⇒ Object
-
#shutdown ⇒ Object
-
#shutdown=(state) ⇒ Object
-
#speed ⇒ Object
-
#speed=(val) ⇒ Object
-
#stp_bpdufilter ⇒ Object
-
#stp_bpdufilter=(val) ⇒ Object
-
#stp_bpduguard ⇒ Object
-
#stp_bpduguard=(val) ⇒ Object
-
#stp_cost ⇒ Object
-
#stp_cost=(val) ⇒ Object
-
#stp_guard ⇒ Object
-
#stp_guard=(val) ⇒ Object
-
#stp_link_type ⇒ Object
-
#stp_link_type=(val) ⇒ Object
-
#stp_mst_cost ⇒ Object
Getter: Builds an array of mst cost commands currently on the device.
-
#stp_mst_cost=(list) ⇒ Object
-
#stp_mst_port_priority ⇒ Object
Getter: Builds an array of mst port-priority commands currently on the device.
-
#stp_mst_port_priority=(list) ⇒ Object
-
#stp_port_priority ⇒ Object
-
#stp_port_priority=(val) ⇒ Object
-
#stp_port_type ⇒ Object
-
#stp_port_type=(val) ⇒ Object
-
#stp_vlan_cost ⇒ Object
Getter: Builds an array of vlan cost commands currently on the device.
-
#stp_vlan_cost=(list) ⇒ Object
-
#stp_vlan_port_priority ⇒ Object
Getter: Builds an array of vlan port-priority commands currently on the device.
-
#stp_vlan_port_priority=(list) ⇒ Object
-
#svi_autostate ⇒ Object
svi_autostate is exclusive to svi interfaces.
-
#svi_autostate=(val) ⇒ Object
-
#svi_cmd_allowed?(cmd) ⇒ Boolean
-
#svi_management ⇒ Object
svi_management is exclusive to svi interfaces.
-
#svi_management=(val) ⇒ Object
-
#switchport ⇒ Object
-
#switchport_autostate_exclude ⇒ Object
switchport_autostate_exclude is exclusive to switchport interfaces.
-
#switchport_autostate_exclude=(val) ⇒ Object
-
#switchport_enable(val = true) ⇒ Object
-
#switchport_enable_and_mode(mode_set) ⇒ Object
-
#switchport_enable_and_mode_private_vlan_host(mode_set) ⇒ Object
-
#switchport_mode ⇒ Object
-
#switchport_mode=(mode_set) ⇒ Object
-
#switchport_mode_lookup_string ⇒ Object
-
#switchport_mode_private_vlan_host ⇒ Object
-
#switchport_mode_private_vlan_host=(mode_set) ⇒ Object
-
#switchport_mode_private_vlan_host_association ⇒ Object
-
#switchport_mode_private_vlan_host_association=(vlans) ⇒ Object
-
#switchport_mode_private_vlan_host_promisc ⇒ Object
-
#switchport_mode_private_vlan_host_promisc=(vlans) ⇒ Object
-
#switchport_mode_private_vlan_trunk_promiscuous ⇒ Object
-
#switchport_mode_private_vlan_trunk_promiscuous=(state) ⇒ Object
-
#switchport_mode_private_vlan_trunk_secondary ⇒ Object
-
#switchport_mode_private_vlan_trunk_secondary=(state) ⇒ Object
-
#switchport_private_vlan_association_trunk ⇒ Object
-
#switchport_private_vlan_association_trunk=(vlans) ⇒ Object
-
#switchport_private_vlan_mapping_trunk ⇒ Object
-
#switchport_private_vlan_mapping_trunk=(vlans) ⇒ Object
-
#switchport_private_vlan_trunk_allowed_vlan ⇒ Object
-
#switchport_private_vlan_trunk_allowed_vlan=(vlans) ⇒ Object
-
#switchport_private_vlan_trunk_native_vlan ⇒ Object
-
#switchport_private_vlan_trunk_native_vlan=(vlan) ⇒ Object
-
#switchport_status?(status) ⇒ Boolean
-
#switchport_trunk_allowed_vlan ⇒ Object
-
#switchport_trunk_allowed_vlan=(val) ⇒ Object
-
#switchport_trunk_native_vlan ⇒ Object
-
#switchport_trunk_native_vlan=(val) ⇒ Object
-
#switchport_vtp ⇒ Object
-
#switchport_vtp=(vtp_set) ⇒ Object
-
#switchport_vtp_feature? ⇒ Boolean
-
#switchport_vtp_mode_capable? ⇒ Boolean
-
#system_default_svi_autostate ⇒ Object
-
#system_default_switchport ⇒ Object
-
#system_default_switchport_shutdown ⇒ Object
-
#to_s ⇒ Object
-
#vlan_mapping ⇒ Object
-
#vlan_mapping=(should_list) ⇒ Object
-
#vlan_mapping_enable ⇒ Object
-
#vlan_mapping_enable=(state) ⇒ Object
-
#vpc_id ⇒ Object
-
#vpc_id=(num) ⇒ Object
-
#vpc_peer_link ⇒ Object
-
#vpc_peer_link=(state) ⇒ Object
-
#vrf ⇒ Object
-
#vrf=(v) ⇒ Object
Methods inherited from NodeUtil
client, #client, config_get, #config_get, #config_get_default, config_get_default, config_set, #config_set, #get, #ios_xr?, #nexus?, #node, node, platform, #platform, supports?, #supports?
Constructor Details
#initialize(name, instantiate = true) ⇒ Interface
Returns a new instance of Interface.
58
59
60
61
62
63
64
65
66
|
# File 'lib/cisco_node_utils/interface.rb', line 58
def initialize(name, instantiate=true)
fail TypeError unless name.is_a?(String)
fail ArgumentError unless name.length > 0
@name = name.downcase
@smr = config_get('interface', 'stp_mst_range')
@svr = config_get('interface', 'stp_vlan_range')
@match_found = false
create if instantiate
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
56
57
58
|
# File 'lib/cisco_node_utils/interface.rb', line 56
def name
@name
end
|
Class Method Details
.capabilities(intf, mode = :hash) ⇒ Object
‘capabilities’ is a getter-only helper for minitest and beaker. mode values:
:hash = Transform the output into a hash
:raw = The raw output from 'show int capabilities'. Some multi-line
values do not translate easily so this option allows the
caller to extract the data it needs.
Sample cli output:
Model: N7K-M132XP-12L
Type (SFP capable): 10Gbase-SR
Speed: 10,100,1000
Sample hash output: “Type”=>“10Gbase-SR”, “Speed”=>“10,100,1000”
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/cisco_node_utils/interface.rb', line 113
def self.capabilities(intf, mode=:hash)
array = config_get('interface', 'capabilities', name: intf)
return array if mode == :raw
hash = {}
if array
array.delete('')
array.each do |line|
k, v = line.split(':')
next if k.nil? || v.nil?
k.gsub!(/ \(.*\)/, '') v.strip!
hash[k] = v
end
end
hash
end
|
.filter(opt, id) ⇒ Object
General-purpose filter for Interface.interfaces().
opt: Identifies the filter. This may be overloaded in the future to
allow a hash of filter conditions.
id: The interface name
Return: true if the interface should be filtered out, false to keep it.
90
91
92
93
94
95
96
|
# File 'lib/cisco_node_utils/interface.rb', line 90
def self.filter(opt, id)
case opt
when :private_vlan_any
return false if config_get('interface', 'private_vlan_any', name: id)
end
true
end
|
.interfaces(opt = nil) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/cisco_node_utils/interface.rb', line 72
def self.interfaces(opt=nil)
hash = {}
intf_list = config_get('interface', 'all_interfaces')
return hash if intf_list.nil?
intf_list.each do |id|
id = id.downcase
next if opt && filter(opt, id)
hash[id] = Interface.new(id, false)
end
hash
end
|
Instance Method Details
#access_vlan ⇒ Object
For range based attributes, a new attribute purge will be added in future. When purge is set to true, all the ranges which are specified in the manifest will be set to the desired values and those which are not specified in the manifest will be set to default. When purge is false, only the ranges specified in the manifest will be set to the values given in the manifest and others are left untouched.
158
159
160
|
# File 'lib/cisco_node_utils/interface.rb', line 158
def access_vlan
config_get('interface', 'access_vlan', name: @name)
end
|
#access_vlan=(vlan) ⇒ Object
162
163
164
|
# File 'lib/cisco_node_utils/interface.rb', line 162
def access_vlan=(vlan)
config_set('interface', 'access_vlan', name: @name, vlan: vlan)
end
|
#check_switchport(status) ⇒ Object
1615
1616
1617
1618
1619
|
# File 'lib/cisco_node_utils/interface.rb', line 1615
def check_switchport(status)
return if switchport_status?(status)
fail("#{caller[0][/`.*'/][1..-2]} cannot be set unless " \
"switchport mode is #{status}")
end
|
#cli_error_check(result) ⇒ Object
Interface private vlan configuration properties private vlan mode (host, promisc, trunk promisc , trunk sec) private vlan mapping private vlan native vlan private vlan allow vlan
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
|
# File 'lib/cisco_node_utils/interface.rb', line 967
def cli_error_check(result)
errors = /(ERROR:|VLAN:|Eth)/
return unless
result[1].is_a?(Hash) && errors.match(result[1]['body'].to_s)
error_list =
(result[1]['body'].split(errors) - ['']).each_slice(2).map(&:join)
error_list.each do |_msg|
fail result[1]['body']
end
end
|
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
|
# File 'lib/cisco_node_utils/interface.rb', line 1095
def configure_private_vlan_host_property(property, should_list_new,
is_list_new, pr_vlan)
delta_hash = Utils.delta_add_remove(should_list_new, is_list_new)
[:add, :remove].each do |action|
delta_hash[action].each do |vlans|
state = (action == :add) ? '' : 'no'
oper = (action == :add) ? 'add' : 'remove'
if property[/(host_promisc|mapping_trunk)/]
result = config_set('interface', PVLAN_PROPERTY[property],
name: @name, state: state,
vlan_pr: pr_vlan, vlans: vlans)
@match_found = true
end
if property[/allow_vlan/]
result = config_set('interface',
PVLAN_PROPERTY[property],
name: @name, state: '',
oper: oper, vlans: vlans)
end
if property[/vlan_mapping/]
result = config_set('interface',
PVLAN_PROPERTY[property],
name: @name, state: state,
vlans: vlans)
end
cli_error_check(result)
end
end
end
|
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
|
# File 'lib/cisco_node_utils/interface.rb', line 1126
def configure_private_vlan_trunk_property(property, should_list_new,
is_list, pr_vlan)
case property
when :trunk_assoc
is_list.each do |vlans|
vlans = vlans.split(' ')
if vlans[0].eql? should_list_new[0]
config_set('interface',
'switchport_private_vlan_association_trunk',
name: @name, state: 'no',
vlan_pr: pr_vlan, vlan: vlans[1])
break
else
next
end
end
result = config_set('interface', PVLAN_PROPERTY[property], name: @name,
state: '', vlan_pr: should_list_new[0],
vlan: should_list_new[1])
when :mapping_trunk
@match_found = false
is_list.each do |vlans|
vlans = vlans.split(' ')
interf_vlan_list_delta(:mapping_trunk, vlans,
should_list_new)
if @match_found
break
else
next
end
end
result = config_set('interface', PVLAN_PROPERTY[property], name: @name,
state: '', vlan_pr: should_list_new[0],
vlans: should_list_new[1])
end
cli_error_check(result)
end
|
#create ⇒ Object
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/cisco_node_utils/interface.rb', line 130
def create
feature_vlan_set(true) if @name[/(vlan|bdi)/i]
config_set('interface', 'create', name: @name)
rescue Cisco::CliError
raise unless PORTCHANNEL =~ @name && platform == :ios_xr
raise Cisco::UnsupportedError.new('interface', @name, 'create')
end
|
#default_access_vlan ⇒ Object
166
167
168
|
# File 'lib/cisco_node_utils/interface.rb', line 166
def default_access_vlan
config_get_default('interface', 'access_vlan')
end
|
#default_description ⇒ Object
185
186
187
|
# File 'lib/cisco_node_utils/interface.rb', line 185
def default_description
config_get_default('interface', 'description')
end
|
#default_duplex ⇒ Object
552
553
554
|
# File 'lib/cisco_node_utils/interface.rb', line 552
def default_duplex
config_get_default('interface', 'duplex')
end
|
#default_encapsulation_dot1q ⇒ Object
203
204
205
|
# File 'lib/cisco_node_utils/interface.rb', line 203
def default_encapsulation_dot1q
config_get_default('interface', 'encapsulation_dot1q')
end
|
#default_fabric_forwarding_anycast_gateway ⇒ Object
236
237
238
|
# File 'lib/cisco_node_utils/interface.rb', line 236
def default_fabric_forwarding_anycast_gateway
config_get_default('interface', 'fabric_forwarding_anycast_gateway')
end
|
#default_ipv4_acl_in ⇒ Object
257
258
259
|
# File 'lib/cisco_node_utils/interface.rb', line 257
def default_ipv4_acl_in
config_get_default('interface', 'ipv4_acl_in')
end
|
#default_ipv4_acl_out ⇒ Object
278
279
280
|
# File 'lib/cisco_node_utils/interface.rb', line 278
def default_ipv4_acl_out
config_get_default('interface', 'ipv4_acl_out')
end
|
#default_ipv4_address ⇒ Object
353
354
355
|
# File 'lib/cisco_node_utils/interface.rb', line 353
def default_ipv4_address
config_get_default('interface', 'ipv4_address')
end
|
#default_ipv4_address_secondary ⇒ Object
357
358
359
|
# File 'lib/cisco_node_utils/interface.rb', line 357
def default_ipv4_address_secondary
default_ipv4_address
end
|
#default_ipv4_arp_timeout ⇒ Object
390
391
392
|
# File 'lib/cisco_node_utils/interface.rb', line 390
def default_ipv4_arp_timeout
config_get_default('interface', ipv4_arp_timeout_lookup_string)
end
|
#default_ipv4_forwarding ⇒ Object
403
404
405
|
# File 'lib/cisco_node_utils/interface.rb', line 403
def default_ipv4_forwarding
config_get_default('interface', 'ipv4_forwarding')
end
|
#default_ipv4_netmask_length ⇒ Object
361
362
363
|
# File 'lib/cisco_node_utils/interface.rb', line 361
def default_ipv4_netmask_length
config_get_default('interface', 'ipv4_netmask_length')
end
|
#default_ipv4_netmask_length_secondary ⇒ Object
365
366
367
|
# File 'lib/cisco_node_utils/interface.rb', line 365
def default_ipv4_netmask_length_secondary
default_ipv4_netmask_length
end
|
#default_ipv4_pim_sparse_mode ⇒ Object
418
419
420
|
# File 'lib/cisco_node_utils/interface.rb', line 418
def default_ipv4_pim_sparse_mode
config_get_default('interface', 'ipv4_pim_sparse_mode')
end
|
#default_ipv4_proxy_arp ⇒ Object
432
433
434
|
# File 'lib/cisco_node_utils/interface.rb', line 432
def default_ipv4_proxy_arp
config_get_default('interface', 'ipv4_proxy_arp')
end
|
#default_ipv4_redirects ⇒ Object
456
457
458
|
# File 'lib/cisco_node_utils/interface.rb', line 456
def default_ipv4_redirects
config_get_default('interface', ipv4_redirects_lookup_string)
end
|
#default_ipv6_acl_in ⇒ Object
476
477
478
|
# File 'lib/cisco_node_utils/interface.rb', line 476
def default_ipv6_acl_in
config_get_default('interface', 'ipv6_acl_in')
end
|
#default_ipv6_acl_out ⇒ Object
496
497
498
|
# File 'lib/cisco_node_utils/interface.rb', line 496
def default_ipv6_acl_out
config_get_default('interface', 'ipv6_acl_out')
end
|
#default_mtu ⇒ Object
528
529
530
|
# File 'lib/cisco_node_utils/interface.rb', line 528
def default_mtu
config_get_default('interface', mtu_lookup_string)
end
|
#default_negotiate_auto ⇒ Object
577
578
579
|
# File 'lib/cisco_node_utils/interface.rb', line 577
def default_negotiate_auto
config_get_default('interface', negotiate_auto_lookup_string)
end
|
#default_private_vlan_mapping ⇒ Object
1427
1428
1429
1430
|
# File 'lib/cisco_node_utils/interface.rb', line 1427
def default_private_vlan_mapping
config_get_default('interface',
'private_vlan_mapping')
end
|
#default_shutdown ⇒ Object
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
|
# File 'lib/cisco_node_utils/interface.rb', line 590
def default_shutdown
case @name
when ETHERNET
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 PORTCHANNEL
lookup = 'shutdown_ether_channel'
when /Vlan/i
lookup = 'shutdown_vlan'
else
lookup = 'shutdown_unknown'
end
config_get_default('interface', lookup)
end
|
#default_speed ⇒ Object
540
541
542
|
# File 'lib/cisco_node_utils/interface.rb', line 540
def default_speed
config_get_default('interface', 'speed')
end
|
#default_stp_bpdufilter ⇒ Object
639
640
641
|
# File 'lib/cisco_node_utils/interface.rb', line 639
def default_stp_bpdufilter
config_get_default('interface', 'stp_bpdufilter')
end
|
#default_stp_bpduguard ⇒ Object
658
659
660
|
# File 'lib/cisco_node_utils/interface.rb', line 658
def default_stp_bpduguard
config_get_default('interface', 'stp_bpduguard')
end
|
#default_stp_cost ⇒ Object
672
673
674
|
# File 'lib/cisco_node_utils/interface.rb', line 672
def default_stp_cost
config_get_default('interface', 'stp_cost')
end
|
#default_stp_guard ⇒ Object
692
693
694
|
# File 'lib/cisco_node_utils/interface.rb', line 692
def default_stp_guard
config_get_default('interface', 'stp_guard')
end
|
#default_stp_link_type ⇒ Object
705
706
707
|
# File 'lib/cisco_node_utils/interface.rb', line 705
def default_stp_link_type
config_get_default('interface', 'stp_link_type')
end
|
#default_stp_mst_cost ⇒ Object
740
741
742
|
# File 'lib/cisco_node_utils/interface.rb', line 740
def default_stp_mst_cost
config_get_default('interface', 'stp_mst_cost')
end
|
#default_stp_mst_port_priority ⇒ Object
762
763
764
|
# File 'lib/cisco_node_utils/interface.rb', line 762
def default_stp_mst_port_priority
config_get_default('interface', 'stp_mst_port_priority')
end
|
#default_stp_port_priority ⇒ Object
718
719
720
|
# File 'lib/cisco_node_utils/interface.rb', line 718
def default_stp_port_priority
config_get_default('interface', 'stp_port_priority')
end
|
#default_stp_port_type ⇒ Object
781
782
783
|
# File 'lib/cisco_node_utils/interface.rb', line 781
def default_stp_port_type
config_get_default('interface', 'stp_port_type')
end
|
#default_stp_vlan_cost ⇒ Object
803
804
805
|
# File 'lib/cisco_node_utils/interface.rb', line 803
def default_stp_vlan_cost
config_get_default('interface', 'stp_vlan_cost')
end
|
#default_stp_vlan_port_priority ⇒ Object
825
826
827
|
# File 'lib/cisco_node_utils/interface.rb', line 825
def default_stp_vlan_port_priority
config_get_default('interface', 'stp_vlan_port_priority')
end
|
#default_svi_autostate ⇒ Object
1563
1564
1565
|
# File 'lib/cisco_node_utils/interface.rb', line 1563
def default_svi_autostate
system_default_svi_autostate
end
|
#default_svi_management ⇒ Object
1589
1590
1591
|
# File 'lib/cisco_node_utils/interface.rb', line 1589
def default_svi_management
config_get_default('interface', 'svi_management')
end
|
#default_switchport_autostate_exclude ⇒ Object
855
856
857
|
# File 'lib/cisco_node_utils/interface.rb', line 855
def default_switchport_autostate_exclude
config_get_default('interface', 'switchport_autostate_exclude')
end
|
#default_switchport_mode ⇒ Object
922
923
924
925
926
927
|
# File 'lib/cisco_node_utils/interface.rb', line 922
def default_switchport_mode
return nil if platform == :ios_xr
return :disabled unless system_default_switchport
IF_SWITCHPORT_MODE.key(
config_get_default('interface', switchport_mode_lookup_string))
end
|
#default_switchport_mode_private_vlan_host ⇒ Object
1019
1020
1021
1022
|
# File 'lib/cisco_node_utils/interface.rb', line 1019
def default_switchport_mode_private_vlan_host
config_get_default('interface',
'switchport_mode_private_vlan_host')
end
|
#default_switchport_mode_private_vlan_host_association ⇒ Object
1053
1054
1055
1056
|
# File 'lib/cisco_node_utils/interface.rb', line 1053
def default_switchport_mode_private_vlan_host_association
config_get_default('interface',
'switchport_mode_private_vlan_host_association')
end
|
#default_switchport_mode_private_vlan_host_promisc ⇒ Object
1222
1223
1224
1225
|
# File 'lib/cisco_node_utils/interface.rb', line 1222
def default_switchport_mode_private_vlan_host_promisc
config_get_default('interface',
'switchport_mode_private_vlan_host_promiscous')
end
|
#default_switchport_mode_private_vlan_trunk_promiscuous ⇒ Object
1253
1254
1255
1256
|
# File 'lib/cisco_node_utils/interface.rb', line 1253
def default_switchport_mode_private_vlan_trunk_promiscuous
config_get_default('interface',
'switchport_mode_private_vlan_trunk_promiscuous')
end
|
#default_switchport_mode_private_vlan_trunk_secondary ⇒ Object
1282
1283
1284
1285
|
# File 'lib/cisco_node_utils/interface.rb', line 1282
def default_switchport_mode_private_vlan_trunk_secondary
config_get_default('interface',
'switchport_mode_private_vlan_trunk_secondary')
end
|
#default_switchport_private_vlan_association_trunk ⇒ Object
1372
1373
1374
1375
|
# File 'lib/cisco_node_utils/interface.rb', line 1372
def default_switchport_private_vlan_association_trunk
config_get_default('interface',
'switchport_private_vlan_association_trunk')
end
|
#default_switchport_private_vlan_mapping_trunk ⇒ Object
1398
1399
1400
1401
|
# File 'lib/cisco_node_utils/interface.rb', line 1398
def default_switchport_private_vlan_mapping_trunk
config_get_default('interface',
'switchport_private_vlan_mapping_trunk')
end
|
#default_switchport_private_vlan_trunk_allowed_vlan ⇒ Object
1320
1321
1322
1323
|
# File 'lib/cisco_node_utils/interface.rb', line 1320
def default_switchport_private_vlan_trunk_allowed_vlan
config_get_default('interface',
'switchport_private_vlan_trunk_allowed_vlan')
end
|
#default_switchport_private_vlan_trunk_native_vlan ⇒ Object
1346
1347
1348
1349
|
# File 'lib/cisco_node_utils/interface.rb', line 1346
def default_switchport_private_vlan_trunk_native_vlan
config_get_default('interface',
'switchport_private_vlan_trunk_native_vlan')
end
|
#default_switchport_trunk_allowed_vlan ⇒ Object
943
944
945
|
# File 'lib/cisco_node_utils/interface.rb', line 943
def default_switchport_trunk_allowed_vlan
config_get_default('interface', 'switchport_trunk_allowed_vlan')
end
|
#default_switchport_trunk_native_vlan ⇒ Object
1492
1493
1494
|
# File 'lib/cisco_node_utils/interface.rb', line 1492
def default_switchport_trunk_native_vlan
config_get_default('interface', 'switchport_trunk_native_vlan')
end
|
#default_switchport_vtp ⇒ Object
1593
1594
1595
1596
|
# File 'lib/cisco_node_utils/interface.rb', line 1593
def default_switchport_vtp
return nil unless switchport_vtp_mode_capable?
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’]]
1447
1448
1449
|
# File 'lib/cisco_node_utils/interface.rb', line 1447
def default_vlan_mapping
config_get_default('interface', 'vlan_mapping')
end
|
#default_vlan_mapping_enable ⇒ Object
cli: switchport vlan mapping enable
1479
1480
1481
|
# File 'lib/cisco_node_utils/interface.rb', line 1479
def default_vlan_mapping_enable
config_get_default('interface', 'vlan_mapping_enable')
end
|
#default_vpc_id ⇒ Object
1635
1636
1637
|
# File 'lib/cisco_node_utils/interface.rb', line 1635
def default_vpc_id
config_get_default('interface', 'vpc_id')
end
|
#default_vpc_peer_link ⇒ Object
1648
1649
1650
|
# File 'lib/cisco_node_utils/interface.rb', line 1648
def default_vpc_peer_link
config_get_default('interface', 'vpc_peer_link')
end
|
#default_vrf ⇒ Object
1678
1679
1680
|
# File 'lib/cisco_node_utils/interface.rb', line 1678
def default_vrf
config_get_default('interface', 'vrf')
end
|
#description ⇒ Object
170
171
172
|
# File 'lib/cisco_node_utils/interface.rb', line 170
def description
config_get('interface', 'description', name: @name)
end
|
#description=(desc) ⇒ Object
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/cisco_node_utils/interface.rb', line 174
def description=(desc)
fail TypeError unless desc.is_a?(String)
if desc.strip.empty?
config_set('interface', 'description',
name: @name, state: 'no', desc: '')
else
config_set('interface', 'description',
name: @name, state: '', desc: desc)
end
end
|
#destroy ⇒ Object
141
142
143
|
# File 'lib/cisco_node_utils/interface.rb', line 141
def destroy
config_set('interface', 'destroy', name: @name)
end
|
#duplex ⇒ Object
544
545
546
|
# File 'lib/cisco_node_utils/interface.rb', line 544
def duplex
config_get('interface', 'duplex', name: @name)
end
|
#duplex=(val) ⇒ Object
548
549
550
|
# File 'lib/cisco_node_utils/interface.rb', line 548
def duplex=(val)
config_set('interface', 'duplex', name: @name, duplex: val)
end
|
#encapsulation_dot1q ⇒ Object
189
190
191
|
# File 'lib/cisco_node_utils/interface.rb', line 189
def encapsulation_dot1q
config_get('interface', 'encapsulation_dot1q', name: @name)
end
|
#encapsulation_dot1q=(val) ⇒ Object
193
194
195
196
197
198
199
200
201
|
# File 'lib/cisco_node_utils/interface.rb', line 193
def encapsulation_dot1q=(val)
if val.to_s.empty?
config_set('interface', 'encapsulation_dot1q',
name: @name, state: 'no', vlan: '')
else
config_set('interface', 'encapsulation_dot1q',
name: @name, state: '', vlan: val)
end
end
|
#fabric_forwarding_anycast_gateway ⇒ Object
215
216
217
|
# File 'lib/cisco_node_utils/interface.rb', line 215
def fabric_forwarding_anycast_gateway
config_get('interface', 'fabric_forwarding_anycast_gateway', name: @name)
end
|
#fabric_forwarding_anycast_gateway=(state) ⇒ Object
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
# File 'lib/cisco_node_utils/interface.rb', line 219
def fabric_forwarding_anycast_gateway=(state)
no_cmd = (state ? '' : 'no')
config_set('interface',
'fabric_forwarding_anycast_gateway',
name: @name, state: no_cmd)
fail if fabric_forwarding_anycast_gateway.to_s != state.to_s
rescue Cisco::CliError => e
raise "#{e} '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 "#{e} Anycast gateway mac must be configured " \
'before configuring forwarding mode under interface'
end
raise
end
|
#fabricpath_feature ⇒ Object
#fabricpath_feature_set(fabricpath_set) ⇒ Object
#feature_lacp? ⇒ Boolean
500
501
502
|
# File 'lib/cisco_node_utils/interface.rb', line 500
def feature_lacp?
config_get('interface', 'feature_lacp')
end
|
#feature_lacp_set(val) ⇒ Object
504
505
506
507
|
# File 'lib/cisco_node_utils/interface.rb', line 504
def feature_lacp_set(val)
return if feature_lacp? == val
config_set('interface', 'feature_lacp', state: val ? '' : 'no')
end
|
#feature_vlan? ⇒ Boolean
1567
1568
1569
|
# File 'lib/cisco_node_utils/interface.rb', line 1567
def feature_vlan?
config_get('interface', 'feature_vlan')
end
|
#feature_vlan_set(val) ⇒ Object
1571
1572
1573
1574
|
# File 'lib/cisco_node_utils/interface.rb', line 1571
def feature_vlan_set(val)
return if feature_vlan? == val
config_set('interface', 'feature_vlan', state: val ? '' : 'no')
end
|
#interf_vlan_list_delta(property, is_list, should_list) ⇒ Object
interf_vlan_list_delta is a helper function for the private_vlan_mapping property. It walks the delta hash and adds/removes each target private vlan.
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
|
# File 'lib/cisco_node_utils/interface.rb', line 1169
def interf_vlan_list_delta(property, is_list, should_list)
pr_vlan = should_list[0]
if is_list[0].eql? should_list[0]
should_list = should_list[1].split(',')
is_list = is_list[1].split(',')
should_list_new = prepare_array(should_list)
is_list_new = prepare_array(is_list)
configure_private_vlan_host_property(property, should_list_new,
is_list_new, pr_vlan)
else
case property
when :mapping_trunk
return
end
if should_list == default_switchport_mode_private_vlan_host_promisc
result = config_set('interface',
'switchport_mode_private_vlan_host_promiscous',
name: @name, state: 'no',
vlan_pr: '', vlans: '')
else
result = config_set('interface',
'switchport_mode_private_vlan_host_promiscous',
name: @name, state: '',
vlan_pr: pr_vlan, vlans: should_list[1])
end
cli_error_check(result)
end
end
|
#ipv4_acl_in ⇒ Object
240
241
242
|
# File 'lib/cisco_node_utils/interface.rb', line 240
def ipv4_acl_in
config_get('interface', 'ipv4_acl_in', name: @name)
end
|
#ipv4_acl_in=(val) ⇒ Object
244
245
246
247
248
249
250
251
252
253
254
255
|
# File 'lib/cisco_node_utils/interface.rb', line 244
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: @name, state: state, acl: val)
end
|
#ipv4_acl_out ⇒ Object
261
262
263
|
# File 'lib/cisco_node_utils/interface.rb', line 261
def ipv4_acl_out
config_get('interface', 'ipv4_acl_out', name: @name)
end
|
#ipv4_acl_out=(val) ⇒ Object
265
266
267
268
269
270
271
272
273
274
275
276
|
# File 'lib/cisco_node_utils/interface.rb', line 265
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: @name, state: state, acl: val)
end
|
#ipv4_addr_mask ⇒ Object
303
304
305
306
307
308
309
310
311
312
313
314
315
|
# File 'lib/cisco_node_utils/interface.rb', line 303
def ipv4_addr_mask
val = config_get('interface', 'ipv4_addr_mask', name: @name)
if val && platform == :ios_xr
val.each_with_index do |entry, i|
mask = entry[1].split(' ')
mask[0] = Utils.bitmask_to_length(mask[0])
val[i][1] = mask.join(' ')
end
end
val
end
|
#ipv4_addr_mask_set(addr, mask, secondary = false) ⇒ Object
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
# File 'lib/cisco_node_utils/interface.rb', line 282
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: @name, state: state, addr: am, secondary: sec)
end
|
#ipv4_address ⇒ Object
337
338
339
|
# File 'lib/cisco_node_utils/interface.rb', line 337
def ipv4_address
select_ipv4_attribute(:v4_addr)
end
|
#ipv4_address_secondary ⇒ Object
341
342
343
|
# File 'lib/cisco_node_utils/interface.rb', line 341
def ipv4_address_secondary
select_ipv4_attribute(:v4_addr_secondary)
end
|
#ipv4_arp_timeout ⇒ Object
378
379
380
|
# File 'lib/cisco_node_utils/interface.rb', line 378
def ipv4_arp_timeout
config_get('interface', ipv4_arp_timeout_lookup_string, name: @name)
end
|
#ipv4_arp_timeout=(timeout) ⇒ Object
382
383
384
385
386
387
388
|
# File 'lib/cisco_node_utils/interface.rb', line 382
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: @name, state: state, timeout: timeout)
end
|
#ipv4_arp_timeout_lookup_string ⇒ Object
369
370
371
372
373
374
375
376
|
# File 'lib/cisco_node_utils/interface.rb', line 369
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_forwarding ⇒ Object
394
395
396
|
# File 'lib/cisco_node_utils/interface.rb', line 394
def ipv4_forwarding
config_get('interface', 'ipv4_forwarding', name: @name)
end
|
#ipv4_forwarding=(state) ⇒ Object
398
399
400
401
|
# File 'lib/cisco_node_utils/interface.rb', line 398
def ipv4_forwarding=(state)
config_set('interface', 'ipv4_forwarding',
name: @name, state: state ? '' : 'no')
end
|
#ipv4_netmask_length ⇒ Object
345
346
347
|
# File 'lib/cisco_node_utils/interface.rb', line 345
def ipv4_netmask_length
select_ipv4_attribute(:v4_mask)
end
|
#ipv4_netmask_length_secondary ⇒ Object
349
350
351
|
# File 'lib/cisco_node_utils/interface.rb', line 349
def ipv4_netmask_length_secondary
select_ipv4_attribute(:v4_mask_secondary)
end
|
#ipv4_pim_sparse_mode ⇒ Object
407
408
409
|
# File 'lib/cisco_node_utils/interface.rb', line 407
def ipv4_pim_sparse_mode
config_get('interface', 'ipv4_pim_sparse_mode', name: @name)
end
|
#ipv4_pim_sparse_mode=(state) ⇒ Object
411
412
413
414
415
416
|
# File 'lib/cisco_node_utils/interface.rb', line 411
def ipv4_pim_sparse_mode=(state)
check_switchport(:disabled)
Feature.pim_enable unless platform == :ios_xr
config_set('interface', 'ipv4_pim_sparse_mode',
name: @name, state: state ? '' : 'no')
end
|
#ipv4_proxy_arp ⇒ Object
422
423
424
|
# File 'lib/cisco_node_utils/interface.rb', line 422
def ipv4_proxy_arp
config_get('interface', 'ipv4_proxy_arp', name: @name)
end
|
#ipv4_proxy_arp=(proxy_arp) ⇒ Object
426
427
428
429
430
|
# File 'lib/cisco_node_utils/interface.rb', line 426
def ipv4_proxy_arp=(proxy_arp)
check_switchport(:disabled)
no_cmd = (proxy_arp ? '' : 'no')
config_set('interface', 'ipv4_proxy_arp', name: @name, state: no_cmd)
end
|
#ipv4_redirects ⇒ Object
445
446
447
|
# File 'lib/cisco_node_utils/interface.rb', line 445
def ipv4_redirects
config_get('interface', ipv4_redirects_lookup_string, name: @name)
end
|
#ipv4_redirects=(redirects) ⇒ Object
449
450
451
452
453
454
|
# File 'lib/cisco_node_utils/interface.rb', line 449
def ipv4_redirects=(redirects)
check_switchport(:disabled)
no_cmd = (redirects ? '' : 'no')
config_set('interface', ipv4_redirects_lookup_string,
name: @name, state: no_cmd)
end
|
#ipv4_redirects_lookup_string ⇒ Object
436
437
438
439
440
441
442
443
|
# File 'lib/cisco_node_utils/interface.rb', line 436
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
460
461
462
|
# File 'lib/cisco_node_utils/interface.rb', line 460
def ipv6_acl_in
config_get('interface', 'ipv6_acl_in', name: @name)
end
|
#ipv6_acl_in=(val) ⇒ Object
464
465
466
467
468
469
470
471
472
473
474
|
# File 'lib/cisco_node_utils/interface.rb', line 464
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: @name, state: state, acl: val)
end
|
#ipv6_acl_out ⇒ Object
480
481
482
|
# File 'lib/cisco_node_utils/interface.rb', line 480
def ipv6_acl_out
config_get('interface', 'ipv6_acl_out', name: @name)
end
|
#ipv6_acl_out=(val) ⇒ Object
484
485
486
487
488
489
490
491
492
493
494
|
# File 'lib/cisco_node_utils/interface.rb', line 484
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: @name, state: state, acl: val)
end
|
#mtu ⇒ Object
518
519
520
|
# File 'lib/cisco_node_utils/interface.rb', line 518
def mtu
config_get('interface', mtu_lookup_string, name: @name)
end
|
#mtu=(val) ⇒ Object
522
523
524
525
526
|
# File 'lib/cisco_node_utils/interface.rb', line 522
def mtu=(val)
check_switchport(:disabled)
config_set('interface', mtu_lookup_string,
name: @name, state: '', mtu: val)
end
|
#mtu_lookup_string ⇒ Object
509
510
511
512
513
514
515
516
|
# File 'lib/cisco_node_utils/interface.rb', line 509
def mtu_lookup_string
case @name
when /loopback/i
return 'mtu_loopback'
else
return 'mtu_other_interfaces'
end
end
|
#negotiate_auto ⇒ Object
567
568
569
|
# File 'lib/cisco_node_utils/interface.rb', line 567
def negotiate_auto
config_get('interface', negotiate_auto_lookup_string, name: @name)
end
|
#negotiate_auto=(negotiate_auto) ⇒ Object
571
572
573
574
575
|
# File 'lib/cisco_node_utils/interface.rb', line 571
def negotiate_auto=(negotiate_auto)
lookup = negotiate_auto_lookup_string
no_cmd = (negotiate_auto ? '' : 'no')
config_set('interface', lookup, name: @name, state: no_cmd)
end
|
#negotiate_auto_lookup_string ⇒ Object
556
557
558
559
560
561
562
563
564
565
|
# File 'lib/cisco_node_utils/interface.rb', line 556
def negotiate_auto_lookup_string
case @name
when ETHERNET
return 'negotiate_auto_ethernet'
when PORTCHANNEL
return 'negotiate_auto_portchannel'
else
return 'negotiate_auto_other_interfaces'
end
end
|
#prepare_array(is_list) ⇒ Object
This api is used by private vlan to prepare the input to the setter method. The input can be in the following formats for vlans: 10-12,14. Prepare_array api is transforming this input into a flat array. In the example above the returned array will be 10, 11, 12, 13. Prepare array is first splitting the input on ‘,’ and the than expanding the vlan range element like 10-12 into a flat array. The final result will be a flat array. This way we can later used the lib utility to check the delta from the input vlan value and the vlan configured to apply the right config.
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
|
# File 'lib/cisco_node_utils/interface.rb', line 1067
def prepare_array(is_list)
new_list = []
is_list.each do |item|
if item.include?(',')
new_list.push(item.split(','))
else
new_list.push(item)
end
end
new_list.flatten!
new_list.sort!
new_list.each { |item| item.gsub!('-', '..') }
is_list_new = []
new_list.each do |elem|
if elem.include?('..')
elema = elem.split('..').map { |d| Integer(d) }
elema.sort!
tr = elema[0]..elema[1]
tr.to_a.each do |item|
is_list_new.push(item.to_s)
end
else
is_list_new.push(elem)
end
end
is_list_new
end
|
#private_vlan_mapping ⇒ Object
1403
1404
1405
1406
1407
1408
1409
|
# File 'lib/cisco_node_utils/interface.rb', line 1403
def private_vlan_mapping
match = config_get('interface',
'private_vlan_mapping',
name: @name)
match[0].delete!(' ') unless match == default_private_vlan_mapping
match
end
|
#private_vlan_mapping=(vlans) ⇒ Object
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
|
# File 'lib/cisco_node_utils/interface.rb', line 1411
def private_vlan_mapping=(vlans)
fail TypeError unless vlans.is_a?(Array) || vlans.empty?
Feature.private_vlan_enable
feature_vlan_set(true)
if vlans == default_private_vlan_mapping
config_set('interface', 'private_vlan_mapping',
name: @name, state: 'no', vlans: '')
else
is_list = private_vlan_mapping
new_is_list = prepare_array(is_list)
new_vlans = prepare_array(vlans)
configure_private_vlan_host_property(:vlan_mapping, new_vlans,
new_is_list, '')
end
end
|
#select_ipv4_attribute(attribute) ⇒ Object
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
|
# File 'lib/cisco_node_utils/interface.rb', line 317
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
|
#set_range_based_params(list, param_name) ⇒ Object
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
|
# File 'lib/cisco_node_utils/interface.rb', line 1682
def set_range_based_params(list, param_name)
list.each do |range, property_value|
if property_value == 'default'
config_set('interface', param_name,
name: @name, state: 'no',
range: range, val: '')
else
config_set('interface', param_name,
name: @name, state: '',
range: range, val: property_value)
end
end
end
|
#shutdown ⇒ Object
581
582
583
|
# File 'lib/cisco_node_utils/interface.rb', line 581
def shutdown
config_get('interface', 'shutdown', name: @name)
end
|
#shutdown=(state) ⇒ Object
585
586
587
588
|
# File 'lib/cisco_node_utils/interface.rb', line 585
def shutdown=(state)
no_cmd = (state ? '' : 'no')
config_set('interface', 'shutdown', name: @name, state: no_cmd)
end
|
#speed ⇒ Object
532
533
534
|
# File 'lib/cisco_node_utils/interface.rb', line 532
def speed
config_get('interface', 'speed', name: @name)
end
|
#speed=(val) ⇒ Object
536
537
538
|
# File 'lib/cisco_node_utils/interface.rb', line 536
def speed=(val)
config_set('interface', 'speed', name: @name, speed: val)
end
|
#stp_bpdufilter ⇒ Object
623
624
625
|
# File 'lib/cisco_node_utils/interface.rb', line 623
def stp_bpdufilter
config_get('interface', 'stp_bpdufilter', name: @name)
end
|
#stp_bpdufilter=(val) ⇒ Object
627
628
629
630
631
632
633
634
635
636
637
|
# File 'lib/cisco_node_utils/interface.rb', line 627
def stp_bpdufilter=(val)
check_switchport([:access, :trunk])
if val
state = ''
else
state = 'no'
val = ''
end
config_set('interface',
'stp_bpdufilter', name: @name, state: state, filter: val)
end
|
#stp_bpduguard ⇒ Object
643
644
645
|
# File 'lib/cisco_node_utils/interface.rb', line 643
def stp_bpduguard
config_get('interface', 'stp_bpduguard', name: @name)
end
|
#stp_bpduguard=(val) ⇒ Object
647
648
649
650
651
652
653
654
655
656
|
# File 'lib/cisco_node_utils/interface.rb', line 647
def stp_bpduguard=(val)
if val
state = ''
else
state = 'no'
val = ''
end
config_set('interface',
'stp_bpduguard', name: @name, state: state, guard: val)
end
|
#stp_cost ⇒ Object
662
663
664
665
|
# File 'lib/cisco_node_utils/interface.rb', line 662
def stp_cost
cost = config_get('interface', 'stp_cost', name: @name)
cost == 'auto' ? cost : cost.to_i
end
|
#stp_cost=(val) ⇒ Object
667
668
669
670
|
# File 'lib/cisco_node_utils/interface.rb', line 667
def stp_cost=(val)
check_switchport([:access, :trunk])
config_set('interface', 'stp_cost', name: @name, cost: val)
end
|
#stp_guard ⇒ Object
676
677
678
|
# File 'lib/cisco_node_utils/interface.rb', line 676
def stp_guard
config_get('interface', 'stp_guard', name: @name)
end
|
#stp_guard=(val) ⇒ Object
680
681
682
683
684
685
686
687
688
689
690
|
# File 'lib/cisco_node_utils/interface.rb', line 680
def stp_guard=(val)
check_switchport([:access, :trunk])
if val
state = ''
else
state = 'no'
val = ''
end
config_set('interface', 'stp_guard', name: @name, state: state,
guard: val)
end
|
#stp_link_type ⇒ Object
696
697
698
|
# File 'lib/cisco_node_utils/interface.rb', line 696
def stp_link_type
config_get('interface', 'stp_link_type', name: @name)
end
|
#stp_link_type=(val) ⇒ Object
700
701
702
703
|
# File 'lib/cisco_node_utils/interface.rb', line 700
def stp_link_type=(val)
check_switchport([:access, :trunk])
config_set('interface', 'stp_link_type', name: @name, type: val)
end
|
#stp_mst_cost ⇒ Object
Getter: Builds an array of mst cost commands currently on the device.
cli: spanning-tree mst 0,2-4,6,8-12 cost 1000
spanning-tree mst 4000-4020 cost 2568
array: [[‘0,2-4,6,8-12’, ‘1000’], [‘4000-4020’, ‘2568’]]
728
729
730
|
# File 'lib/cisco_node_utils/interface.rb', line 728
def stp_mst_cost
config_get('interface', 'stp_mst_cost', name: @name)
end
|
#stp_mst_cost=(list) ⇒ Object
732
733
734
735
736
737
738
|
# File 'lib/cisco_node_utils/interface.rb', line 732
def stp_mst_cost=(list)
check_switchport([:access, :trunk])
config_set('interface', 'stp_mst_cost',
name: @name, state: 'no', range: @smr,
val: '') if list.empty?
set_range_based_params(list, 'stp_mst_cost')
end
|
#stp_mst_port_priority ⇒ Object
Getter: Builds an array of mst port-priority commands currently on the device.
cli: spanning-tree mst 0,2-4,6,8-12 port-priority 64
spanning-tree mst 4000-4020 port-priority 160
array: [[‘0,2-4,6,8-12’, ‘64’], [‘4000-4020’, ‘160’]]
750
751
752
|
# File 'lib/cisco_node_utils/interface.rb', line 750
def stp_mst_port_priority
config_get('interface', 'stp_mst_port_priority', name: @name)
end
|
#stp_mst_port_priority=(list) ⇒ Object
754
755
756
757
758
759
760
|
# File 'lib/cisco_node_utils/interface.rb', line 754
def stp_mst_port_priority=(list)
check_switchport([:access, :trunk])
config_set('interface', 'stp_mst_port_priority',
name: @name, state: 'no', range: @smr,
val: '') if list.empty?
set_range_based_params(list, 'stp_mst_port_priority')
end
|
#stp_port_priority ⇒ Object
709
710
711
|
# File 'lib/cisco_node_utils/interface.rb', line 709
def stp_port_priority
config_get('interface', 'stp_port_priority', name: @name)
end
|
#stp_port_priority=(val) ⇒ Object
713
714
715
716
|
# File 'lib/cisco_node_utils/interface.rb', line 713
def stp_port_priority=(val)
check_switchport([:access, :trunk])
config_set('interface', 'stp_port_priority', name: @name, pp: val)
end
|
#stp_port_type ⇒ Object
766
767
768
|
# File 'lib/cisco_node_utils/interface.rb', line 766
def stp_port_type
config_get('interface', 'stp_port_type', name: @name)
end
|
#stp_port_type=(val) ⇒ Object
770
771
772
773
774
775
776
777
778
779
|
# File 'lib/cisco_node_utils/interface.rb', line 770
def stp_port_type=(val)
if val
state = ''
else
state = 'no'
val = ''
end
config_set('interface', 'stp_port_type', name: @name,
state: state, type: val)
end
|
#stp_vlan_cost ⇒ Object
Getter: Builds an array of vlan cost commands currently on the device.
cli: spanning-tree vlan 1-4,6,8-12 cost 1000
spanning-tree vlan 3000-3960 cost 2568
array: [[‘1-4,6,8-12’, ‘1000’], [‘3000-3960’, ‘2568’]]
791
792
793
|
# File 'lib/cisco_node_utils/interface.rb', line 791
def stp_vlan_cost
config_get('interface', 'stp_vlan_cost', name: @name)
end
|
#stp_vlan_cost=(list) ⇒ Object
795
796
797
798
799
800
801
|
# File 'lib/cisco_node_utils/interface.rb', line 795
def stp_vlan_cost=(list)
check_switchport([:access, :trunk])
config_set('interface', 'stp_vlan_cost',
name: @name, state: 'no',
range: @svr, val: '') if list.empty?
set_range_based_params(list, 'stp_vlan_cost')
end
|
#stp_vlan_port_priority ⇒ Object
Getter: Builds an array of vlan port-priority commands currently on the device.
cli: spanning-tree vlan 1-4,6,8-12 port-priority 64
spanning-tree vlan 3000-3960 port-priority 160
array: [[‘1-4,6,8-12’, ‘64’], [‘3000-3960’, ‘160’]]
813
814
815
|
# File 'lib/cisco_node_utils/interface.rb', line 813
def stp_vlan_port_priority
config_get('interface', 'stp_vlan_port_priority', name: @name)
end
|
#stp_vlan_port_priority=(list) ⇒ Object
817
818
819
820
821
822
823
|
# File 'lib/cisco_node_utils/interface.rb', line 817
def stp_vlan_port_priority=(list)
check_switchport([:access, :trunk])
config_set('interface', 'stp_vlan_port_priority',
name: @name, state: 'no',
range: @svr, val: '') if list.empty?
set_range_based_params(list, 'stp_vlan_port_priority')
end
|
#svi_autostate ⇒ Object
svi_autostate is exclusive to svi interfaces
1551
1552
1553
1554
|
# File 'lib/cisco_node_utils/interface.rb', line 1551
def svi_autostate
return nil unless @name[/^vlan/i]
config_get('interface', 'svi_autostate', name: @name)
end
|
#svi_autostate=(val) ⇒ Object
1556
1557
1558
1559
1560
1561
|
# File 'lib/cisco_node_utils/interface.rb', line 1556
def svi_autostate=(val)
check_switchport(:disabled)
svi_cmd_allowed?('autostate')
config_set('interface', 'svi_autostate',
name: @name, state: val ? '' : 'no')
end
|
#svi_cmd_allowed?(cmd) ⇒ Boolean
1545
1546
1547
1548
|
# File 'lib/cisco_node_utils/interface.rb', line 1545
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
1577
1578
1579
1580
|
# File 'lib/cisco_node_utils/interface.rb', line 1577
def svi_management
return nil unless @name[/^vlan/i]
config_get('interface', 'svi_management', name: @name)
end
|
#svi_management=(val) ⇒ Object
1582
1583
1584
1585
1586
1587
|
# File 'lib/cisco_node_utils/interface.rb', line 1582
def svi_management=(val)
check_switchport(:disabled)
svi_cmd_allowed?('management')
config_set('interface', 'svi_management',
name: @name, state: val ? '' : 'no')
end
|
#switchport ⇒ Object
829
830
831
832
|
# File 'lib/cisco_node_utils/interface.rb', line 829
def switchport
config_get('interface', 'switchport', name: @name)
end
|
#switchport_autostate_exclude ⇒ Object
switchport_autostate_exclude is exclusive to switchport interfaces
839
840
841
842
|
# File 'lib/cisco_node_utils/interface.rb', line 839
def switchport_autostate_exclude
config_get('interface',
'switchport_autostate_exclude', name: @name)
end
|
#switchport_autostate_exclude=(val) ⇒ Object
844
845
846
847
848
849
850
851
852
853
|
# File 'lib/cisco_node_utils/interface.rb', line 844
def switchport_autostate_exclude=(val)
if platform == :nexus
fail('switchport mode must be configured before ' \
'switchport autostate') unless switchport
feature_vlan_set(true)
end
config_set('interface', 'switchport_autostate_exclude',
name: @name, state: val ? '' : 'no')
end
|
#switchport_enable(val = true) ⇒ Object
834
835
836
|
# File 'lib/cisco_node_utils/interface.rb', line 834
def switchport_enable(val=true)
config_set('interface', 'switchport', name: @name, state: val ? '' : 'no')
end
|
#switchport_enable_and_mode(mode_set) ⇒ Object
884
885
886
887
888
889
890
891
892
893
894
|
# File 'lib/cisco_node_utils/interface.rb', line 884
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
Feature.fex_enable
end
config_set('interface', switchport_mode_lookup_string,
name: @name, state: '', mode: IF_SWITCHPORT_MODE[mode_set])
end
|
#switchport_enable_and_mode_private_vlan_host(mode_set) ⇒ Object
986
987
988
989
990
991
992
993
994
995
|
# File 'lib/cisco_node_utils/interface.rb', line 986
def switchport_enable_and_mode_private_vlan_host(mode_set)
switchport_enable unless switchport
if mode_set[/(host|promiscuous)/]
config_set('interface', 'switchport_mode_private_vlan_host',
name: @name, state: '', mode: IF_SWITCHPORT_MODE[mode_set])
else
config_set('interface', 'switchport_mode_private_vlan_host',
name: @name, state: 'no', mode: IF_SWITCHPORT_MODE[mode_set])
end
end
|
#switchport_mode ⇒ Object
870
871
872
873
874
875
876
877
878
879
880
881
882
|
# File 'lib/cisco_node_utils/interface.rb', line 870
def switchport_mode
return nil if platform == :ios_xr
mode = config_get('interface', switchport_mode_lookup_string, name: @name)
return mode.nil? ? :disabled : IF_SWITCHPORT_MODE.key(mode)
rescue IndexError
return :disabled
end
|
#switchport_mode=(mode_set) ⇒ Object
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
|
# File 'lib/cisco_node_utils/interface.rb', line 896
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: @name, state: 'no')
end
when :default
if :disabled == default_switchport_mode
config_set('interface', switchport_mode_lookup_string,
name: @name, state: 'no', mode: '')
else
switchport_enable_and_mode(mode_set)
end
else
switchport_enable_and_mode(mode_set)
end end
|
#switchport_mode_lookup_string ⇒ Object
859
860
861
862
863
864
865
866
867
868
|
# File 'lib/cisco_node_utils/interface.rb', line 859
def switchport_mode_lookup_string
case @name
when ETHERNET
return 'switchport_mode_ethernet'
when PORTCHANNEL
return 'switchport_mode_port_channel'
else
return 'switchport_mode_other_interfaces'
end
end
|
#switchport_mode_private_vlan_host ⇒ Object
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
|
# File 'lib/cisco_node_utils/interface.rb', line 997
def switchport_mode_private_vlan_host
mode = config_get('interface',
'switchport_mode_private_vlan_host',
name: @name)
unless mode == default_switchport_mode_private_vlan_host
mode = IF_SWITCHPORT_MODE.key(mode)
end
mode
rescue IndexError
return default_switchport_mode_private_vlan_host
end
|
#switchport_mode_private_vlan_host=(mode_set) ⇒ Object
1013
1014
1015
1016
1017
|
# File 'lib/cisco_node_utils/interface.rb', line 1013
def switchport_mode_private_vlan_host=(mode_set)
fail ArgumentError unless IF_SWITCHPORT_MODE.keys.include? mode_set
Feature.private_vlan_enable
switchport_enable_and_mode_private_vlan_host(mode_set)
end
|
#switchport_mode_private_vlan_host_association ⇒ Object
1024
1025
1026
1027
1028
1029
1030
1031
1032
|
# File 'lib/cisco_node_utils/interface.rb', line 1024
def switchport_mode_private_vlan_host_association
result = config_get('interface',
'switchport_mode_private_vlan_host_association',
name: @name)
unless result == default_switchport_mode_private_vlan_host_association
result = result[0].split(' ')
end
result
end
|
#switchport_mode_private_vlan_host_association=(vlans) ⇒ Object
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
|
# File 'lib/cisco_node_utils/interface.rb', line 1034
def switchport_mode_private_vlan_host_association=(vlans)
fail TypeError unless vlans.is_a?(Array) || vlans.empty?
switchport_enable unless switchport
Feature.private_vlan_enable
if vlans == default_switchport_mode_private_vlan_host_association
result = config_set('interface',
'switchport_mode_private_vlan_host_association',
name: @name, state: 'no', vlan_pr: '', vlan_sec: '')
else
result = config_set('interface',
'switchport_mode_private_vlan_host_association',
name: @name, state: '',
vlan_pr: vlans[0], vlan_sec: vlans[1])
end
cli_error_check(result)
end
|
#switchport_mode_private_vlan_host_promisc ⇒ Object
1203
1204
1205
1206
1207
1208
1209
1210
1211
|
# File 'lib/cisco_node_utils/interface.rb', line 1203
def switchport_mode_private_vlan_host_promisc
result = config_get('interface',
'switchport_mode_private_vlan_host_promiscous',
name: @name)
unless result == default_switchport_mode_private_vlan_host_promisc
result = result[0].split(' ')
end
result
end
|
#switchport_mode_private_vlan_host_promisc=(vlans) ⇒ Object
1213
1214
1215
1216
1217
1218
1219
1220
|
# File 'lib/cisco_node_utils/interface.rb', line 1213
def switchport_mode_private_vlan_host_promisc=(vlans)
fail TypeError unless vlans.is_a?(Array)
fail TypeError unless vlans.empty? || vlans.length == 2
switchport_enable unless switchport
Feature.private_vlan_enable
is_list = switchport_mode_private_vlan_host_promisc
interf_vlan_list_delta(:host_promisc, is_list, vlans)
end
|
#switchport_mode_private_vlan_trunk_promiscuous ⇒ Object
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
|
# File 'lib/cisco_node_utils/interface.rb', line 1227
def switchport_mode_private_vlan_trunk_promiscuous
config_get('interface',
'switchport_mode_private_vlan_trunk_promiscuous',
name: @name)
rescue IndexError
return default_switchport_mode_private_vlan_trunk_promiscuous
end
|
#switchport_mode_private_vlan_trunk_promiscuous=(state) ⇒ Object
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
|
# File 'lib/cisco_node_utils/interface.rb', line 1239
def switchport_mode_private_vlan_trunk_promiscuous=(state)
Feature.private_vlan_enable
switchport_enable unless switchport
if state == default_switchport_mode_private_vlan_trunk_promiscuous
config_set('interface',
'switchport_mode_private_vlan_trunk_promiscuous',
name: @name, state: 'no')
else
config_set('interface',
'switchport_mode_private_vlan_trunk_promiscuous',
name: @name, state: '')
end
end
|
#switchport_mode_private_vlan_trunk_secondary ⇒ Object
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
|
# File 'lib/cisco_node_utils/interface.rb', line 1258
def switchport_mode_private_vlan_trunk_secondary
config_get('interface',
'switchport_mode_private_vlan_trunk_secondary',
name: @name)
rescue IndexError
return default_switchport_mode_private_vlan_trunk_secondary
end
|
#switchport_mode_private_vlan_trunk_secondary=(state) ⇒ Object
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
|
# File 'lib/cisco_node_utils/interface.rb', line 1270
def switchport_mode_private_vlan_trunk_secondary=(state)
Feature.private_vlan_enable
switchport_enable unless switchport
if state == default_switchport_mode_private_vlan_trunk_secondary
config_set('interface', 'switchport_mode_private_vlan_trunk_secondary',
name: @name, state: 'no')
else
config_set('interface', 'switchport_mode_private_vlan_trunk_secondary',
name: @name, state: '')
end
end
|
#switchport_private_vlan_association_trunk ⇒ Object
1351
1352
1353
1354
1355
|
# File 'lib/cisco_node_utils/interface.rb', line 1351
def switchport_private_vlan_association_trunk
config_get('interface',
'switchport_private_vlan_association_trunk',
name: @name)
end
|
#switchport_private_vlan_association_trunk=(vlans) ⇒ Object
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
|
# File 'lib/cisco_node_utils/interface.rb', line 1357
def switchport_private_vlan_association_trunk=(vlans)
fail TypeError unless vlans.is_a?(Array) || vlans.empty?
Feature.private_vlan_enable
switchport_enable unless switchport
if vlans == default_switchport_private_vlan_association_trunk
config_set('interface', 'switchport_private_vlan_association_trunk',
name: @name, state: 'no',
vlan_pr: '', vlan: '')
else
is_list = switchport_private_vlan_association_trunk
configure_private_vlan_trunk_property(:trunk_assoc, vlans,
is_list, vlans[0])
end
end
|
#switchport_private_vlan_mapping_trunk ⇒ Object
1377
1378
1379
1380
1381
|
# File 'lib/cisco_node_utils/interface.rb', line 1377
def switchport_private_vlan_mapping_trunk
config_get('interface',
'switchport_private_vlan_mapping_trunk',
name: @name)
end
|
#switchport_private_vlan_mapping_trunk=(vlans) ⇒ Object
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
|
# File 'lib/cisco_node_utils/interface.rb', line 1383
def switchport_private_vlan_mapping_trunk=(vlans)
fail TypeError unless vlans.is_a?(Array) || vlans.empty?
Feature.private_vlan_enable
switchport_enable unless switchport
if vlans == default_switchport_private_vlan_mapping_trunk
config_set('interface', 'switchport_private_vlan_mapping_trunk',
name: @name, state: 'no',
vlan_pr: '', vlans: '')
else
is_list = switchport_private_vlan_mapping_trunk
configure_private_vlan_trunk_property(:mapping_trunk, vlans,
is_list, vlans[0])
end
end
|
#switchport_private_vlan_trunk_allowed_vlan ⇒ Object
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
|
# File 'lib/cisco_node_utils/interface.rb', line 1287
def switchport_private_vlan_trunk_allowed_vlan
result = config_get('interface',
'switchport_private_vlan_trunk_allowed_vlan',
name: @name)
unless result == default_switchport_private_vlan_trunk_allowed_vlan
if result[0].eql? 'none'
result = default_switchport_private_vlan_trunk_allowed_vlan
else
result = result[0].split(',')
end
end
result
end
|
#switchport_private_vlan_trunk_allowed_vlan=(vlans) ⇒ Object
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
|
# File 'lib/cisco_node_utils/interface.rb', line 1302
def switchport_private_vlan_trunk_allowed_vlan=(vlans)
fail TypeError unless vlans.is_a?(Array)
Feature.private_vlan_enable
switchport_enable unless switchport
if vlans == default_switchport_private_vlan_trunk_allowed_vlan
vlans = prepare_array(switchport_private_vlan_trunk_allowed_vlan)
return if vlans == default_switchport_private_vlan_trunk_allowed_vlan
configure_private_vlan_host_property(:allow_vlan, [],
vlans, '')
else
vlans = prepare_array(vlans)
is_list = prepare_array(switchport_private_vlan_trunk_allowed_vlan)
configure_private_vlan_host_property(:allow_vlan, vlans,
is_list, '')
end
end
|
#switchport_private_vlan_trunk_native_vlan ⇒ Object
1325
1326
1327
1328
1329
|
# File 'lib/cisco_node_utils/interface.rb', line 1325
def switchport_private_vlan_trunk_native_vlan
config_get('interface',
'switchport_private_vlan_trunk_native_vlan',
name: @name)
end
|
#switchport_private_vlan_trunk_native_vlan=(vlan) ⇒ Object
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
|
# File 'lib/cisco_node_utils/interface.rb', line 1331
def switchport_private_vlan_trunk_native_vlan=(vlan)
Feature.private_vlan_enable
switchport_enable unless switchport
if vlan == default_switchport_private_vlan_trunk_native_vlan
config_set('interface',
'switchport_private_vlan_trunk_native_vlan',
name: @name, state: 'no', vlan: '')
else
config_set('interface',
'switchport_private_vlan_trunk_native_vlan',
name: @name, state: '', vlan: vlan)
end
end
|
#switchport_status?(status) ⇒ Boolean
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
|
# File 'lib/cisco_node_utils/interface.rb', line 1602
def switchport_status?(status)
case status
when :disabled
return true if switchport_mode == status || switchport_mode.nil?
when :access, :trunk
return switchport_mode == status
when Array
return status.include?(switchport_mode)
else
return false
end
end
|
#switchport_trunk_allowed_vlan ⇒ Object
929
930
931
|
# File 'lib/cisco_node_utils/interface.rb', line 929
def switchport_trunk_allowed_vlan
config_get('interface', 'switchport_trunk_allowed_vlan', name: @name)
end
|
#switchport_trunk_allowed_vlan=(val) ⇒ Object
933
934
935
936
937
938
939
940
941
|
# File 'lib/cisco_node_utils/interface.rb', line 933
def switchport_trunk_allowed_vlan=(val)
if val.nil?
config_set('interface', 'switchport_trunk_allowed_vlan',
name: @name, state: 'no', vlan: '')
else
config_set('interface', 'switchport_trunk_allowed_vlan',
name: @name, state: '', vlan: val)
end
end
|
#switchport_trunk_native_vlan ⇒ Object
947
948
949
|
# File 'lib/cisco_node_utils/interface.rb', line 947
def switchport_trunk_native_vlan
config_get('interface', 'switchport_trunk_native_vlan', name: @name)
end
|
#switchport_trunk_native_vlan=(val) ⇒ Object
951
952
953
954
955
956
957
958
959
|
# File 'lib/cisco_node_utils/interface.rb', line 951
def switchport_trunk_native_vlan=(val)
if val.nil?
config_set('interface', 'switchport_trunk_native_vlan',
name: @name, state: 'no', vlan: '')
else
config_set('interface', 'switchport_trunk_native_vlan',
name: @name, state: '', vlan: val)
end
end
|
#switchport_vtp ⇒ Object
1533
1534
1535
1536
|
# File 'lib/cisco_node_utils/interface.rb', line 1533
def switchport_vtp
return nil unless switchport_vtp_mode_capable?
config_get('interface', 'vtp', name: @name)
end
|
#switchport_vtp=(vtp_set) ⇒ Object
1538
1539
1540
1541
1542
1543
|
# File 'lib/cisco_node_utils/interface.rb', line 1538
def switchport_vtp=(vtp_set)
return false unless switchport_vtp_mode_capable?
no_cmd = (vtp_set) ? '' : 'no'
config_set('interface', 'vtp', name: @name, state: no_cmd)
end
|
#switchport_vtp_feature? ⇒ Boolean
1598
1599
1600
|
# File 'lib/cisco_node_utils/interface.rb', line 1598
def switchport_vtp_feature?
config_get('vtp', 'feature')
end
|
#switchport_vtp_mode_capable? ⇒ Boolean
1529
1530
1531
|
# File 'lib/cisco_node_utils/interface.rb', line 1529
def switchport_vtp_mode_capable?
!switchport_mode.to_s.match(/(access|trunk)/).nil?
end
|
#system_default_svi_autostate ⇒ Object
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
|
# File 'lib/cisco_node_utils/interface.rb', line 1514
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
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
|
# File 'lib/cisco_node_utils/interface.rb', line 1496
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
1509
1510
1511
1512
|
# File 'lib/cisco_node_utils/interface.rb', line 1509
def system_default_switchport_shutdown
config_get('interface', 'system_default_switchport_shutdown')
end
|
#to_s ⇒ Object
68
69
70
|
# File 'lib/cisco_node_utils/interface.rb', line 68
def to_s
"interface #{name}"
end
|
#vlan_mapping ⇒ Object
1451
1452
1453
1454
1455
|
# File 'lib/cisco_node_utils/interface.rb', line 1451
def vlan_mapping
match = config_get('interface', 'vlan_mapping', name: @name)
match.each(&:compact!) unless match.nil?
match
end
|
#vlan_mapping=(should_list) ⇒ Object
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
|
# File 'lib/cisco_node_utils/interface.rb', line 1457
def vlan_mapping=(should_list)
Feature.vni_enable
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|
Cisco::Logger.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: @name,
state: state, original: original, translated: translated)
end
end
end
|
#vlan_mapping_enable ⇒ Object
1483
1484
1485
|
# File 'lib/cisco_node_utils/interface.rb', line 1483
def vlan_mapping_enable
config_get('interface', 'vlan_mapping_enable', name: @name)
end
|
#vlan_mapping_enable=(state) ⇒ Object
1487
1488
1489
1490
|
# File 'lib/cisco_node_utils/interface.rb', line 1487
def vlan_mapping_enable=(state)
config_set('interface', 'vlan_mapping_enable',
name: @name, state: state ? '' : 'no')
end
|
#vpc_id ⇒ Object
1621
1622
1623
|
# File 'lib/cisco_node_utils/interface.rb', line 1621
def vpc_id
config_get('interface', 'vpc_id', name: @name)
end
|
#vpc_id=(num) ⇒ Object
1625
1626
1627
1628
1629
1630
1631
1632
1633
|
# File 'lib/cisco_node_utils/interface.rb', line 1625
def vpc_id=(num)
if num
config_set('interface', 'vpc_id', name: @name, state: '', id: num)
else
num = vpc_id
config_set('interface', 'vpc_id', name: @name, state: 'no', id: num)
end
end
|
#vpc_peer_link ⇒ Object
1639
1640
1641
|
# File 'lib/cisco_node_utils/interface.rb', line 1639
def vpc_peer_link
config_get('interface', 'vpc_peer_link', name: @name)
end
|
#vpc_peer_link=(state) ⇒ Object
1643
1644
1645
1646
|
# File 'lib/cisco_node_utils/interface.rb', line 1643
def vpc_peer_link=(state)
no_cmd = (state ? '' : 'no')
config_set('interface', 'vpc_peer_link', name: @name, state: no_cmd)
end
|
#vrf ⇒ Object
1652
1653
1654
|
# File 'lib/cisco_node_utils/interface.rb', line 1652
def vrf
config_get('interface', 'vrf', name: @name)
end
|
#vrf=(v) ⇒ Object
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
|
# File 'lib/cisco_node_utils/interface.rb', line 1656
def vrf=(v)
fail TypeError unless v.is_a?(String)
return if v == vrf
addr_1 = ipv4_address
mask_1 = ipv4_netmask_length
addr_2 = ipv4_address_secondary
mask_2 = ipv4_netmask_length_secondary
unless platform == :nexus
ipv4_addr_mask_set(nil, nil, false) unless addr_1.nil?
ipv4_addr_mask_set(nil, nil, true) unless addr_2.nil?
end
if v.empty?
config_set('interface', 'vrf', name: @name, state: 'no', vrf: '')
else
config_set('interface', 'vrf', name: @name, state: '', vrf: v)
end
ipv4_addr_mask_set(addr_1, mask_1, false) unless addr_1.nil?
ipv4_addr_mask_set(addr_2, mask_2, true) unless addr_2.nil?
end
|