Class: Cisco::Interface

Inherits:
InterfaceDeprecated show all
Defined in:
lib/cisco_node_utils/interface.rb

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)

Constants inherited from InterfaceDeprecated

Cisco::InterfaceDeprecated::PVLAN_PROPERTY

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from InterfaceDeprecated

#configure_private_vlan_host_property, #configure_private_vlan_trunk_property, #default_private_vlan_mapping, #default_switchport_mode_private_vlan_host, #default_switchport_mode_private_vlan_host_association, #default_switchport_mode_private_vlan_host_promisc, #default_switchport_mode_private_vlan_trunk_promiscuous, #default_switchport_mode_private_vlan_trunk_secondary, #default_switchport_private_vlan_association_trunk, #default_switchport_private_vlan_mapping_trunk, #default_switchport_private_vlan_trunk_allowed_vlan, #default_switchport_private_vlan_trunk_native_vlan, #deprecation_warning, #interf_vlan_list_delta, #prepare_array, #private_vlan_mapping, #private_vlan_mapping=, #switchport_enable_and_mode_private_vlan_host, #switchport_mode_private_vlan_host, #switchport_mode_private_vlan_host=, #switchport_mode_private_vlan_host_association, #switchport_mode_private_vlan_host_association=, #switchport_mode_private_vlan_host_promisc, #switchport_mode_private_vlan_host_promisc=, #switchport_mode_private_vlan_trunk_promiscuous, #switchport_mode_private_vlan_trunk_promiscuous=, #switchport_mode_private_vlan_trunk_secondary, #switchport_mode_private_vlan_trunk_secondary=, #switchport_private_vlan_association_trunk, #switchport_private_vlan_association_trunk=, #switchport_private_vlan_mapping_trunk, #switchport_private_vlan_mapping_trunk=, #switchport_private_vlan_trunk_allowed_vlan, #switchport_private_vlan_trunk_allowed_vlan=, #switchport_private_vlan_trunk_native_vlan, #switchport_private_vlan_trunk_native_vlan=

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.



56
57
58
59
60
61
62
63
64
# File 'lib/cisco_node_utils/interface.rb', line 56

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

#nameObject (readonly)

Returns the value of attribute name.



54
55
56
# File 'lib/cisco_node_utils/interface.rb', line 54

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”



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/cisco_node_utils/interface.rb', line 114

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!(/ \(.*\)/, '') # Remove any parenthetical text from key
      v.strip!
      v.gsub!(%r{half/full}, 'half,full') if k == 'Duplex'
      hash[k] = v
    end
  end
  hash
end

.filter(filter, id) ⇒ Object

General-purpose filter for Interface.interfaces(). filter: This may be overloaded in the future to allow a hash of filters.

id: The interface name

Return: true if the interface should be filtered out, false to keep it.



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/cisco_node_utils/interface.rb', line 87

def self.filter(filter, id)
  case filter
  when :pvlan_any
    return false if config_get('interface', 'pvlan_any', name: id)

  else
    # Just a basic pattern filter (:ethernet, :loopback, etc)
    return false if id.match(filter.to_s)
  end
  true
end

.interfaces(opt = nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/cisco_node_utils/interface.rb', line 70

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_vlanObject

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.



165
166
167
# File 'lib/cisco_node_utils/interface.rb', line 165

def access_vlan
  config_get('interface', 'access_vlan', name: @name)
end

#access_vlan=(vlan) ⇒ Object



169
170
171
# File 'lib/cisco_node_utils/interface.rb', line 169

def access_vlan=(vlan)
  config_set('interface', 'access_vlan', name: @name, vlan: vlan)
end

#bfd_echoObject



177
178
179
180
181
# File 'lib/cisco_node_utils/interface.rb', line 177

def bfd_echo
  return nil unless Feature.bfd_enabled?
  return nil if @name[/loop/i]
  config_get('interface', 'bfd_echo', name: @name)
end

#bfd_echo=(val) ⇒ Object



183
184
185
186
187
188
189
190
191
# File 'lib/cisco_node_utils/interface.rb', line 183

def bfd_echo=(val)
  fail ArgumentError, 'Interface cannot be loopback' if
    @name[/loop/i]
  return if val == bfd_echo
  state = (val ? '' : 'no')
  Feature.bfd_enable
  config_set('interface', 'bfd_echo',
             name: @name, state: state)
end

#check_switchport(status) ⇒ Object



1706
1707
1708
1709
1710
# File 'lib/cisco_node_utils/interface.rb', line 1706

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




1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
# File 'lib/cisco_node_utils/interface.rb', line 1182

def cli_error_check(result)
  # Check for messages that can be safely ignored.
  # The NXOS interface private-vlan cli does not raise an exception
  # in some conditions and instead just displays a STDOUT error message
  # thus NXAPI does not detect the failure.
  # We must catch it by inspecting the "body" hash entry returned by NXAPI.
  # This vlan cli behavior is unlikely to change.

  errors = /(ERROR:|VLAN:|Eth)/
  return unless
    result[1].is_a?(Hash) && errors.match(result[1]['body'].to_s)
  # Split errors into a list, but keep the delimiter as part of the message.
  error_list =
    (result[1]['body'].split(errors) - ['']).each_slice(2).map(&:join)
  error_list.each do |_msg|
    fail result[1]['body']
  end
end

#createObject



132
133
134
135
136
137
138
139
140
141
# File 'lib/cisco_node_utils/interface.rb', line 132

def create
  feature_vlan_set(true) if @name[/(vlan|bdi)/i]
  config_set('interface', 'create', name: @name)
rescue Cisco::CliError
  # Some XR platforms do not support channel-group configuration
  # on some OS versions. Since this is an OS version difference and not
  # a platform difference, we can't handle this in the YAML.
  raise unless PORTCHANNEL =~ @name && platform == :ios_xr
  raise Cisco::UnsupportedError.new('interface', @name, 'create')
end

#default_access_vlanObject



173
174
175
# File 'lib/cisco_node_utils/interface.rb', line 173

def default_access_vlan
  config_get_default('interface', 'access_vlan')
end

#default_bfd_echoObject



193
194
195
196
197
# File 'lib/cisco_node_utils/interface.rb', line 193

def default_bfd_echo
  return nil unless Feature.bfd_enabled?
  return nil if @name[/loop/i]
  config_get_default('interface', 'bfd_echo')
end

#default_descriptionObject



214
215
216
# File 'lib/cisco_node_utils/interface.rb', line 214

def default_description
  config_get_default('interface', 'description')
end

#default_duplexObject



723
724
725
# File 'lib/cisco_node_utils/interface.rb', line 723

def default_duplex
  config_get_default('interface', 'duplex')
end

#default_encapsulation_dot1qObject



232
233
234
# File 'lib/cisco_node_utils/interface.rb', line 232

def default_encapsulation_dot1q
  config_get_default('interface', 'encapsulation_dot1q')
end

#default_fabric_forwarding_anycast_gatewayObject



265
266
267
# File 'lib/cisco_node_utils/interface.rb', line 265

def default_fabric_forwarding_anycast_gateway
  config_get_default('interface', 'fabric_forwarding_anycast_gateway')
end

#default_ipv4_acl_inObject



286
287
288
# File 'lib/cisco_node_utils/interface.rb', line 286

def default_ipv4_acl_in
  config_get_default('interface', 'ipv4_acl_in')
end

#default_ipv4_acl_outObject



307
308
309
# File 'lib/cisco_node_utils/interface.rb', line 307

def default_ipv4_acl_out
  config_get_default('interface', 'ipv4_acl_out')
end

#default_ipv4_addressObject



382
383
384
# File 'lib/cisco_node_utils/interface.rb', line 382

def default_ipv4_address
  config_get_default('interface', 'ipv4_address')
end

#default_ipv4_address_secondaryObject



386
387
388
# File 'lib/cisco_node_utils/interface.rb', line 386

def default_ipv4_address_secondary
  default_ipv4_address
end

#default_ipv4_arp_timeoutObject



419
420
421
# File 'lib/cisco_node_utils/interface.rb', line 419

def default_ipv4_arp_timeout
  config_get_default('interface', ipv4_arp_timeout_lookup_string)
end

#default_ipv4_dhcp_relay_addrObject



443
444
445
# File 'lib/cisco_node_utils/interface.rb', line 443

def default_ipv4_dhcp_relay_addr
  config_get_default('interface', 'ipv4_dhcp_relay_addr')
end

#default_ipv4_dhcp_relay_info_trustObject



457
458
459
# File 'lib/cisco_node_utils/interface.rb', line 457

def default_ipv4_dhcp_relay_info_trust
  config_get_default('interface', 'ipv4_dhcp_relay_info_trust')
end

#default_ipv4_dhcp_relay_src_addr_hsrpObject



471
472
473
# File 'lib/cisco_node_utils/interface.rb', line 471

def default_ipv4_dhcp_relay_src_addr_hsrp
  config_get_default('interface', 'ipv4_dhcp_relay_src_addr_hsrp')
end

#default_ipv4_dhcp_relay_src_intfObject



490
491
492
# File 'lib/cisco_node_utils/interface.rb', line 490

def default_ipv4_dhcp_relay_src_intf
  config_get_default('interface', 'ipv4_dhcp_relay_src_intf')
end

#default_ipv4_dhcp_relay_subnet_broadcastObject



504
505
506
# File 'lib/cisco_node_utils/interface.rb', line 504

def default_ipv4_dhcp_relay_subnet_broadcast
  config_get_default('interface', 'ipv4_dhcp_relay_subnet_broadcast')
end

#default_ipv4_dhcp_smart_relayObject



518
519
520
# File 'lib/cisco_node_utils/interface.rb', line 518

def default_ipv4_dhcp_smart_relay
  config_get_default('interface', 'ipv4_dhcp_smart_relay')
end

#default_ipv4_forwardingObject



531
532
533
# File 'lib/cisco_node_utils/interface.rb', line 531

def default_ipv4_forwarding
  config_get_default('interface', 'ipv4_forwarding')
end

#default_ipv4_netmask_lengthObject



390
391
392
# File 'lib/cisco_node_utils/interface.rb', line 390

def default_ipv4_netmask_length
  config_get_default('interface', 'ipv4_netmask_length')
end

#default_ipv4_netmask_length_secondaryObject



394
395
396
# File 'lib/cisco_node_utils/interface.rb', line 394

def default_ipv4_netmask_length_secondary
  default_ipv4_netmask_length
end

#default_ipv4_pim_sparse_modeObject



546
547
548
# File 'lib/cisco_node_utils/interface.rb', line 546

def default_ipv4_pim_sparse_mode
  config_get_default('interface', 'ipv4_pim_sparse_mode')
end

#default_ipv4_proxy_arpObject



560
561
562
# File 'lib/cisco_node_utils/interface.rb', line 560

def default_ipv4_proxy_arp
  config_get_default('interface', 'ipv4_proxy_arp')
end

#default_ipv4_redirectsObject



584
585
586
# File 'lib/cisco_node_utils/interface.rb', line 584

def default_ipv4_redirects
  config_get_default('interface', ipv4_redirects_lookup_string)
end

#default_ipv6_acl_inObject



604
605
606
# File 'lib/cisco_node_utils/interface.rb', line 604

def default_ipv6_acl_in
  config_get_default('interface', 'ipv6_acl_in')
end

#default_ipv6_acl_outObject



624
625
626
# File 'lib/cisco_node_utils/interface.rb', line 624

def default_ipv6_acl_out
  config_get_default('interface', 'ipv6_acl_out')
end

#default_ipv6_dhcp_relay_addrObject



648
649
650
# File 'lib/cisco_node_utils/interface.rb', line 648

def default_ipv6_dhcp_relay_addr
  config_get_default('interface', 'ipv6_dhcp_relay_addr')
end

#default_ipv6_dhcp_relay_src_intfObject



667
668
669
# File 'lib/cisco_node_utils/interface.rb', line 667

def default_ipv6_dhcp_relay_src_intf
  config_get_default('interface', 'ipv6_dhcp_relay_src_intf')
end

#default_mtuObject



699
700
701
# File 'lib/cisco_node_utils/interface.rb', line 699

def default_mtu
  config_get_default('interface', mtu_lookup_string)
end

#default_negotiate_autoObject



748
749
750
# File 'lib/cisco_node_utils/interface.rb', line 748

def default_negotiate_auto
  config_get_default('interface', negotiate_auto_lookup_string)
end

#default_pvlan_mappingObject



1516
1517
1518
# File 'lib/cisco_node_utils/interface.rb', line 1516

def default_pvlan_mapping
  config_get_default('interface', 'pvlan_mapping')
end

#default_shutdownObject



761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
# File 'lib/cisco_node_utils/interface.rb', line 761

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_speedObject



711
712
713
# File 'lib/cisco_node_utils/interface.rb', line 711

def default_speed
  config_get_default('interface', 'speed')
end

#default_storm_control_broadcastObject



805
806
807
# File 'lib/cisco_node_utils/interface.rb', line 805

def default_storm_control_broadcast
  config_get_default('interface', 'storm_control_broadcast')
end

#default_storm_control_multicastObject



820
821
822
# File 'lib/cisco_node_utils/interface.rb', line 820

def default_storm_control_multicast
  config_get_default('interface', 'storm_control_multicast')
end

#default_storm_control_unicastObject



835
836
837
# File 'lib/cisco_node_utils/interface.rb', line 835

def default_storm_control_unicast
  config_get_default('interface', 'storm_control_unicast')
end

#default_stp_bpdufilterObject



855
856
857
# File 'lib/cisco_node_utils/interface.rb', line 855

def default_stp_bpdufilter
  config_get_default('interface', 'stp_bpdufilter')
end

#default_stp_bpduguardObject



874
875
876
# File 'lib/cisco_node_utils/interface.rb', line 874

def default_stp_bpduguard
  config_get_default('interface', 'stp_bpduguard')
end

#default_stp_costObject



888
889
890
# File 'lib/cisco_node_utils/interface.rb', line 888

def default_stp_cost
  config_get_default('interface', 'stp_cost')
end

#default_stp_guardObject



908
909
910
# File 'lib/cisco_node_utils/interface.rb', line 908

def default_stp_guard
  config_get_default('interface', 'stp_guard')
end


921
922
923
# File 'lib/cisco_node_utils/interface.rb', line 921

def default_stp_link_type
  config_get_default('interface', 'stp_link_type')
end

#default_stp_mst_costObject



956
957
958
# File 'lib/cisco_node_utils/interface.rb', line 956

def default_stp_mst_cost
  config_get_default('interface', 'stp_mst_cost')
end

#default_stp_mst_port_priorityObject



978
979
980
# File 'lib/cisco_node_utils/interface.rb', line 978

def default_stp_mst_port_priority
  config_get_default('interface', 'stp_mst_port_priority')
end

#default_stp_port_priorityObject



934
935
936
# File 'lib/cisco_node_utils/interface.rb', line 934

def default_stp_port_priority
  config_get_default('interface', 'stp_port_priority')
end

#default_stp_port_typeObject



997
998
999
# File 'lib/cisco_node_utils/interface.rb', line 997

def default_stp_port_type
  config_get_default('interface', 'stp_port_type')
end

#default_stp_vlan_costObject



1019
1020
1021
# File 'lib/cisco_node_utils/interface.rb', line 1019

def default_stp_vlan_cost
  config_get_default('interface', 'stp_vlan_cost')
end

#default_stp_vlan_port_priorityObject



1041
1042
1043
# File 'lib/cisco_node_utils/interface.rb', line 1041

def default_stp_vlan_port_priority
  config_get_default('interface', 'stp_vlan_port_priority')
end

#default_svi_autostateObject



1652
1653
1654
# File 'lib/cisco_node_utils/interface.rb', line 1652

def default_svi_autostate
  system_default_svi_autostate
end

#default_svi_managementObject



1680
1681
1682
# File 'lib/cisco_node_utils/interface.rb', line 1680

def default_svi_management
  config_get_default('interface', 'svi_management')
end

#default_switchport_autostate_excludeObject



1071
1072
1073
# File 'lib/cisco_node_utils/interface.rb', line 1071

def default_switchport_autostate_exclude
  config_get_default('interface', 'switchport_autostate_exclude')
end

#default_switchport_modeObject



1138
1139
1140
1141
1142
1143
# File 'lib/cisco_node_utils/interface.rb', line 1138

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_pvlan_hostObject



1213
1214
1215
# File 'lib/cisco_node_utils/interface.rb', line 1213

def default_switchport_pvlan_host
  config_get_default('interface', 'switchport_pvlan_host')
end

#default_switchport_pvlan_host_associationObject



1251
1252
1253
# File 'lib/cisco_node_utils/interface.rb', line 1251

def default_switchport_pvlan_host_association
  config_get_default('interface', 'switchport_pvlan_host_association')
end

#default_switchport_pvlan_mappingObject



1266
1267
1268
# File 'lib/cisco_node_utils/interface.rb', line 1266

def default_switchport_pvlan_mapping
  config_get_default('interface', 'switchport_pvlan_mapping')
end

#default_switchport_pvlan_mapping_trunkObject



1331
1332
1333
# File 'lib/cisco_node_utils/interface.rb', line 1331

def default_switchport_pvlan_mapping_trunk
  config_get_default('interface', 'switchport_pvlan_mapping_trunk')
end

#default_switchport_pvlan_promiscuousObject



1229
1230
1231
# File 'lib/cisco_node_utils/interface.rb', line 1229

def default_switchport_pvlan_promiscuous
  config_get_default('interface', 'switchport_pvlan_promiscuous')
end

#default_switchport_pvlan_trunk_allowed_vlanObject



1463
1464
1465
# File 'lib/cisco_node_utils/interface.rb', line 1463

def default_switchport_pvlan_trunk_allowed_vlan
  config_get_default('interface', 'switchport_pvlan_trunk_allowed_vlan')
end

#default_switchport_pvlan_trunk_associationObject



1405
1406
1407
# File 'lib/cisco_node_utils/interface.rb', line 1405

def default_switchport_pvlan_trunk_association
  config_get_default('interface', 'switchport_pvlan_trunk_association')
end

#default_switchport_pvlan_trunk_native_vlanObject



1479
1480
1481
# File 'lib/cisco_node_utils/interface.rb', line 1479

def default_switchport_pvlan_trunk_native_vlan
  config_get_default('interface', 'switchport_pvlan_trunk_native_vlan')
end

#default_switchport_pvlan_trunk_promiscuousObject



1421
1422
1423
# File 'lib/cisco_node_utils/interface.rb', line 1421

def default_switchport_pvlan_trunk_promiscuous
  config_get_default('interface', 'switchport_pvlan_trunk_promiscuous')
end

#default_switchport_pvlan_trunk_secondaryObject



1437
1438
1439
# File 'lib/cisco_node_utils/interface.rb', line 1437

def default_switchport_pvlan_trunk_secondary
  config_get_default('interface', 'switchport_pvlan_trunk_secondary')
end

#default_switchport_trunk_allowed_vlanObject



1163
1164
1165
# File 'lib/cisco_node_utils/interface.rb', line 1163

def default_switchport_trunk_allowed_vlan
  config_get_default('interface', 'switchport_trunk_allowed_vlan')
end

#default_switchport_trunk_native_vlanObject



1581
1582
1583
# File 'lib/cisco_node_utils/interface.rb', line 1581

def default_switchport_trunk_native_vlan
  config_get_default('interface', 'switchport_trunk_native_vlan')
end

#default_switchport_vtpObject



1684
1685
1686
1687
# File 'lib/cisco_node_utils/interface.rb', line 1684

def default_switchport_vtp
  return nil unless switchport_vtp_mode_capable?
  config_get_default('interface', 'vtp')
end

#default_vlan_mappingObject

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’]]



1536
1537
1538
# File 'lib/cisco_node_utils/interface.rb', line 1536

def default_vlan_mapping
  config_get_default('interface', 'vlan_mapping')
end

#default_vlan_mapping_enableObject

cli: switchport vlan mapping enable



1568
1569
1570
# File 'lib/cisco_node_utils/interface.rb', line 1568

def default_vlan_mapping_enable
  config_get_default('interface', 'vlan_mapping_enable')
end

#default_vpc_idObject



1726
1727
1728
# File 'lib/cisco_node_utils/interface.rb', line 1726

def default_vpc_id
  config_get_default('interface', 'vpc_id')
end


1739
1740
1741
# File 'lib/cisco_node_utils/interface.rb', line 1739

def default_vpc_peer_link
  config_get_default('interface', 'vpc_peer_link')
end

#default_vrfObject



1769
1770
1771
# File 'lib/cisco_node_utils/interface.rb', line 1769

def default_vrf
  config_get_default('interface', 'vrf')
end

#descriptionObject



199
200
201
# File 'lib/cisco_node_utils/interface.rb', line 199

def description
  config_get('interface', 'description', name: @name)
end

#description=(desc) ⇒ Object



203
204
205
206
207
208
209
210
211
212
# File 'lib/cisco_node_utils/interface.rb', line 203

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

#destroyObject



143
144
145
# File 'lib/cisco_node_utils/interface.rb', line 143

def destroy
  config_set('interface', 'destroy', name: @name)
end

#duplexObject



715
716
717
# File 'lib/cisco_node_utils/interface.rb', line 715

def duplex
  config_get('interface', 'duplex', name: @name)
end

#duplex=(val) ⇒ Object



719
720
721
# File 'lib/cisco_node_utils/interface.rb', line 719

def duplex=(val)
  config_set('interface', 'duplex', name: @name, duplex: val)
end

#encapsulation_dot1qObject



218
219
220
# File 'lib/cisco_node_utils/interface.rb', line 218

def encapsulation_dot1q
  config_get('interface', 'encapsulation_dot1q', name: @name)
end

#encapsulation_dot1q=(val) ⇒ Object



222
223
224
225
226
227
228
229
230
# File 'lib/cisco_node_utils/interface.rb', line 222

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_gatewayObject



244
245
246
# File 'lib/cisco_node_utils/interface.rb', line 244

def fabric_forwarding_anycast_gateway
  config_get('interface', 'fabric_forwarding_anycast_gateway', name: @name)
end

#fabric_forwarding_anycast_gateway=(state) ⇒ Object



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/cisco_node_utils/interface.rb', line 248

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_featureObject



236
237
238
# File 'lib/cisco_node_utils/interface.rb', line 236

def fabricpath_feature
  FabricpathGlobal.fabricpath_feature
end

#fabricpath_feature_set(fabricpath_set) ⇒ Object



240
241
242
# File 'lib/cisco_node_utils/interface.rb', line 240

def fabricpath_feature_set(fabricpath_set)
  FabricpathGlobal.fabricpath_feature_set(fabricpath_set)
end

#feature_lacp?Boolean

Returns:

  • (Boolean)


671
672
673
# File 'lib/cisco_node_utils/interface.rb', line 671

def feature_lacp?
  config_get('interface', 'feature_lacp')
end

#feature_lacp_set(val) ⇒ Object



675
676
677
678
# File 'lib/cisco_node_utils/interface.rb', line 675

def feature_lacp_set(val)
  return if feature_lacp? == val
  config_set('interface', 'feature_lacp', state: val ? '' : 'no')
end

#feature_vlan?Boolean

Returns:

  • (Boolean)


1656
1657
1658
# File 'lib/cisco_node_utils/interface.rb', line 1656

def feature_vlan?
  config_get('interface', 'feature_vlan')
end

#feature_vlan_set(val = true) ⇒ Object



1660
1661
1662
1663
1664
1665
# File 'lib/cisco_node_utils/interface.rb', line 1660

def feature_vlan_set(val=true)
  # 'feature interface-vlan'
  # TBD: Replace this with Feature.interface_vlan_enable
  return if feature_vlan? == val
  config_set('interface', 'feature_vlan', state: val ? '' : 'no')
end

#ipv4_acl_inObject



269
270
271
# File 'lib/cisco_node_utils/interface.rb', line 269

def ipv4_acl_in
  config_get('interface', 'ipv4_acl_in', name: @name)
end

#ipv4_acl_in=(val) ⇒ Object



273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/cisco_node_utils/interface.rb', line 273

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_outObject



290
291
292
# File 'lib/cisco_node_utils/interface.rb', line 290

def ipv4_acl_out
  config_get('interface', 'ipv4_acl_out', name: @name)
end

#ipv4_acl_out=(val) ⇒ Object



294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/cisco_node_utils/interface.rb', line 294

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_maskObject



332
333
334
335
336
337
338
339
340
341
342
343
344
# File 'lib/cisco_node_utils/interface.rb', line 332

def ipv4_addr_mask
  val = config_get('interface', 'ipv4_addr_mask', name: @name)
  if val && platform == :ios_xr
    # IOS XR reports address as <address> <bitmask> [secondary] but we
    # want <address>/<length> [secondary]
    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



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/cisco_node_utils/interface.rb', line 311

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
      # We need address and mask to remove.
      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_addressObject



366
367
368
# File 'lib/cisco_node_utils/interface.rb', line 366

def ipv4_address
  select_ipv4_attribute(:v4_addr)
end

#ipv4_address_secondaryObject



370
371
372
# File 'lib/cisco_node_utils/interface.rb', line 370

def ipv4_address_secondary
  select_ipv4_attribute(:v4_addr_secondary)
end

#ipv4_arp_timeoutObject



407
408
409
# File 'lib/cisco_node_utils/interface.rb', line 407

def ipv4_arp_timeout
  config_get('interface', ipv4_arp_timeout_lookup_string, name: @name)
end

#ipv4_arp_timeout=(timeout) ⇒ Object



411
412
413
414
415
416
417
# File 'lib/cisco_node_utils/interface.rb', line 411

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_stringObject



398
399
400
401
402
403
404
405
# File 'lib/cisco_node_utils/interface.rb', line 398

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_dhcp_relay_addrObject



423
424
425
# File 'lib/cisco_node_utils/interface.rb', line 423

def ipv4_dhcp_relay_addr
  config_get('interface', 'ipv4_dhcp_relay_addr', name: @name)
end

#ipv4_dhcp_relay_addr=(list) ⇒ Object



427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
# File 'lib/cisco_node_utils/interface.rb', line 427

def ipv4_dhcp_relay_addr=(list)
  cur_list = ipv4_dhcp_relay_addr
  # remove the current addresses first
  unless cur_list.empty?
    cur_list.each do |addr|
      config_set('interface', 'ipv4_dhcp_relay_addr',
                 name:  @name, state: 'no', addr: addr)
    end
  end
  Feature.dhcp_enable unless list.empty?
  list.each do |addr|
    config_set('interface', 'ipv4_dhcp_relay_addr',
               name:  @name, state: '', addr: addr)
  end
end

#ipv4_dhcp_relay_info_trustObject



447
448
449
# File 'lib/cisco_node_utils/interface.rb', line 447

def ipv4_dhcp_relay_info_trust
  config_get('interface', 'ipv4_dhcp_relay_info_trust', name: @name)
end

#ipv4_dhcp_relay_info_trust=(state) ⇒ Object



451
452
453
454
455
# File 'lib/cisco_node_utils/interface.rb', line 451

def ipv4_dhcp_relay_info_trust=(state)
  Feature.dhcp_enable if state
  config_set('interface', 'ipv4_dhcp_relay_info_trust',
             name:  @name, state: state ? '' : 'no')
end

#ipv4_dhcp_relay_src_addr_hsrpObject



461
462
463
# File 'lib/cisco_node_utils/interface.rb', line 461

def ipv4_dhcp_relay_src_addr_hsrp
  config_get('interface', 'ipv4_dhcp_relay_src_addr_hsrp', name: @name)
end

#ipv4_dhcp_relay_src_addr_hsrp=(state) ⇒ Object



465
466
467
468
469
# File 'lib/cisco_node_utils/interface.rb', line 465

def ipv4_dhcp_relay_src_addr_hsrp=(state)
  Feature.dhcp_enable if state
  config_set('interface', 'ipv4_dhcp_relay_src_addr_hsrp',
             name:  @name, state: state ? '' : 'no')
end

#ipv4_dhcp_relay_src_intfObject



475
476
477
478
479
480
# File 'lib/cisco_node_utils/interface.rb', line 475

def ipv4_dhcp_relay_src_intf
  intf = config_get('interface', 'ipv4_dhcp_relay_src_intf', name: @name)
  # Normalize by downcasing and removing white space
  intf = intf.downcase.delete(' ') if intf
  intf
end

#ipv4_dhcp_relay_src_intf=(val) ⇒ Object



482
483
484
485
486
487
488
# File 'lib/cisco_node_utils/interface.rb', line 482

def ipv4_dhcp_relay_src_intf=(val)
  state = val == default_ipv4_dhcp_relay_src_intf ? 'no' : ''
  intf = val == default_ipv4_dhcp_relay_src_intf ? '' : val
  Feature.dhcp_enable if state.empty?
  config_set('interface', 'ipv4_dhcp_relay_src_intf',
             name:  @name, state: state, intf: intf)
end

#ipv4_dhcp_relay_subnet_broadcastObject



494
495
496
# File 'lib/cisco_node_utils/interface.rb', line 494

def ipv4_dhcp_relay_subnet_broadcast
  config_get('interface', 'ipv4_dhcp_relay_subnet_broadcast', name: @name)
end

#ipv4_dhcp_relay_subnet_broadcast=(state) ⇒ Object



498
499
500
501
502
# File 'lib/cisco_node_utils/interface.rb', line 498

def ipv4_dhcp_relay_subnet_broadcast=(state)
  Feature.dhcp_enable if state
  config_set('interface', 'ipv4_dhcp_relay_subnet_broadcast',
             name:  @name, state: state ? '' : 'no')
end

#ipv4_dhcp_smart_relayObject



508
509
510
# File 'lib/cisco_node_utils/interface.rb', line 508

def ipv4_dhcp_smart_relay
  config_get('interface', 'ipv4_dhcp_smart_relay', name: @name)
end

#ipv4_dhcp_smart_relay=(state) ⇒ Object



512
513
514
515
516
# File 'lib/cisco_node_utils/interface.rb', line 512

def ipv4_dhcp_smart_relay=(state)
  Feature.dhcp_enable if state
  config_set('interface', 'ipv4_dhcp_smart_relay',
             name:  @name, state: state ? '' : 'no')
end

#ipv4_forwardingObject



522
523
524
# File 'lib/cisco_node_utils/interface.rb', line 522

def ipv4_forwarding
  config_get('interface', 'ipv4_forwarding', name: @name)
end

#ipv4_forwarding=(state) ⇒ Object



526
527
528
529
# File 'lib/cisco_node_utils/interface.rb', line 526

def ipv4_forwarding=(state)
  config_set('interface', 'ipv4_forwarding',
             name:  @name, state: state ? '' : 'no')
end

#ipv4_netmask_lengthObject



374
375
376
# File 'lib/cisco_node_utils/interface.rb', line 374

def ipv4_netmask_length
  select_ipv4_attribute(:v4_mask)
end

#ipv4_netmask_length_secondaryObject



378
379
380
# File 'lib/cisco_node_utils/interface.rb', line 378

def ipv4_netmask_length_secondary
  select_ipv4_attribute(:v4_mask_secondary)
end

#ipv4_pim_sparse_modeObject



535
536
537
# File 'lib/cisco_node_utils/interface.rb', line 535

def ipv4_pim_sparse_mode
  config_get('interface', 'ipv4_pim_sparse_mode', name: @name)
end

#ipv4_pim_sparse_mode=(state) ⇒ Object



539
540
541
542
543
544
# File 'lib/cisco_node_utils/interface.rb', line 539

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_arpObject



550
551
552
# File 'lib/cisco_node_utils/interface.rb', line 550

def ipv4_proxy_arp
  config_get('interface', 'ipv4_proxy_arp', name: @name)
end

#ipv4_proxy_arp=(proxy_arp) ⇒ Object



554
555
556
557
558
# File 'lib/cisco_node_utils/interface.rb', line 554

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_redirectsObject



573
574
575
# File 'lib/cisco_node_utils/interface.rb', line 573

def ipv4_redirects
  config_get('interface', ipv4_redirects_lookup_string, name: @name)
end

#ipv4_redirects=(redirects) ⇒ Object



577
578
579
580
581
582
# File 'lib/cisco_node_utils/interface.rb', line 577

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_stringObject



564
565
566
567
568
569
570
571
# File 'lib/cisco_node_utils/interface.rb', line 564

def ipv4_redirects_lookup_string
  case @name
  when /loopback/i
    return 'ipv4_redirects_loopback'
  else
    return 'ipv4_redirects_other_interfaces'
  end
end

#ipv6_acl_inObject



588
589
590
# File 'lib/cisco_node_utils/interface.rb', line 588

def ipv6_acl_in
  config_get('interface', 'ipv6_acl_in', name: @name)
end

#ipv6_acl_in=(val) ⇒ Object



592
593
594
595
596
597
598
599
600
601
602
# File 'lib/cisco_node_utils/interface.rb', line 592

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_outObject



608
609
610
# File 'lib/cisco_node_utils/interface.rb', line 608

def ipv6_acl_out
  config_get('interface', 'ipv6_acl_out', name: @name)
end

#ipv6_acl_out=(val) ⇒ Object



612
613
614
615
616
617
618
619
620
621
622
# File 'lib/cisco_node_utils/interface.rb', line 612

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

#ipv6_dhcp_relay_addrObject



628
629
630
# File 'lib/cisco_node_utils/interface.rb', line 628

def ipv6_dhcp_relay_addr
  config_get('interface', 'ipv6_dhcp_relay_addr', name: @name)
end

#ipv6_dhcp_relay_addr=(list) ⇒ Object



632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
# File 'lib/cisco_node_utils/interface.rb', line 632

def ipv6_dhcp_relay_addr=(list)
  cur_list = ipv6_dhcp_relay_addr
  # remove the current addresses first
  unless cur_list.empty?
    cur_list.each do |addr|
      config_set('interface', 'ipv6_dhcp_relay_addr',
                 name:  @name, state: 'no', addr: addr)
    end
  end
  Feature.dhcp_enable unless list.empty?
  list.each do |addr|
    config_set('interface', 'ipv6_dhcp_relay_addr',
               name:  @name, state: '', addr: addr)
  end
end

#ipv6_dhcp_relay_src_intfObject



652
653
654
655
656
657
# File 'lib/cisco_node_utils/interface.rb', line 652

def ipv6_dhcp_relay_src_intf
  intf = config_get('interface', 'ipv6_dhcp_relay_src_intf', name: @name)
  # Normalize by downcasing and removing white space
  intf = intf.downcase.delete(' ') if intf
  intf
end

#ipv6_dhcp_relay_src_intf=(val) ⇒ Object



659
660
661
662
663
664
665
# File 'lib/cisco_node_utils/interface.rb', line 659

def ipv6_dhcp_relay_src_intf=(val)
  state = val == default_ipv6_dhcp_relay_src_intf ? 'no' : ''
  intf = val == default_ipv6_dhcp_relay_src_intf ? '' : val
  Feature.dhcp_enable if state.empty?
  config_set('interface', 'ipv6_dhcp_relay_src_intf',
             name:  @name, state: state, intf: intf)
end

#mtuObject



689
690
691
# File 'lib/cisco_node_utils/interface.rb', line 689

def mtu
  config_get('interface', mtu_lookup_string, name: @name)
end

#mtu=(val) ⇒ Object



693
694
695
696
697
# File 'lib/cisco_node_utils/interface.rb', line 693

def mtu=(val)
  check_switchport(:disabled)
  config_set('interface', mtu_lookup_string,
             name: @name, state: '', mtu: val)
end

#mtu_lookup_stringObject



680
681
682
683
684
685
686
687
# File 'lib/cisco_node_utils/interface.rb', line 680

def mtu_lookup_string
  case @name
  when /loopback/i
    return 'mtu_loopback'
  else
    return 'mtu_other_interfaces'
  end
end

#negotiate_autoObject



738
739
740
# File 'lib/cisco_node_utils/interface.rb', line 738

def negotiate_auto
  config_get('interface', negotiate_auto_lookup_string, name: @name)
end

#negotiate_auto=(negotiate_auto) ⇒ Object



742
743
744
745
746
# File 'lib/cisco_node_utils/interface.rb', line 742

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_stringObject



727
728
729
730
731
732
733
734
735
736
# File 'lib/cisco_node_utils/interface.rb', line 727

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

#pvlan_enableObject



147
148
149
150
# File 'lib/cisco_node_utils/interface.rb', line 147

def pvlan_enable
  switchport_enable
  Feature.private_vlan_enable
end

#pvlan_mappingObject


This is an SVI property. <state> private-vlan mapping <range> # ex. range = [‘2-4,9’] Always returns an array.



1487
1488
1489
1490
1491
# File 'lib/cisco_node_utils/interface.rb', line 1487

def pvlan_mapping
  range = config_get('interface', 'pvlan_mapping', name: @name)
  return default_pvlan_mapping if range.nil?
  range.empty? ? range : [range.delete(' ')]
end

#pvlan_mapping=(range) ⇒ Object



1493
1494
1495
1496
1497
1498
1499
1500
1501
# File 'lib/cisco_node_utils/interface.rb', line 1493

def pvlan_mapping=(range)
  feature_vlan_set
  Feature.private_vlan_enable

  is = Utils.dash_range_to_elements(pvlan_mapping)
  should = Utils.dash_range_to_elements(range)

  pvlan_mapping_delta(is, should)
end

#pvlan_mapping_delta(is, should) ⇒ Object



1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
# File 'lib/cisco_node_utils/interface.rb', line 1503

def pvlan_mapping_delta(is, should)
  delta_hash = Utils.delta_add_remove(should, is)
  Cisco::Logger.debug("pvlan_mapping_delta: #{delta_hash}")
  [:remove, :add].each do |action|
    delta_hash[action].each do |vlan|
      state = (action == :add) ? '' : 'no'
      cli_error_check(
        config_set('interface', 'pvlan_mapping',
                   name: @name, state: state, vlan: vlan))
    end
  end
end

#pvlan_trunk_association_delta(is, should) ⇒ Object



1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
# File 'lib/cisco_node_utils/interface.rb', line 1388

def pvlan_trunk_association_delta(is, should)
  delta_hash = Utils.delta_add_remove(should, is)
  Cisco::Logger.debug("pvlan_trunk_association_delta: #{delta_hash}")
  [:remove, :add].each do |action|
    delta_hash[action].each do |pri_and_sec|
      state = (action == :add) ? '' : 'no'
      pri, sec = pri_and_sec

      # Cli does not like removals that specify the secondary
      sec = '' if action[/remove/]
      cli_error_check(
        config_set('interface', 'switchport_pvlan_trunk_association',
                   name: @name, state: state, pri: pri, sec: sec))
    end
  end
end

#select_ipv4_attribute(attribute) ⇒ Object



346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/cisco_node_utils/interface.rb', line 346

def select_ipv4_attribute(attribute)
  d = ipv4_addr_mask.flatten unless ipv4_addr_mask.nil?
  # (d)ata format after flatten: ['addr', 'mask', 'addr', 'mask secondary']
  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



1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
# File 'lib/cisco_node_utils/interface.rb', line 1773

def set_range_based_params(list, param_name)
  list.each do |range, property_value|
    # if a particular range is set to default, use 'no' cmd
    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

#shutdownObject



752
753
754
# File 'lib/cisco_node_utils/interface.rb', line 752

def shutdown
  config_get('interface', 'shutdown', name: @name)
end

#shutdown=(state) ⇒ Object



756
757
758
759
# File 'lib/cisco_node_utils/interface.rb', line 756

def shutdown=(state)
  no_cmd = (state ? '' : 'no')
  config_set('interface', 'shutdown', name: @name, state: no_cmd)
end

#speedObject



703
704
705
# File 'lib/cisco_node_utils/interface.rb', line 703

def speed
  config_get('interface', 'speed', name: @name)
end

#speed=(val) ⇒ Object



707
708
709
# File 'lib/cisco_node_utils/interface.rb', line 707

def speed=(val)
  config_set('interface', 'speed', name: @name, speed: val)
end

#storm_control_broadcastObject



794
795
796
# File 'lib/cisco_node_utils/interface.rb', line 794

def storm_control_broadcast
  config_get('interface', 'storm_control_broadcast', name: @name)
end

#storm_control_broadcast=(val) ⇒ Object



798
799
800
801
802
803
# File 'lib/cisco_node_utils/interface.rb', line 798

def storm_control_broadcast=(val)
  state = val == default_storm_control_broadcast ? 'no' : ''
  level = val == default_storm_control_broadcast ? '' : val
  config_set('interface', 'storm_control_broadcast',
             name: @name, state: state, level: level)
end

#storm_control_multicastObject



809
810
811
# File 'lib/cisco_node_utils/interface.rb', line 809

def storm_control_multicast
  config_get('interface', 'storm_control_multicast', name: @name)
end

#storm_control_multicast=(val) ⇒ Object



813
814
815
816
817
818
# File 'lib/cisco_node_utils/interface.rb', line 813

def storm_control_multicast=(val)
  state = val == default_storm_control_multicast ? 'no' : ''
  level = val == default_storm_control_multicast ? '' : val
  config_set('interface', 'storm_control_multicast',
             name: @name, state: state, level: level)
end

#storm_control_unicastObject



824
825
826
# File 'lib/cisco_node_utils/interface.rb', line 824

def storm_control_unicast
  config_get('interface', 'storm_control_unicast', name: @name)
end

#storm_control_unicast=(val) ⇒ Object



828
829
830
831
832
833
# File 'lib/cisco_node_utils/interface.rb', line 828

def storm_control_unicast=(val)
  state = val == default_storm_control_unicast ? 'no' : ''
  level = val == default_storm_control_unicast ? '' : val
  config_set('interface', 'storm_control_unicast',
             name: @name, state: state, level: level)
end

#stp_bpdufilterObject



839
840
841
# File 'lib/cisco_node_utils/interface.rb', line 839

def stp_bpdufilter
  config_get('interface', 'stp_bpdufilter', name: @name)
end

#stp_bpdufilter=(val) ⇒ Object



843
844
845
846
847
848
849
850
851
852
853
# File 'lib/cisco_node_utils/interface.rb', line 843

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_bpduguardObject



859
860
861
# File 'lib/cisco_node_utils/interface.rb', line 859

def stp_bpduguard
  config_get('interface', 'stp_bpduguard', name: @name)
end

#stp_bpduguard=(val) ⇒ Object



863
864
865
866
867
868
869
870
871
872
# File 'lib/cisco_node_utils/interface.rb', line 863

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_costObject



878
879
880
881
# File 'lib/cisco_node_utils/interface.rb', line 878

def stp_cost
  cost = config_get('interface', 'stp_cost', name: @name)
  cost == 'auto' ? cost : cost.to_i
end

#stp_cost=(val) ⇒ Object



883
884
885
886
# File 'lib/cisco_node_utils/interface.rb', line 883

def stp_cost=(val)
  check_switchport([:access, :trunk])
  config_set('interface', 'stp_cost', name: @name, cost: val)
end

#stp_guardObject



892
893
894
# File 'lib/cisco_node_utils/interface.rb', line 892

def stp_guard
  config_get('interface', 'stp_guard', name: @name)
end

#stp_guard=(val) ⇒ Object



896
897
898
899
900
901
902
903
904
905
906
# File 'lib/cisco_node_utils/interface.rb', line 896

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


912
913
914
# File 'lib/cisco_node_utils/interface.rb', line 912

def stp_link_type
  config_get('interface', 'stp_link_type', name: @name)
end


916
917
918
919
# File 'lib/cisco_node_utils/interface.rb', line 916

def stp_link_type=(val)
  check_switchport([:access, :trunk])
  config_set('interface', 'stp_link_type', name: @name, type: val)
end

#stp_mst_costObject

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’]]



944
945
946
# File 'lib/cisco_node_utils/interface.rb', line 944

def stp_mst_cost
  config_get('interface', 'stp_mst_cost', name: @name)
end

#stp_mst_cost=(list) ⇒ Object



948
949
950
951
952
953
954
# File 'lib/cisco_node_utils/interface.rb', line 948

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_priorityObject

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’]]



966
967
968
# File 'lib/cisco_node_utils/interface.rb', line 966

def stp_mst_port_priority
  config_get('interface', 'stp_mst_port_priority', name: @name)
end

#stp_mst_port_priority=(list) ⇒ Object



970
971
972
973
974
975
976
# File 'lib/cisco_node_utils/interface.rb', line 970

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_priorityObject



925
926
927
# File 'lib/cisco_node_utils/interface.rb', line 925

def stp_port_priority
  config_get('interface', 'stp_port_priority', name: @name)
end

#stp_port_priority=(val) ⇒ Object



929
930
931
932
# File 'lib/cisco_node_utils/interface.rb', line 929

def stp_port_priority=(val)
  check_switchport([:access, :trunk])
  config_set('interface', 'stp_port_priority', name: @name, pp: val)
end

#stp_port_typeObject



982
983
984
# File 'lib/cisco_node_utils/interface.rb', line 982

def stp_port_type
  config_get('interface', 'stp_port_type', name: @name)
end

#stp_port_type=(val) ⇒ Object



986
987
988
989
990
991
992
993
994
995
# File 'lib/cisco_node_utils/interface.rb', line 986

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_costObject

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’]]



1007
1008
1009
# File 'lib/cisco_node_utils/interface.rb', line 1007

def stp_vlan_cost
  config_get('interface', 'stp_vlan_cost', name: @name)
end

#stp_vlan_cost=(list) ⇒ Object



1011
1012
1013
1014
1015
1016
1017
# File 'lib/cisco_node_utils/interface.rb', line 1011

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_priorityObject

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’]]



1029
1030
1031
# File 'lib/cisco_node_utils/interface.rb', line 1029

def stp_vlan_port_priority
  config_get('interface', 'stp_vlan_port_priority', name: @name)
end

#stp_vlan_port_priority=(list) ⇒ Object



1033
1034
1035
1036
1037
1038
1039
# File 'lib/cisco_node_utils/interface.rb', line 1033

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_autostateObject

svi_autostate is exclusive to svi interfaces



1640
1641
1642
1643
# File 'lib/cisco_node_utils/interface.rb', line 1640

def svi_autostate
  return nil unless @name[/^vlan/i]
  config_get('interface', 'svi_autostate', name: @name)
end

#svi_autostate=(val) ⇒ Object



1645
1646
1647
1648
1649
1650
# File 'lib/cisco_node_utils/interface.rb', line 1645

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

Returns:

  • (Boolean)


1634
1635
1636
1637
# File 'lib/cisco_node_utils/interface.rb', line 1634

def svi_cmd_allowed?(cmd)
  fail "[#{@name}] Invalid interface type for command [#{cmd}]" unless
    @name[/vlan/i]
end

#svi_managementObject

svi_management is exclusive to svi interfaces



1668
1669
1670
1671
# File 'lib/cisco_node_utils/interface.rb', line 1668

def svi_management
  return nil unless @name[/^vlan/i]
  config_get('interface', 'svi_management', name: @name)
end

#svi_management=(val) ⇒ Object



1673
1674
1675
1676
1677
1678
# File 'lib/cisco_node_utils/interface.rb', line 1673

def svi_management=(val)
  check_switchport(:disabled)
  svi_cmd_allowed?('management')
  config_set('interface', 'svi_management',
             name: @name, state: val ? '' : 'no')
end

#switchportObject



1045
1046
1047
1048
# File 'lib/cisco_node_utils/interface.rb', line 1045

def switchport
  # This is "switchport", not "switchport mode"
  config_get('interface', 'switchport', name: @name)
end

#switchport_autostate_excludeObject

switchport_autostate_exclude is exclusive to switchport interfaces



1055
1056
1057
1058
# File 'lib/cisco_node_utils/interface.rb', line 1055

def switchport_autostate_exclude
  config_get('interface',
             'switchport_autostate_exclude', name: @name)
end

#switchport_autostate_exclude=(val) ⇒ Object



1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
# File 'lib/cisco_node_utils/interface.rb', line 1060

def switchport_autostate_exclude=(val)
  if platform == :nexus
    # cannot configure autostate unless feature vlan is enabled
    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



1050
1051
1052
# File 'lib/cisco_node_utils/interface.rb', line 1050

def switchport_enable(val=true)
  config_set('interface', 'switchport', name: @name, state: val ? '' : 'no')
end

#switchport_enable_and_mode(mode_set) ⇒ Object



1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
# File 'lib/cisco_node_utils/interface.rb', line 1100

def switchport_enable_and_mode(mode_set)
  switchport_enable

  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_modeObject



1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
# File 'lib/cisco_node_utils/interface.rb', line 1086

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
  # Assume this is an interface that doesn't support switchport.
  # Do not raise exception since the providers will prefetch this property
  # regardless of interface type.
  # TODO: this should probably be nil instead
  return :disabled
end

#switchport_mode=(mode_set) ⇒ Object



1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
# File 'lib/cisco_node_utils/interface.rb', line 1112

def switchport_mode=(mode_set)
  # no system default switchport
  # int e1/1
  #   switchport
  #   switchport mode [access|trunk|fex|...]
  fail ArgumentError unless IF_SWITCHPORT_MODE.keys.include? mode_set
  case mode_set
  when :disabled
    if switchport
      # Note: turn off switchport command, not switchport mode
      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 # case
end

#switchport_mode_lookup_stringObject



1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
# File 'lib/cisco_node_utils/interface.rb', line 1075

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_pvlan_hostObject


<state> switchport mode private-vlan host



1203
1204
1205
# File 'lib/cisco_node_utils/interface.rb', line 1203

def switchport_pvlan_host
  config_get('interface', 'switchport_pvlan_host', name: @name)
end

#switchport_pvlan_host=(state) ⇒ Object



1207
1208
1209
1210
1211
# File 'lib/cisco_node_utils/interface.rb', line 1207

def switchport_pvlan_host=(state)
  pvlan_enable
  config_set('interface', 'switchport_pvlan_host',
             name: @name, state: state ? '' : 'no')
end

#switchport_pvlan_host_associationObject


<state> switchport private-vlan host-association <pri> <sec> Note this is NOT a multiple, unlike trunk association.



1236
1237
1238
# File 'lib/cisco_node_utils/interface.rb', line 1236

def switchport_pvlan_host_association
  config_get('interface', 'switchport_pvlan_host_association', name: @name)
end

#switchport_pvlan_host_association=(pri_and_sec) ⇒ Object

Input: An array of primary and secondary vlans: [‘44’, ‘244’]



1241
1242
1243
1244
1245
1246
1247
1248
1249
# File 'lib/cisco_node_utils/interface.rb', line 1241

def switchport_pvlan_host_association=(pri_and_sec)
  pvlan_enable

  state = pri_and_sec.empty? ? 'no' : ''
  pri, sec = pri_and_sec
  cli_error_check(
    config_set('interface', 'switchport_pvlan_host_association',
               name: @name, state: state, pri: pri, sec: sec))
end

#switchport_pvlan_mappingObject


<state> switchport private-vlan mapping <primary> <vlan>



1257
1258
1259
# File 'lib/cisco_node_utils/interface.rb', line 1257

def switchport_pvlan_mapping
  config_get('interface', 'switchport_pvlan_mapping', name: @name)
end

#switchport_pvlan_mapping=(primary_and_range) ⇒ Object

Input: An array of primary vlan and range of vlans: [‘44’, ‘3-4,6’]



1262
1263
1264
# File 'lib/cisco_node_utils/interface.rb', line 1262

def switchport_pvlan_mapping=(primary_and_range)
  switchport_pvlan_mapping_delta(primary_and_range)
end

#switchport_pvlan_mapping_delta(primary_and_range) ⇒ Object


Find the is/should delta and add/remove commands as needed.

Inputs: primary_and_range: An array of primary vlan and range of vlans



1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
# File 'lib/cisco_node_utils/interface.rb', line 1275

def switchport_pvlan_mapping_delta(primary_and_range)
  # Enable switchport mode and feature private-vlan
  pvlan_enable
  primary, should_range = primary_and_range

  # primary changes require removing the entire command first
  is_range = switchport_pvlan_mapping_remove?(primary)

  # convert ranges to individual elements
  is = Utils.dash_range_to_elements(is_range)
  should = Utils.dash_range_to_elements(should_range)

  # create the delta hash and apply the changes
  delta_hash = Utils.delta_add_remove(should, is)
  Cisco::Logger.debug('switchport_pvlan_mapping_delta: '\
                      "#{primary}: #{delta_hash}")
  [:add, :remove].each do |action|
    delta_hash[action].each do |vlan|
      state = (action == :add) ? '' : 'no'
      cli_error_check(
        config_set('interface', 'switchport_pvlan_mapping',
                   name: @name, state: state, primary: primary, vlan: vlan))
    end
  end
end

#switchport_pvlan_mapping_remove?(should_primary) ⇒ Boolean


switchport_pvlan_mapping_remove? This is a helper to check if command needs to be removed entirely.

should_primary: the new primary vlan value

Returns: the current vlan range

Returns:

  • (Boolean)


1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
# File 'lib/cisco_node_utils/interface.rb', line 1307

def switchport_pvlan_mapping_remove?(should_primary)
  is_primary, is_range = switchport_pvlan_mapping

  if (is_primary != should_primary) && !is_primary.nil?
    cli_error_check(
      config_set('interface', 'switchport_pvlan_mapping',
                 name: @name, state: 'no', primary: '', vlan: ''))
    is_range = []
  end
  is_range
end

#switchport_pvlan_mapping_trunkObject


<state> switchport private-vlan mapping trunk <primary> <vlan>



1321
1322
1323
# File 'lib/cisco_node_utils/interface.rb', line 1321

def switchport_pvlan_mapping_trunk
  config_get('interface', 'switchport_pvlan_mapping_trunk', name: @name)
end

#switchport_pvlan_mapping_trunk=(should) ⇒ Object

Input: A nested array of primary vlan and range of vlans:

[‘44’, ‘3-4,6’], [‘99’, ‘199’]


1327
1328
1329
# File 'lib/cisco_node_utils/interface.rb', line 1327

def switchport_pvlan_mapping_trunk=(should)
  switchport_pvlan_mapping_trunk_delta(should)
end

#switchport_pvlan_mapping_trunk_delta(should) ⇒ Object


switchport_pvlan_mapping_trunk_delta(should)

Find the is/should delta and add/remove commands as needed. The ‘should’ value is a nested array of primary vlan and secondary ranges; e.g.:

[['44', '144-145'], ['99', '199-201']


1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
# File 'lib/cisco_node_utils/interface.rb', line 1343

def switchport_pvlan_mapping_trunk_delta(should)
  # Enable switchport mode and feature private-vlan
  pvlan_enable

  # Handle single-level arrays if found: [pri, range] -> [[pri,range]]
  should = [should] if !should.empty? && (Utils.depth(should) == 1)

  is = switchport_pvlan_mapping_trunk
  delta_hash = Utils.delta_add_remove(should, is, :updates_not_allowed)
  Cisco::Logger.debug("switchport_pvlan_mapping_trunk_delta: #{delta_hash}")
  [:remove, :add].each do |action|
    delta_hash[action].each do |pri_and_range|
      pri, range = pri_and_range
      if action == :add
        state = ''
      else
        state = 'no'
        range = ''
      end
      cli_error_check(
        config_set('interface', 'switchport_pvlan_mapping_trunk',
                   name: @name, state: state, primary: pri, range: range))
    end
  end
end

#switchport_pvlan_promiscuousObject


<state> switchport mode private-vlan promiscuous



1219
1220
1221
# File 'lib/cisco_node_utils/interface.rb', line 1219

def switchport_pvlan_promiscuous
  config_get('interface', 'switchport_pvlan_promiscuous', name: @name)
end

#switchport_pvlan_promiscuous=(state) ⇒ Object



1223
1224
1225
1226
1227
# File 'lib/cisco_node_utils/interface.rb', line 1223

def switchport_pvlan_promiscuous=(state)
  pvlan_enable
  config_set('interface', 'switchport_pvlan_promiscuous',
             name: @name, state: state ? '' : 'no')
end

#switchport_pvlan_trunk_allowed_vlanObject


<state> switchport private-vlan trunk allowed vlan <range> Note that range is handled as a string because the entire range is replaced instead of individually adding or removing vlans from the range.



1445
1446
1447
1448
1449
1450
1451
# File 'lib/cisco_node_utils/interface.rb', line 1445

def switchport_pvlan_trunk_allowed_vlan
  vlans = config_get('interface', 'switchport_pvlan_trunk_allowed_vlan',
                     name: @name)
  vlans = vlans.join(',') if vlans.is_a?(Array)
  vlans = Utils.normalize_range_array(vlans, :string) unless vlans == 'none'
  vlans
end

#switchport_pvlan_trunk_allowed_vlan=(range) ⇒ Object



1453
1454
1455
1456
1457
1458
1459
1460
1461
# File 'lib/cisco_node_utils/interface.rb', line 1453

def switchport_pvlan_trunk_allowed_vlan=(range)
  pvlan_enable

  range = Utils.normalize_range_array(range, :string) unless
    range == default_switchport_pvlan_trunk_allowed_vlan

  config_set('interface', 'switchport_pvlan_trunk_allowed_vlan',
             name: @name, range: range)
end

#switchport_pvlan_trunk_associationObject


<state> switchport private-vlan association trunk <pri> <sec> Supports multiple.



1372
1373
1374
# File 'lib/cisco_node_utils/interface.rb', line 1372

def switchport_pvlan_trunk_association
  config_get('interface', 'switchport_pvlan_trunk_association', name: @name)
end

#switchport_pvlan_trunk_association=(should) ⇒ Object

Input: A nested array of primary and secondary vlans:

[‘44’, ‘244’], [‘99’, ‘299’]


1378
1379
1380
1381
1382
1383
1384
1385
1386
# File 'lib/cisco_node_utils/interface.rb', line 1378

def switchport_pvlan_trunk_association=(should)
  pvlan_enable

  # Handle single-level arrays if found: [pri, sec] -> [[pri,sec]]
  should = [should] if !should.empty? && (Utils.depth(should) == 1)

  is = switchport_pvlan_trunk_association
  pvlan_trunk_association_delta(is, should)
end

#switchport_pvlan_trunk_native_vlanObject


<state> switchport trunk native vlan <vlan>



1469
1470
1471
# File 'lib/cisco_node_utils/interface.rb', line 1469

def switchport_pvlan_trunk_native_vlan
  config_get('interface', 'switchport_pvlan_trunk_native_vlan', name: @name)
end

#switchport_pvlan_trunk_native_vlan=(vlan) ⇒ Object



1473
1474
1475
1476
1477
# File 'lib/cisco_node_utils/interface.rb', line 1473

def switchport_pvlan_trunk_native_vlan=(vlan)
  pvlan_enable
  config_set('interface', 'switchport_pvlan_trunk_native_vlan',
             name: @name, vlan: vlan)
end

#switchport_pvlan_trunk_promiscuousObject


<state> switchport mode private-vlan trunk promiscuous



1411
1412
1413
# File 'lib/cisco_node_utils/interface.rb', line 1411

def switchport_pvlan_trunk_promiscuous
  config_get('interface', 'switchport_pvlan_trunk_promiscuous', name: @name)
end

#switchport_pvlan_trunk_promiscuous=(state) ⇒ Object



1415
1416
1417
1418
1419
# File 'lib/cisco_node_utils/interface.rb', line 1415

def switchport_pvlan_trunk_promiscuous=(state)
  pvlan_enable
  config_set('interface', 'switchport_pvlan_trunk_promiscuous',
             name: @name, state: state ? '' : 'no')
end

#switchport_pvlan_trunk_secondaryObject


<state> switchport mode private-vlan trunk secondary



1427
1428
1429
# File 'lib/cisco_node_utils/interface.rb', line 1427

def switchport_pvlan_trunk_secondary
  config_get('interface', 'switchport_pvlan_trunk_secondary', name: @name)
end

#switchport_pvlan_trunk_secondary=(state) ⇒ Object



1431
1432
1433
1434
1435
# File 'lib/cisco_node_utils/interface.rb', line 1431

def switchport_pvlan_trunk_secondary=(state)
  pvlan_enable
  config_set('interface', 'switchport_pvlan_trunk_secondary',
             name: @name, state: state ? '' : 'no')
end

#switchport_status?(status) ⇒ Boolean

Returns:

  • (Boolean)


1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
# File 'lib/cisco_node_utils/interface.rb', line 1693

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_vlanObject



1145
1146
1147
1148
1149
1150
1151
# File 'lib/cisco_node_utils/interface.rb', line 1145

def switchport_trunk_allowed_vlan
  vlans = config_get('interface', 'switchport_trunk_allowed_vlan',
                     name: @name)
  vlans = vlans.join(',') if vlans.is_a?(Array)
  vlans = Utils.normalize_range_array(vlans, :string) unless vlans == 'none'
  vlans
end

#switchport_trunk_allowed_vlan=(val) ⇒ Object



1153
1154
1155
1156
1157
1158
1159
1160
1161
# File 'lib/cisco_node_utils/interface.rb', line 1153

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_vlanObject



1167
1168
1169
# File 'lib/cisco_node_utils/interface.rb', line 1167

def switchport_trunk_native_vlan
  config_get('interface', 'switchport_trunk_native_vlan', name: @name)
end

#switchport_trunk_native_vlan=(val) ⇒ Object



1171
1172
1173
1174
1175
1176
1177
1178
1179
# File 'lib/cisco_node_utils/interface.rb', line 1171

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_vtpObject



1622
1623
1624
1625
# File 'lib/cisco_node_utils/interface.rb', line 1622

def switchport_vtp
  return nil unless switchport_vtp_mode_capable?
  config_get('interface', 'vtp', name: @name)
end

#switchport_vtp=(vtp_set) ⇒ Object



1627
1628
1629
1630
1631
1632
# File 'lib/cisco_node_utils/interface.rb', line 1627

def switchport_vtp=(vtp_set)
  # TODO: throw UnsupportedError instead of returning false?
  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

Returns:

  • (Boolean)


1689
1690
1691
# File 'lib/cisco_node_utils/interface.rb', line 1689

def switchport_vtp_feature?
  config_get('vtp', 'feature')
end

#switchport_vtp_mode_capable?Boolean

Returns:

  • (Boolean)


1618
1619
1620
# File 'lib/cisco_node_utils/interface.rb', line 1618

def switchport_vtp_mode_capable?
  !switchport_mode.to_s.match(/(access|trunk)/).nil?
end

#system_default_svi_autostateObject



1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
# File 'lib/cisco_node_utils/interface.rb', line 1603

def system_default_svi_autostate
  # This command is a user-configurable system default.
  #
  # This property behaves differently on an n7k vs ni(3|9)k and therefore
  # needs special handling.
  # N7K: When enabled, does not nvgen.
  #      When disabled, does nvgen, but differently then n(3|9)k.
  #      Return true for the disabled case, false otherwise.
  # N(3|9)K: When enabled, does nvgen.
  #          When disabled, does nvgen.
  #          Return true for the enabled case, false otherwise.
  result = config_get('interface', 'system_default_svi_autostate')
  /N7K/.match(node.product_id) ? !result : result
end

#system_default_switchportObject



1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
# File 'lib/cisco_node_utils/interface.rb', line 1585

def system_default_switchport
  # This command is a user-configurable system default.
  #
  # Note: This is a simple boolean state but there is a bug on some
  # platforms that causes the cli to nvgen twice; this causes config_get to
  # raise an error when it encounters the multiple. Therefore we define it
  # as a multiple to avoid the raise and handle the array if necessary.
  #
  val = config_get('interface', 'system_default_switchport')
  return (val[0][/^no /] ? false : true) if val.is_a?(Array)
  val
end

#system_default_switchport_shutdownObject



1598
1599
1600
1601
# File 'lib/cisco_node_utils/interface.rb', line 1598

def system_default_switchport_shutdown
  # This command is a user-configurable system default.
  config_get('interface', 'system_default_switchport_shutdown')
end

#to_sObject



66
67
68
# File 'lib/cisco_node_utils/interface.rb', line 66

def to_s
  "interface #{name}"
end

#vlan_mappingObject



1540
1541
1542
1543
1544
# File 'lib/cisco_node_utils/interface.rb', line 1540

def vlan_mapping
  match = config_get('interface', 'vlan_mapping', name: @name)
  match.each(&:compact!) unless match.nil?
  match
end

#vlan_mapping=(should_list) ⇒ Object



1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
# File 'lib/cisco_node_utils/interface.rb', line 1546

def vlan_mapping=(should_list)
  Feature.vni_enable

  # Process a hash of vlan_mapping cmds from delta_add_remove().
  # The vlan_mapping cli does not allow commands to be updated, they must
  # first be removed if there is a change.
  delta_hash = Utils.delta_add_remove(should_list, vlan_mapping,
                                      :updates_not_allowed)
  return if delta_hash.values.flatten.empty?
  # Process :remove first to ensure "update" commands will not fail.
  [: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_enableObject



1572
1573
1574
# File 'lib/cisco_node_utils/interface.rb', line 1572

def vlan_mapping_enable
  config_get('interface', 'vlan_mapping_enable', name: @name)
end

#vlan_mapping_enable=(state) ⇒ Object



1576
1577
1578
1579
# File 'lib/cisco_node_utils/interface.rb', line 1576

def vlan_mapping_enable=(state)
  config_set('interface', 'vlan_mapping_enable',
             name: @name, state: state ? '' : 'no')
end

#vpc_idObject



1712
1713
1714
# File 'lib/cisco_node_utils/interface.rb', line 1712

def vpc_id
  config_get('interface', 'vpc_id', name: @name)
end

#vpc_id=(num) ⇒ Object



1716
1717
1718
1719
1720
1721
1722
1723
1724
# File 'lib/cisco_node_utils/interface.rb', line 1716

def vpc_id=(num)
  if num
    config_set('interface', 'vpc_id', name: @name, state: '', id: num)
  else
    # 'no vpc' doesn't work for phy ports, so do a get
    num = vpc_id
    config_set('interface', 'vpc_id', name: @name, state: 'no', id: num)
  end
end


1730
1731
1732
# File 'lib/cisco_node_utils/interface.rb', line 1730

def vpc_peer_link
  config_get('interface', 'vpc_peer_link', name: @name)
end

#vpc_peer_link=(state) ⇒ Object



1734
1735
1736
1737
# File 'lib/cisco_node_utils/interface.rb', line 1734

def vpc_peer_link=(state)
  no_cmd = (state ? '' : 'no')
  config_set('interface', 'vpc_peer_link', name: @name, state: no_cmd)
end

#vrfObject



1743
1744
1745
# File 'lib/cisco_node_utils/interface.rb', line 1743

def vrf
  config_get('interface', 'vrf', name: @name)
end

#vrf=(v) ⇒ Object



1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
# File 'lib/cisco_node_utils/interface.rb', line 1747

def vrf=(v)
  fail TypeError unless v.is_a?(String)
  return if v == vrf
  # Changing the VRF can result in loss of IP address, so cache it
  addr_1 = ipv4_address
  mask_1 = ipv4_netmask_length
  addr_2 = ipv4_address_secondary
  mask_2 = ipv4_netmask_length_secondary
  # XR actually blocks you from changing the VRF if IP addr is present
  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