Class: Cisco::Interface
- 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)
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#show_name ⇒ Object
readonly
Returns the value of attribute show_name.
-
#state_default ⇒ Object
readonly
Returns the value of attribute state_default.
Class Method Summary collapse
-
.capabilities(intf, mode = :hash) ⇒ Object
‘capabilities’ is a getter-only helper for minitest and beaker.
-
.filter(filter, id, show_name) ⇒ Object
General-purpose filter for Interface.interfaces().
- .interface_count ⇒ Object
- .interfaces(opt = nil, show_name = nil) ⇒ Object
Instance Method Summary collapse
- #access_vlan ⇒ Object
- #access_vlan=(vlan) ⇒ Object
- #bfd_echo ⇒ Object
- #bfd_echo=(val) ⇒ Object
- #check_switchport(status) ⇒ Object
-
#cli_error_check(result) ⇒ Object
————————–.
- #create ⇒ Object
- #default? ⇒ Boolean
- #default_access_vlan ⇒ Object
- #default_bfd_echo ⇒ Object
- #default_description ⇒ Object
- #default_duplex ⇒ Object
- #default_encapsulation_dot1q ⇒ Object
- #default_fabric_forwarding_anycast_gateway ⇒ Object
- #default_hsrp_bfd ⇒ Object
- #default_hsrp_delay ⇒ Object
- #default_hsrp_delay_minimum ⇒ Object
- #default_hsrp_delay_reload ⇒ Object
- #default_hsrp_mac_refresh ⇒ Object
- #default_hsrp_use_bia ⇒ Object
- #default_hsrp_version ⇒ 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_dhcp_relay_addr ⇒ Object
- #default_ipv4_dhcp_relay_info_trust ⇒ Object
- #default_ipv4_dhcp_relay_src_addr_hsrp ⇒ Object
- #default_ipv4_dhcp_relay_src_intf ⇒ Object
- #default_ipv4_dhcp_relay_subnet_broadcast ⇒ Object
- #default_ipv4_dhcp_smart_relay ⇒ 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_ipv6_dhcp_relay_addr ⇒ Object
- #default_ipv6_dhcp_relay_src_intf ⇒ Object
- #default_ipv6_redirects ⇒ Object
- #default_lacp_rate ⇒ Object
- #default_load_interval_counter_1_delay ⇒ Object
- #default_load_interval_counter_2_delay ⇒ Object
- #default_load_interval_counter_3_delay ⇒ Object
- #default_mtu ⇒ Object
- #default_negotiate_auto ⇒ Object
- #default_pim_bfd ⇒ Object
- #default_pvlan_mapping ⇒ Object
- #default_shutdown ⇒ Object
- #default_speed ⇒ Object
- #default_storm_control_broadcast ⇒ Object
- #default_storm_control_multicast ⇒ Object
- #default_storm_control_unicast ⇒ 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_pvlan_host ⇒ Object
- #default_switchport_pvlan_host_association ⇒ Object
- #default_switchport_pvlan_mapping ⇒ Object
- #default_switchport_pvlan_mapping_trunk ⇒ Object
- #default_switchport_pvlan_promiscuous ⇒ Object
- #default_switchport_pvlan_trunk_allowed_vlan ⇒ Object
- #default_switchport_pvlan_trunk_association ⇒ Object
- #default_switchport_pvlan_trunk_native_vlan ⇒ Object
- #default_switchport_pvlan_trunk_promiscuous ⇒ Object
- #default_switchport_pvlan_trunk_secondary ⇒ 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 = true) ⇒ Object
- #hsrp_bfd ⇒ Object
- #hsrp_bfd=(val) ⇒ Object
-
#hsrp_delay ⇒ Object
hsrp delay minimum and reload are in the same CLI hsrp delay minimum 0 reload 0.
- #hsrp_delay_minimum ⇒ Object
-
#hsrp_delay_minimum=(val) ⇒ Object
hsrp delay minimum and reload are in the same CLI but both can be set independent of each other.
- #hsrp_delay_reload ⇒ Object
-
#hsrp_delay_reload=(val) ⇒ Object
hsrp delay minimum and reload are in the same CLI but both can be set independent of each other.
- #hsrp_mac_refresh ⇒ Object
- #hsrp_mac_refresh=(val) ⇒ Object
- #hsrp_use_bia ⇒ Object
- #hsrp_use_bia=(val) ⇒ Object
- #hsrp_version ⇒ Object
- #hsrp_version=(val) ⇒ Object
-
#initialize(name, instantiate = true, default_state = false, show_name = nil) ⇒ Interface
constructor
A new instance of Interface.
- #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_dhcp_relay_addr ⇒ Object
- #ipv4_dhcp_relay_addr=(list) ⇒ Object
- #ipv4_dhcp_relay_info_trust ⇒ Object
- #ipv4_dhcp_relay_info_trust=(state) ⇒ Object
- #ipv4_dhcp_relay_src_addr_hsrp ⇒ Object
- #ipv4_dhcp_relay_src_addr_hsrp=(state) ⇒ Object
- #ipv4_dhcp_relay_src_intf ⇒ Object
- #ipv4_dhcp_relay_src_intf=(val) ⇒ Object
- #ipv4_dhcp_relay_subnet_broadcast ⇒ Object
- #ipv4_dhcp_relay_subnet_broadcast=(state) ⇒ Object
- #ipv4_dhcp_smart_relay ⇒ Object
- #ipv4_dhcp_smart_relay=(state) ⇒ 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
- #ipv6_dhcp_relay_addr ⇒ Object
- #ipv6_dhcp_relay_addr=(list) ⇒ Object
- #ipv6_dhcp_relay_src_intf ⇒ Object
- #ipv6_dhcp_relay_src_intf=(val) ⇒ Object
- #ipv6_redirects ⇒ Object
- #ipv6_redirects=(redirects) ⇒ Object
- #lacp_rate ⇒ Object
- #lacp_rate=(val) ⇒ Object
-
#lacp_rate_shut_needed? ⇒ Boolean
For range based attributes, a new attribute purge will be added in future.
- #load_interval_counter_1_delay ⇒ Object
- #load_interval_counter_1_delay=(val) ⇒ Object
- #load_interval_counter_2_delay ⇒ Object
- #load_interval_counter_2_delay=(val) ⇒ Object
- #load_interval_counter_3_delay ⇒ Object
- #load_interval_counter_3_delay=(val) ⇒ Object
- #mtu ⇒ Object
- #mtu=(val) ⇒ Object
- #mtu_lookup_string ⇒ Object
- #negotiate_auto ⇒ Object
- #negotiate_auto=(negotiate_auto) ⇒ Object
- #negotiate_auto_lookup_string ⇒ Object
- #pim_bfd ⇒ Object
- #pim_bfd=(val) ⇒ Object
- #pvlan_enable ⇒ Object
-
#pvlan_mapping ⇒ Object
————————– This is an SVI property.
- #pvlan_mapping=(range) ⇒ Object
- #pvlan_mapping_delta(is, should) ⇒ Object
- #pvlan_trunk_association_delta(is, should) ⇒ Object
- #select_ipv4_attribute(attribute) ⇒ Object
- #set_range_based_params(list, param_name) ⇒ Object
- #shutdown ⇒ Object
- #shutdown=(state) ⇒ Object
- #speed ⇒ Object
- #speed=(val) ⇒ Object
- #storm_control_broadcast ⇒ Object
- #storm_control_broadcast=(val) ⇒ Object
- #storm_control_multicast ⇒ Object
- #storm_control_multicast=(val) ⇒ Object
- #storm_control_unicast ⇒ Object
- #storm_control_unicast=(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_mode ⇒ Object
- #switchport_mode=(mode_set) ⇒ Object
- #switchport_mode_lookup_string ⇒ Object
-
#switchport_pvlan_host ⇒ Object
————————– <state> switchport mode private-vlan host.
- #switchport_pvlan_host=(state) ⇒ Object
-
#switchport_pvlan_host_association ⇒ Object
————————– <state> switchport private-vlan host-association <pri> <sec> Note this is NOT a multiple, unlike trunk association.
-
#switchport_pvlan_host_association=(pri_and_sec) ⇒ Object
Input: An array of primary and secondary vlans: [‘44’, ‘244’].
-
#switchport_pvlan_mapping ⇒ Object
————————– <state> switchport private-vlan mapping <primary> <vlan>.
-
#switchport_pvlan_mapping=(primary_and_range) ⇒ Object
Input: An array of primary vlan and range of vlans: [‘44’, ‘3-4,6’].
-
#switchport_pvlan_mapping_delta(primary_and_range) ⇒ Object
————————– Find the is/should delta and add/remove commands as needed.
-
#switchport_pvlan_mapping_remove?(should_primary) ⇒ Boolean
————————– switchport_pvlan_mapping_remove? This is a helper to check if command needs to be removed entirely.
-
#switchport_pvlan_mapping_trunk ⇒ Object
————————– <state> switchport private-vlan mapping trunk <primary> <vlan>.
-
#switchport_pvlan_mapping_trunk=(should) ⇒ Object
Input: A nested array of primary vlan and range of vlans: [[‘44’, ‘3-4,6’], [‘99’, ‘199’]].
-
#switchport_pvlan_mapping_trunk_delta(should) ⇒ Object
————————– switchport_pvlan_mapping_trunk_delta(should).
-
#switchport_pvlan_promiscuous ⇒ Object
————————– <state> switchport mode private-vlan promiscuous.
- #switchport_pvlan_promiscuous=(state) ⇒ Object
-
#switchport_pvlan_trunk_allowed_vlan ⇒ Object
————————– <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.
- #switchport_pvlan_trunk_allowed_vlan=(range) ⇒ Object
-
#switchport_pvlan_trunk_association ⇒ Object
————————– <state> switchport private-vlan association trunk <pri> <sec> Supports multiple.
-
#switchport_pvlan_trunk_association=(should) ⇒ Object
Input: A nested array of primary and secondary vlans: [[‘44’, ‘244’], [‘99’, ‘299’]].
-
#switchport_pvlan_trunk_native_vlan ⇒ Object
————————– <state> switchport trunk native vlan <vlan>.
- #switchport_pvlan_trunk_native_vlan=(vlan) ⇒ Object
-
#switchport_pvlan_trunk_promiscuous ⇒ Object
————————– <state> switchport mode private-vlan trunk promiscuous.
- #switchport_pvlan_trunk_promiscuous=(state) ⇒ Object
-
#switchport_pvlan_trunk_secondary ⇒ Object
————————– <state> switchport mode private-vlan trunk secondary.
- #switchport_pvlan_trunk_secondary=(state) ⇒ 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, default_state = false, show_name = nil) ⇒ Interface
Returns a new instance of Interface.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cisco_node_utils/interface.rb', line 47 def initialize(name, instantiate=true, default_state=false, show_name=nil) fail TypeError unless name.is_a?(String) fail ArgumentError unless name.length > 0 # @name is used for context: keys only # @show_name is used for get_command: keys; allows callers to limit # show command to a single interface @name = name.downcase @show_name = show_name.nil? ? '' : Utils.normalize_intf_pattern(show_name) @get_args = { name: @name, show_name: @show_name } @smr = config_get('interface', 'stp_mst_range') @svr = config_get('interface', 'stp_vlan_range') @match_found = false # Keep track of default vs non-default state for # interfaces that cannot be created/destroyed. @state_default = nil # Track ethernet but not sub-interfaces if @name[/ethernet/] && !@name[/ethernet.*\.\d+/] @state_default = default_state end create if instantiate end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
45 46 47 |
# File 'lib/cisco_node_utils/interface.rb', line 45 def name @name end |
#show_name ⇒ Object (readonly)
Returns the value of attribute show_name.
45 46 47 |
# File 'lib/cisco_node_utils/interface.rb', line 45 def show_name @show_name end |
#state_default ⇒ Object (readonly)
Returns the value of attribute state_default.
45 46 47 |
# File 'lib/cisco_node_utils/interface.rb', line 45 def state_default @state_default 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”
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/cisco_node_utils/interface.rb', line 148 def self.capabilities(intf, mode=:hash) array = [] begin array = config_get('interface', 'capabilities', name: intf) rescue CliError => e raise unless e.clierror[/(Invalid command|Cmd exec error)/] end 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, show_name) ⇒ 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
show_name: needed for get_command: <show_name> Return: true if the interface should be filtered out, false to keep it.
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/cisco_node_utils/interface.rb', line 120 def self.filter(filter, id, show_name) case filter when :pvlan_any return false if config_get('interface', 'pvlan_any', name: id, show_name: show_name) else # Just a basic pattern filter (:ethernet, :loopback, etc) return false if id.match(filter.to_s) end true end |
.interface_count ⇒ Object
74 75 76 |
# File 'lib/cisco_node_utils/interface.rb', line 74 def self.interface_count config_get('interface', 'all_count').to_i end |
.interfaces(opt = nil, show_name = nil) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/cisco_node_utils/interface.rb', line 78 def self.interfaces(opt=nil, show_name=nil) hash = {} show_name = Utils.normalize_intf_pattern(show_name) begin intf_list = config_get('interface', 'all_interfaces', show_name: show_name) rescue CliError => e raise unless show_name # ignore logical interfaces that do not exist debug 'Interface.interfaces ignoring CliError => ' + e.to_s end return hash if intf_list.nil? # Massage intf_list data into an array that is easy to work with. # Use a MARKER to hide pesky 'interface' substrings intf_list.collect! { |x| x.strip || x } intf_list.delete('') intf_list.collect! { |x| (x.sub('interface', '~!MARKER!~') unless x[/^interface /]) || x } # rubocop:disable Metrics/LineLength intf_list = intf_list.join(' ').split('interface') intf_list.delete('') # Restore 'interface' substrings intf_list.collect! { |x| x.sub('~!MARKER!~', 'interface') } intf_list.each do |id| int_data = id.strip.split(' ') next if int_data[0].nil? id = int_data[0].downcase next if opt && filter(opt, id, show_name) # If there are any additional options associated # with this interface then it's in a non-default # state. default_state = int_data.size > 1 ? false : true hash[id] = Interface.new(id, false, default_state, show_name) end hash end |
Instance Method Details
#access_vlan ⇒ Object
241 242 243 244 |
# File 'lib/cisco_node_utils/interface.rb', line 241 def access_vlan return nil if switchport_mode == :disabled config_get('interface', 'access_vlan', @get_args) end |
#access_vlan=(vlan) ⇒ Object
246 247 248 |
# File 'lib/cisco_node_utils/interface.rb', line 246 def access_vlan=(vlan) config_set('interface', 'access_vlan', name: @name, vlan: vlan) end |
#bfd_echo ⇒ Object
254 255 256 257 258 |
# File 'lib/cisco_node_utils/interface.rb', line 254 def bfd_echo return nil unless Feature.bfd_enabled? return nil if @name[/loop/i] config_get('interface', 'bfd_echo', @get_args) end |
#bfd_echo=(val) ⇒ Object
260 261 262 263 264 265 266 267 268 |
# File 'lib/cisco_node_utils/interface.rb', line 260 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
2044 2045 2046 2047 2048 |
# File 'lib/cisco_node_utils/interface.rb', line 2044 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
1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 |
# File 'lib/cisco_node_utils/interface.rb', line 1512 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 |
#create ⇒ Object
171 172 173 174 175 176 177 178 179 180 |
# File 'lib/cisco_node_utils/interface.rb', line 171 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? ⇒ Boolean
190 191 192 193 |
# File 'lib/cisco_node_utils/interface.rb', line 190 def default? state = config_get('interface', 'default', @get_args) state.nil? ? true : false end |
#default_access_vlan ⇒ Object
250 251 252 |
# File 'lib/cisco_node_utils/interface.rb', line 250 def default_access_vlan config_get_default('interface', 'access_vlan') end |
#default_bfd_echo ⇒ Object
270 271 272 273 274 |
# File 'lib/cisco_node_utils/interface.rb', line 270 def default_bfd_echo return nil unless Feature.bfd_enabled? return nil if @name[/loop/i] config_get_default('interface', 'bfd_echo') end |
#default_description ⇒ Object
291 292 293 |
# File 'lib/cisco_node_utils/interface.rb', line 291 def default_description config_get_default('interface', 'description') end |
#default_duplex ⇒ Object
1022 1023 1024 |
# File 'lib/cisco_node_utils/interface.rb', line 1022 def default_duplex config_get_default('interface', 'duplex') end |
#default_encapsulation_dot1q ⇒ Object
309 310 311 |
# File 'lib/cisco_node_utils/interface.rb', line 309 def default_encapsulation_dot1q config_get_default('interface', 'encapsulation_dot1q') end |
#default_fabric_forwarding_anycast_gateway ⇒ Object
343 344 345 |
# File 'lib/cisco_node_utils/interface.rb', line 343 def default_fabric_forwarding_anycast_gateway config_get_default('interface', 'fabric_forwarding_anycast_gateway') end |
#default_hsrp_bfd ⇒ Object
361 362 363 |
# File 'lib/cisco_node_utils/interface.rb', line 361 def default_hsrp_bfd config_get_default('interface', 'hsrp_bfd') end |
#default_hsrp_delay ⇒ Object
372 373 374 |
# File 'lib/cisco_node_utils/interface.rb', line 372 def default_hsrp_delay [default_hsrp_delay_minimum, default_hsrp_delay_reload] end |
#default_hsrp_delay_minimum ⇒ Object
390 391 392 |
# File 'lib/cisco_node_utils/interface.rb', line 390 def default_hsrp_delay_minimum config_get_default('interface', 'hsrp_delay_minimum') end |
#default_hsrp_delay_reload ⇒ Object
408 409 410 |
# File 'lib/cisco_node_utils/interface.rb', line 408 def default_hsrp_delay_reload config_get_default('interface', 'hsrp_delay_reload') end |
#default_hsrp_mac_refresh ⇒ Object
424 425 426 |
# File 'lib/cisco_node_utils/interface.rb', line 424 def default_hsrp_mac_refresh config_get_default('interface', 'hsrp_mac_refresh') end |
#default_hsrp_use_bia ⇒ Object
462 463 464 |
# File 'lib/cisco_node_utils/interface.rb', line 462 def default_hsrp_use_bia config_get_default('interface', 'hsrp_use_bia') end |
#default_hsrp_version ⇒ Object
476 477 478 |
# File 'lib/cisco_node_utils/interface.rb', line 476 def default_hsrp_version config_get_default('interface', 'hsrp_version') end |
#default_ipv4_acl_in ⇒ Object
497 498 499 |
# File 'lib/cisco_node_utils/interface.rb', line 497 def default_ipv4_acl_in config_get_default('interface', 'ipv4_acl_in') end |
#default_ipv4_acl_out ⇒ Object
518 519 520 |
# File 'lib/cisco_node_utils/interface.rb', line 518 def default_ipv4_acl_out config_get_default('interface', 'ipv4_acl_out') end |
#default_ipv4_address ⇒ Object
593 594 595 |
# File 'lib/cisco_node_utils/interface.rb', line 593 def default_ipv4_address config_get_default('interface', 'ipv4_address') end |
#default_ipv4_address_secondary ⇒ Object
597 598 599 |
# File 'lib/cisco_node_utils/interface.rb', line 597 def default_ipv4_address_secondary default_ipv4_address end |
#default_ipv4_arp_timeout ⇒ Object
630 631 632 |
# File 'lib/cisco_node_utils/interface.rb', line 630 def default_ipv4_arp_timeout config_get_default('interface', ipv4_arp_timeout_lookup_string) end |
#default_ipv4_dhcp_relay_addr ⇒ Object
654 655 656 |
# File 'lib/cisco_node_utils/interface.rb', line 654 def default_ipv4_dhcp_relay_addr config_get_default('interface', 'ipv4_dhcp_relay_addr') end |
#default_ipv4_dhcp_relay_info_trust ⇒ Object
670 671 672 |
# File 'lib/cisco_node_utils/interface.rb', line 670 def default_ipv4_dhcp_relay_info_trust config_get_default('interface', 'ipv4_dhcp_relay_info_trust') end |
#default_ipv4_dhcp_relay_src_addr_hsrp ⇒ Object
685 686 687 |
# File 'lib/cisco_node_utils/interface.rb', line 685 def default_ipv4_dhcp_relay_src_addr_hsrp config_get_default('interface', 'ipv4_dhcp_relay_src_addr_hsrp') end |
#default_ipv4_dhcp_relay_src_intf ⇒ Object
705 706 707 |
# File 'lib/cisco_node_utils/interface.rb', line 705 def default_ipv4_dhcp_relay_src_intf config_get_default('interface', 'ipv4_dhcp_relay_src_intf') end |
#default_ipv4_dhcp_relay_subnet_broadcast ⇒ Object
721 722 723 |
# File 'lib/cisco_node_utils/interface.rb', line 721 def default_ipv4_dhcp_relay_subnet_broadcast config_get_default('interface', 'ipv4_dhcp_relay_subnet_broadcast') end |
#default_ipv4_dhcp_smart_relay ⇒ Object
737 738 739 |
# File 'lib/cisco_node_utils/interface.rb', line 737 def default_ipv4_dhcp_smart_relay config_get_default('interface', 'ipv4_dhcp_smart_relay') end |
#default_ipv4_forwarding ⇒ Object
751 752 753 |
# File 'lib/cisco_node_utils/interface.rb', line 751 def default_ipv4_forwarding config_get_default('interface', 'ipv4_forwarding') end |
#default_ipv4_netmask_length ⇒ Object
601 602 603 |
# File 'lib/cisco_node_utils/interface.rb', line 601 def default_ipv4_netmask_length config_get_default('interface', 'ipv4_netmask_length') end |
#default_ipv4_netmask_length_secondary ⇒ Object
605 606 607 |
# File 'lib/cisco_node_utils/interface.rb', line 605 def default_ipv4_netmask_length_secondary default_ipv4_netmask_length end |
#default_ipv4_pim_sparse_mode ⇒ Object
767 768 769 |
# File 'lib/cisco_node_utils/interface.rb', line 767 def default_ipv4_pim_sparse_mode config_get_default('interface', 'ipv4_pim_sparse_mode') end |
#default_ipv4_proxy_arp ⇒ Object
782 783 784 |
# File 'lib/cisco_node_utils/interface.rb', line 782 def default_ipv4_proxy_arp config_get_default('interface', 'ipv4_proxy_arp') end |
#default_ipv4_redirects ⇒ Object
807 808 809 |
# File 'lib/cisco_node_utils/interface.rb', line 807 def default_ipv4_redirects config_get_default('interface', ipv4_redirects_lookup_string) end |
#default_ipv6_acl_in ⇒ Object
827 828 829 |
# File 'lib/cisco_node_utils/interface.rb', line 827 def default_ipv6_acl_in config_get_default('interface', 'ipv6_acl_in') end |
#default_ipv6_acl_out ⇒ Object
847 848 849 |
# File 'lib/cisco_node_utils/interface.rb', line 847 def default_ipv6_acl_out config_get_default('interface', 'ipv6_acl_out') end |
#default_ipv6_dhcp_relay_addr ⇒ Object
871 872 873 |
# File 'lib/cisco_node_utils/interface.rb', line 871 def default_ipv6_dhcp_relay_addr config_get_default('interface', 'ipv6_dhcp_relay_addr') end |
#default_ipv6_dhcp_relay_src_intf ⇒ Object
891 892 893 |
# File 'lib/cisco_node_utils/interface.rb', line 891 def default_ipv6_dhcp_relay_src_intf config_get_default('interface', 'ipv6_dhcp_relay_src_intf') end |
#default_ipv6_redirects ⇒ Object
907 908 909 |
# File 'lib/cisco_node_utils/interface.rb', line 907 def default_ipv6_redirects config_get_default('interface', 'ipv6_redirects') end |
#default_lacp_rate ⇒ Object
237 238 239 |
# File 'lib/cisco_node_utils/interface.rb', line 237 def default_lacp_rate config_get_default('interface', 'lacp_rate') end |
#default_load_interval_counter_1_delay ⇒ Object
932 933 934 935 936 937 938 939 940 |
# File 'lib/cisco_node_utils/interface.rb', line 932 def default_load_interval_counter_1_delay # for vlan and bdi the default is 60 if @name[/(vlan|bdi)/i] config_get_default('interface', 'load_interval_counter_1_delay_vlan_bdi') else config_get_default('interface', 'load_interval_counter_1_delay') end end |
#default_load_interval_counter_2_delay ⇒ Object
954 955 956 |
# File 'lib/cisco_node_utils/interface.rb', line 954 def default_load_interval_counter_2_delay config_get_default('interface', 'load_interval_counter_2_delay') end |
#default_load_interval_counter_3_delay ⇒ Object
972 973 974 |
# File 'lib/cisco_node_utils/interface.rb', line 972 def default_load_interval_counter_3_delay config_get_default('interface', 'load_interval_counter_3_delay') end |
#default_mtu ⇒ Object
996 997 998 |
# File 'lib/cisco_node_utils/interface.rb', line 996 def default_mtu config_get_default('interface', mtu_lookup_string) end |
#default_negotiate_auto ⇒ Object
1048 1049 1050 |
# File 'lib/cisco_node_utils/interface.rb', line 1048 def default_negotiate_auto config_get_default('interface', negotiate_auto_lookup_string) end |
#default_pim_bfd ⇒ Object
1108 1109 1110 |
# File 'lib/cisco_node_utils/interface.rb', line 1108 def default_pim_bfd config_get_default('interface', 'pim_bfd') end |
#default_pvlan_mapping ⇒ Object
1852 1853 1854 |
# File 'lib/cisco_node_utils/interface.rb', line 1852 def default_pvlan_mapping config_get_default('interface', 'pvlan_mapping') end |
#default_shutdown ⇒ Object
1061 1062 1063 1064 1065 1066 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 |
# File 'lib/cisco_node_utils/interface.rb', line 1061 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
1009 1010 1011 |
# File 'lib/cisco_node_utils/interface.rb', line 1009 def default_speed config_get_default('interface', 'speed') end |
#default_storm_control_broadcast ⇒ Object
1125 1126 1127 |
# File 'lib/cisco_node_utils/interface.rb', line 1125 def default_storm_control_broadcast config_get_default('interface', 'storm_control_broadcast') end |
#default_storm_control_multicast ⇒ Object
1142 1143 1144 |
# File 'lib/cisco_node_utils/interface.rb', line 1142 def default_storm_control_multicast config_get_default('interface', 'storm_control_multicast') end |
#default_storm_control_unicast ⇒ Object
1159 1160 1161 |
# File 'lib/cisco_node_utils/interface.rb', line 1159 def default_storm_control_unicast config_get_default('interface', 'storm_control_unicast') end |
#default_stp_bpdufilter ⇒ Object
1179 1180 1181 |
# File 'lib/cisco_node_utils/interface.rb', line 1179 def default_stp_bpdufilter config_get_default('interface', 'stp_bpdufilter') end |
#default_stp_bpduguard ⇒ Object
1198 1199 1200 |
# File 'lib/cisco_node_utils/interface.rb', line 1198 def default_stp_bpduguard config_get_default('interface', 'stp_bpduguard') end |
#default_stp_cost ⇒ Object
1213 1214 1215 |
# File 'lib/cisco_node_utils/interface.rb', line 1213 def default_stp_cost config_get_default('interface', 'stp_cost') end |
#default_stp_guard ⇒ Object
1233 1234 1235 |
# File 'lib/cisco_node_utils/interface.rb', line 1233 def default_stp_guard config_get_default('interface', 'stp_guard') end |
#default_stp_link_type ⇒ Object
1247 1248 1249 |
# File 'lib/cisco_node_utils/interface.rb', line 1247 def default_stp_link_type config_get_default('interface', 'stp_link_type') end |
#default_stp_mst_cost ⇒ Object
1283 1284 1285 |
# File 'lib/cisco_node_utils/interface.rb', line 1283 def default_stp_mst_cost config_get_default('interface', 'stp_mst_cost') end |
#default_stp_mst_port_priority ⇒ Object
1305 1306 1307 |
# File 'lib/cisco_node_utils/interface.rb', line 1305 def default_stp_mst_port_priority config_get_default('interface', 'stp_mst_port_priority') end |
#default_stp_port_priority ⇒ Object
1261 1262 1263 |
# File 'lib/cisco_node_utils/interface.rb', line 1261 def default_stp_port_priority config_get_default('interface', 'stp_port_priority') end |
#default_stp_port_type ⇒ Object
1325 1326 1327 |
# File 'lib/cisco_node_utils/interface.rb', line 1325 def default_stp_port_type config_get_default('interface', 'stp_port_type') end |
#default_stp_vlan_cost ⇒ Object
1347 1348 1349 |
# File 'lib/cisco_node_utils/interface.rb', line 1347 def default_stp_vlan_cost config_get_default('interface', 'stp_vlan_cost') end |
#default_stp_vlan_port_priority ⇒ Object
1369 1370 1371 |
# File 'lib/cisco_node_utils/interface.rb', line 1369 def default_stp_vlan_port_priority config_get_default('interface', 'stp_vlan_port_priority') end |
#default_svi_autostate ⇒ Object
1990 1991 1992 |
# File 'lib/cisco_node_utils/interface.rb', line 1990 def default_svi_autostate system_default_svi_autostate end |
#default_svi_management ⇒ Object
2018 2019 2020 |
# File 'lib/cisco_node_utils/interface.rb', line 2018 def default_svi_management config_get_default('interface', 'svi_management') end |
#default_switchport_autostate_exclude ⇒ Object
1399 1400 1401 |
# File 'lib/cisco_node_utils/interface.rb', line 1399 def default_switchport_autostate_exclude config_get_default('interface', 'switchport_autostate_exclude') end |
#default_switchport_mode ⇒ Object
1466 1467 1468 1469 1470 1471 |
# File 'lib/cisco_node_utils/interface.rb', line 1466 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_host ⇒ Object
1544 1545 1546 |
# File 'lib/cisco_node_utils/interface.rb', line 1544 def default_switchport_pvlan_host config_get_default('interface', 'switchport_pvlan_host') end |
#default_switchport_pvlan_host_association ⇒ Object
1583 1584 1585 |
# File 'lib/cisco_node_utils/interface.rb', line 1583 def default_switchport_pvlan_host_association config_get_default('interface', 'switchport_pvlan_host_association') end |
#default_switchport_pvlan_mapping ⇒ Object
1598 1599 1600 |
# File 'lib/cisco_node_utils/interface.rb', line 1598 def default_switchport_pvlan_mapping config_get_default('interface', 'switchport_pvlan_mapping') end |
#default_switchport_pvlan_mapping_trunk ⇒ Object
1663 1664 1665 |
# File 'lib/cisco_node_utils/interface.rb', line 1663 def default_switchport_pvlan_mapping_trunk config_get_default('interface', 'switchport_pvlan_mapping_trunk') end |
#default_switchport_pvlan_promiscuous ⇒ Object
1561 1562 1563 |
# File 'lib/cisco_node_utils/interface.rb', line 1561 def default_switchport_pvlan_promiscuous config_get_default('interface', 'switchport_pvlan_promiscuous') end |
#default_switchport_pvlan_trunk_allowed_vlan ⇒ Object
1798 1799 1800 |
# File 'lib/cisco_node_utils/interface.rb', line 1798 def default_switchport_pvlan_trunk_allowed_vlan config_get_default('interface', 'switchport_pvlan_trunk_allowed_vlan') end |
#default_switchport_pvlan_trunk_association ⇒ Object
1737 1738 1739 |
# File 'lib/cisco_node_utils/interface.rb', line 1737 def default_switchport_pvlan_trunk_association config_get_default('interface', 'switchport_pvlan_trunk_association') end |
#default_switchport_pvlan_trunk_native_vlan ⇒ Object
1815 1816 1817 |
# File 'lib/cisco_node_utils/interface.rb', line 1815 def default_switchport_pvlan_trunk_native_vlan config_get_default('interface', 'switchport_pvlan_trunk_native_vlan') end |
#default_switchport_pvlan_trunk_promiscuous ⇒ Object
1754 1755 1756 |
# File 'lib/cisco_node_utils/interface.rb', line 1754 def default_switchport_pvlan_trunk_promiscuous config_get_default('interface', 'switchport_pvlan_trunk_promiscuous') end |
#default_switchport_pvlan_trunk_secondary ⇒ Object
1771 1772 1773 |
# File 'lib/cisco_node_utils/interface.rb', line 1771 def default_switchport_pvlan_trunk_secondary config_get_default('interface', 'switchport_pvlan_trunk_secondary') end |
#default_switchport_trunk_allowed_vlan ⇒ Object
1492 1493 1494 |
# File 'lib/cisco_node_utils/interface.rb', line 1492 def default_switchport_trunk_allowed_vlan config_get_default('interface', 'switchport_trunk_allowed_vlan') end |
#default_switchport_trunk_native_vlan ⇒ Object
1917 1918 1919 |
# File 'lib/cisco_node_utils/interface.rb', line 1917 def default_switchport_trunk_native_vlan config_get_default('interface', 'switchport_trunk_native_vlan') end |
#default_switchport_vtp ⇒ Object
2022 2023 2024 2025 |
# File 'lib/cisco_node_utils/interface.rb', line 2022 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’]]
1872 1873 1874 |
# File 'lib/cisco_node_utils/interface.rb', line 1872 def default_vlan_mapping config_get_default('interface', 'vlan_mapping') end |
#default_vlan_mapping_enable ⇒ Object
cli: switchport vlan mapping enable
1904 1905 1906 |
# File 'lib/cisco_node_utils/interface.rb', line 1904 def default_vlan_mapping_enable config_get_default('interface', 'vlan_mapping_enable') end |
#default_vpc_id ⇒ Object
2064 2065 2066 |
# File 'lib/cisco_node_utils/interface.rb', line 2064 def default_vpc_id config_get_default('interface', 'vpc_id') end |
#default_vpc_peer_link ⇒ Object
2079 2080 2081 |
# File 'lib/cisco_node_utils/interface.rb', line 2079 def default_vpc_peer_link config_get_default('interface', 'vpc_peer_link') end |
#default_vrf ⇒ Object
2109 2110 2111 |
# File 'lib/cisco_node_utils/interface.rb', line 2109 def default_vrf config_get_default('interface', 'vrf') end |
#description ⇒ Object
276 277 278 |
# File 'lib/cisco_node_utils/interface.rb', line 276 def description config_get('interface', 'description', @get_args) end |
#description=(desc) ⇒ Object
280 281 282 283 284 285 286 287 288 289 |
# File 'lib/cisco_node_utils/interface.rb', line 280 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
182 183 184 185 186 187 188 |
# File 'lib/cisco_node_utils/interface.rb', line 182 def destroy if @name[/ethernet/] && !@name[/ethernet.*\.\d+/] config_set('interface', 'default', name: @name) else config_set('interface', 'destroy', name: @name) end end |
#duplex ⇒ Object
1013 1014 1015 1016 |
# File 'lib/cisco_node_utils/interface.rb', line 1013 def duplex return nil if @name[/loop|vlan/i] config_get('interface', 'duplex', @get_args) end |
#duplex=(val) ⇒ Object
1018 1019 1020 |
# File 'lib/cisco_node_utils/interface.rb', line 1018 def duplex=(val) config_set('interface', 'duplex', name: @name, duplex: val) end |
#encapsulation_dot1q ⇒ Object
295 296 297 |
# File 'lib/cisco_node_utils/interface.rb', line 295 def encapsulation_dot1q config_get('interface', 'encapsulation_dot1q', @get_args) end |
#encapsulation_dot1q=(val) ⇒ Object
299 300 301 302 303 304 305 306 307 |
# File 'lib/cisco_node_utils/interface.rb', line 299 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
321 322 323 |
# File 'lib/cisco_node_utils/interface.rb', line 321 def fabric_forwarding_anycast_gateway config_get('interface', 'fabric_forwarding_anycast_gateway', @get_args) end |
#fabric_forwarding_anycast_gateway=(state) ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/cisco_node_utils/interface.rb', line 325 def fabric_forwarding_anycast_gateway=(state) return if 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
313 314 315 |
# File 'lib/cisco_node_utils/interface.rb', line 313 def fabricpath_feature FabricpathGlobal.fabricpath_feature end |
#fabricpath_feature_set(fabricpath_set) ⇒ Object
317 318 319 |
# File 'lib/cisco_node_utils/interface.rb', line 317 def fabricpath_feature_set(fabricpath_set) FabricpathGlobal.fabricpath_feature_set(fabricpath_set) end |
#feature_lacp? ⇒ Boolean
911 912 913 |
# File 'lib/cisco_node_utils/interface.rb', line 911 def feature_lacp? config_get('interface', 'feature_lacp') end |
#feature_lacp_set(val) ⇒ Object
915 916 917 918 |
# File 'lib/cisco_node_utils/interface.rb', line 915 def feature_lacp_set(val) return if feature_lacp? == val config_set('interface', 'feature_lacp', state: val ? '' : 'no') end |
#feature_vlan? ⇒ Boolean
1994 1995 1996 |
# File 'lib/cisco_node_utils/interface.rb', line 1994 def feature_vlan? config_get('interface', 'feature_vlan') end |
#feature_vlan_set(val = true) ⇒ Object
1998 1999 2000 2001 2002 2003 |
# File 'lib/cisco_node_utils/interface.rb', line 1998 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 |
#hsrp_bfd ⇒ Object
347 348 349 |
# File 'lib/cisco_node_utils/interface.rb', line 347 def hsrp_bfd config_get('interface', 'hsrp_bfd', @get_args) end |
#hsrp_bfd=(val) ⇒ Object
351 352 353 354 355 356 357 358 359 |
# File 'lib/cisco_node_utils/interface.rb', line 351 def hsrp_bfd=(val) return if val == hsrp_bfd state = val ? '' : 'no' if val Feature.hsrp_enable Feature.bfd_enable end config_set('interface', 'hsrp_bfd', name: @name, state: state) end |
#hsrp_delay ⇒ Object
hsrp delay minimum and reload are in the same CLI hsrp delay minimum 0 reload 0
367 368 369 370 |
# File 'lib/cisco_node_utils/interface.rb', line 367 def hsrp_delay match = config_get('interface', 'hsrp_delay', @get_args) match.nil? ? default_hsrp_delay : match.collect(&:to_i) end |
#hsrp_delay_minimum ⇒ Object
376 377 378 379 380 |
# File 'lib/cisco_node_utils/interface.rb', line 376 def hsrp_delay_minimum return nil if switchport_mode != :disabled || @name[/loop/i] minimum, _reload = hsrp_delay minimum.nil? ? default_hsrp_delay_minimum : minimum end |
#hsrp_delay_minimum=(val) ⇒ Object
hsrp delay minimum and reload are in the same CLI but both can be set independent of each other
384 385 386 387 388 |
# File 'lib/cisco_node_utils/interface.rb', line 384 def hsrp_delay_minimum=(val) Feature.hsrp_enable if val config_set('interface', 'hsrp_delay', name: @name, minimum: 'minimum', min: val, reload: '', rel: '') end |
#hsrp_delay_reload ⇒ Object
394 395 396 397 398 |
# File 'lib/cisco_node_utils/interface.rb', line 394 def hsrp_delay_reload return nil if switchport_mode != :disabled || @name[/loop/i] _minimum, reload = hsrp_delay reload.nil? ? default_hsrp_delay_reload : reload end |
#hsrp_delay_reload=(val) ⇒ Object
hsrp delay minimum and reload are in the same CLI but both can be set independent of each other
402 403 404 405 406 |
# File 'lib/cisco_node_utils/interface.rb', line 402 def hsrp_delay_reload=(val) Feature.hsrp_enable if val config_set('interface', 'hsrp_delay', name: @name, minimum: '', min: '', reload: 'reload', rel: val) end |
#hsrp_mac_refresh ⇒ Object
412 413 414 |
# File 'lib/cisco_node_utils/interface.rb', line 412 def hsrp_mac_refresh config_get('interface', 'hsrp_mac_refresh', @get_args) end |
#hsrp_mac_refresh=(val) ⇒ Object
416 417 418 419 420 421 422 |
# File 'lib/cisco_node_utils/interface.rb', line 416 def hsrp_mac_refresh=(val) state = val ? '' : 'no' time = val ? val : '' Feature.hsrp_enable if val config_set('interface', 'hsrp_mac_refresh', name: @name, state: state, timeout: time) end |
#hsrp_use_bia ⇒ Object
428 429 430 431 432 |
# File 'lib/cisco_node_utils/interface.rb', line 428 def hsrp_use_bia match = config_get('interface', 'hsrp_use_bia', @get_args) return default_hsrp_use_bia unless match match.include?('scope') ? :use_bia_intf : :use_bia end |
#hsrp_use_bia=(val) ⇒ Object
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 |
# File 'lib/cisco_node_utils/interface.rb', line 434 def hsrp_use_bia=(val) # Return early if device already set to the correct value return if val == hsrp_use_bia # need to reset before set if val Feature.hsrp_enable if val == :use_bia config_set('interface', 'hsrp_use_bia', name: name, state: 'no', scope: ' scope interface') config_set('interface', 'hsrp_use_bia', name: name, state: '', scope: '') else config_set('interface', 'hsrp_use_bia', name: name, state: 'no', scope: '') config_set('interface', 'hsrp_use_bia', name: name, state: '', scope: ' scope interface') end else if hsrp_use_bia == :use_bia config_set('interface', 'hsrp_use_bia', name: name, state: 'no', scope: '') else config_set('interface', 'hsrp_use_bia', name: name, state: 'no', scope: ' scope interface') end end end |
#hsrp_version ⇒ Object
466 467 468 469 |
# File 'lib/cisco_node_utils/interface.rb', line 466 def hsrp_version return nil if switchport_mode != :disabled || @name[/loop/i] config_get('interface', 'hsrp_version', @get_args) end |
#hsrp_version=(val) ⇒ Object
471 472 473 474 |
# File 'lib/cisco_node_utils/interface.rb', line 471 def hsrp_version=(val) Feature.hsrp_enable if val config_set('interface', 'hsrp_version', name: name, ver: val) end |
#ipv4_acl_in ⇒ Object
480 481 482 |
# File 'lib/cisco_node_utils/interface.rb', line 480 def ipv4_acl_in config_get('interface', 'ipv4_acl_in', @get_args) end |
#ipv4_acl_in=(val) ⇒ Object
484 485 486 487 488 489 490 491 492 493 494 495 |
# File 'lib/cisco_node_utils/interface.rb', line 484 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
501 502 503 |
# File 'lib/cisco_node_utils/interface.rb', line 501 def ipv4_acl_out config_get('interface', 'ipv4_acl_out', @get_args) end |
#ipv4_acl_out=(val) ⇒ Object
505 506 507 508 509 510 511 512 513 514 515 516 |
# File 'lib/cisco_node_utils/interface.rb', line 505 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
543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'lib/cisco_node_utils/interface.rb', line 543 def ipv4_addr_mask val = config_get('interface', 'ipv4_addr_mask', @get_args) 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
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
# File 'lib/cisco_node_utils/interface.rb', line 522 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_address ⇒ Object
577 578 579 |
# File 'lib/cisco_node_utils/interface.rb', line 577 def ipv4_address select_ipv4_attribute(:v4_addr) end |
#ipv4_address_secondary ⇒ Object
581 582 583 |
# File 'lib/cisco_node_utils/interface.rb', line 581 def ipv4_address_secondary select_ipv4_attribute(:v4_addr_secondary) end |
#ipv4_arp_timeout ⇒ Object
618 619 620 |
# File 'lib/cisco_node_utils/interface.rb', line 618 def ipv4_arp_timeout config_get('interface', ipv4_arp_timeout_lookup_string, @get_args) end |
#ipv4_arp_timeout=(timeout) ⇒ Object
622 623 624 625 626 627 628 |
# File 'lib/cisco_node_utils/interface.rb', line 622 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
609 610 611 612 613 614 615 616 |
# File 'lib/cisco_node_utils/interface.rb', line 609 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_addr ⇒ Object
634 635 636 |
# File 'lib/cisco_node_utils/interface.rb', line 634 def ipv4_dhcp_relay_addr config_get('interface', 'ipv4_dhcp_relay_addr', @get_args) end |
#ipv4_dhcp_relay_addr=(list) ⇒ Object
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 |
# File 'lib/cisco_node_utils/interface.rb', line 638 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_trust ⇒ Object
658 659 660 661 |
# File 'lib/cisco_node_utils/interface.rb', line 658 def ipv4_dhcp_relay_info_trust return nil if @name[/loop/i] || switchport_mode != :disabled config_get('interface', 'ipv4_dhcp_relay_info_trust', @get_args) end |
#ipv4_dhcp_relay_info_trust=(state) ⇒ Object
663 664 665 666 667 668 |
# File 'lib/cisco_node_utils/interface.rb', line 663 def ipv4_dhcp_relay_info_trust=(state) return false if !state && !Feature.dhcp_enabled? Feature.dhcp_enable if state config_set('interface', 'ipv4_dhcp_relay_info_trust', name: @name, state: state ? '' : 'no') end |
#ipv4_dhcp_relay_src_addr_hsrp ⇒ Object
674 675 676 |
# File 'lib/cisco_node_utils/interface.rb', line 674 def ipv4_dhcp_relay_src_addr_hsrp config_get('interface', 'ipv4_dhcp_relay_src_addr_hsrp', @get_args) end |
#ipv4_dhcp_relay_src_addr_hsrp=(state) ⇒ Object
678 679 680 681 682 683 |
# File 'lib/cisco_node_utils/interface.rb', line 678 def ipv4_dhcp_relay_src_addr_hsrp=(state) return false if !state && !Feature.dhcp_enabled? Feature.dhcp_enable if state config_set('interface', 'ipv4_dhcp_relay_src_addr_hsrp', name: @name, state: state ? '' : 'no') end |
#ipv4_dhcp_relay_src_intf ⇒ Object
689 690 691 692 693 694 |
# File 'lib/cisco_node_utils/interface.rb', line 689 def ipv4_dhcp_relay_src_intf intf = config_get('interface', 'ipv4_dhcp_relay_src_intf', @get_args) # Normalize by downcasing and removing white space intf = intf.downcase.delete(' ') if intf intf end |
#ipv4_dhcp_relay_src_intf=(val) ⇒ Object
696 697 698 699 700 701 702 703 |
# File 'lib/cisco_node_utils/interface.rb', line 696 def ipv4_dhcp_relay_src_intf=(val) state = val == default_ipv4_dhcp_relay_src_intf ? 'no' : '' return false if state == 'no' && !Feature.dhcp_enabled? Feature.dhcp_enable if state.empty? intf = val == default_ipv4_dhcp_relay_src_intf ? '' : val config_set('interface', 'ipv4_dhcp_relay_src_intf', name: @name, state: state, intf: intf) end |
#ipv4_dhcp_relay_subnet_broadcast ⇒ Object
709 710 711 712 |
# File 'lib/cisco_node_utils/interface.rb', line 709 def ipv4_dhcp_relay_subnet_broadcast return nil if @name[/loop/i] || switchport_mode != :disabled config_get('interface', 'ipv4_dhcp_relay_subnet_broadcast', @get_args) end |
#ipv4_dhcp_relay_subnet_broadcast=(state) ⇒ Object
714 715 716 717 718 719 |
# File 'lib/cisco_node_utils/interface.rb', line 714 def ipv4_dhcp_relay_subnet_broadcast=(state) return false if !state && !Feature.dhcp_enabled? Feature.dhcp_enable if state config_set('interface', 'ipv4_dhcp_relay_subnet_broadcast', name: @name, state: state ? '' : 'no') end |
#ipv4_dhcp_smart_relay ⇒ Object
725 726 727 728 |
# File 'lib/cisco_node_utils/interface.rb', line 725 def ipv4_dhcp_smart_relay return nil if @name[/loop/i] || switchport_mode != :disabled config_get('interface', 'ipv4_dhcp_smart_relay', @get_args) end |
#ipv4_dhcp_smart_relay=(state) ⇒ Object
730 731 732 733 734 735 |
# File 'lib/cisco_node_utils/interface.rb', line 730 def ipv4_dhcp_smart_relay=(state) return false if !state && !Feature.dhcp_enabled? Feature.dhcp_enable if state config_set('interface', 'ipv4_dhcp_smart_relay', name: @name, state: state ? '' : 'no') end |
#ipv4_forwarding ⇒ Object
741 742 743 |
# File 'lib/cisco_node_utils/interface.rb', line 741 def ipv4_forwarding config_get('interface', 'ipv4_forwarding', @get_args) end |
#ipv4_forwarding=(state) ⇒ Object
745 746 747 748 749 |
# File 'lib/cisco_node_utils/interface.rb', line 745 def ipv4_forwarding=(state) return if state == ipv4_forwarding config_set('interface', 'ipv4_forwarding', name: @name, state: state ? '' : 'no') end |
#ipv4_netmask_length ⇒ Object
585 586 587 |
# File 'lib/cisco_node_utils/interface.rb', line 585 def ipv4_netmask_length select_ipv4_attribute(:v4_mask) end |
#ipv4_netmask_length_secondary ⇒ Object
589 590 591 |
# File 'lib/cisco_node_utils/interface.rb', line 589 def ipv4_netmask_length_secondary select_ipv4_attribute(:v4_mask_secondary) end |
#ipv4_pim_sparse_mode ⇒ Object
755 756 757 758 |
# File 'lib/cisco_node_utils/interface.rb', line 755 def ipv4_pim_sparse_mode return nil unless switchport_mode == :disabled config_get('interface', 'ipv4_pim_sparse_mode', @get_args) end |
#ipv4_pim_sparse_mode=(state) ⇒ Object
760 761 762 763 764 765 |
# File 'lib/cisco_node_utils/interface.rb', line 760 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
771 772 773 774 |
# File 'lib/cisco_node_utils/interface.rb', line 771 def ipv4_proxy_arp return nil if @name[/loop/i] || switchport_mode != :disabled config_get('interface', 'ipv4_proxy_arp', @get_args) end |
#ipv4_proxy_arp=(proxy_arp) ⇒ Object
776 777 778 779 780 |
# File 'lib/cisco_node_utils/interface.rb', line 776 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
795 796 797 798 |
# File 'lib/cisco_node_utils/interface.rb', line 795 def ipv4_redirects return nil unless switchport_mode == :disabled config_get('interface', ipv4_redirects_lookup_string, @get_args) end |
#ipv4_redirects=(redirects) ⇒ Object
800 801 802 803 804 805 |
# File 'lib/cisco_node_utils/interface.rb', line 800 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
786 787 788 789 790 791 792 793 |
# File 'lib/cisco_node_utils/interface.rb', line 786 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
811 812 813 |
# File 'lib/cisco_node_utils/interface.rb', line 811 def ipv6_acl_in config_get('interface', 'ipv6_acl_in', @get_args) end |
#ipv6_acl_in=(val) ⇒ Object
815 816 817 818 819 820 821 822 823 824 825 |
# File 'lib/cisco_node_utils/interface.rb', line 815 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
831 832 833 |
# File 'lib/cisco_node_utils/interface.rb', line 831 def ipv6_acl_out config_get('interface', 'ipv6_acl_out', @get_args) end |
#ipv6_acl_out=(val) ⇒ Object
835 836 837 838 839 840 841 842 843 844 845 |
# File 'lib/cisco_node_utils/interface.rb', line 835 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_addr ⇒ Object
851 852 853 |
# File 'lib/cisco_node_utils/interface.rb', line 851 def ipv6_dhcp_relay_addr config_get('interface', 'ipv6_dhcp_relay_addr', @get_args) end |
#ipv6_dhcp_relay_addr=(list) ⇒ Object
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 |
# File 'lib/cisco_node_utils/interface.rb', line 855 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_intf ⇒ Object
875 876 877 878 879 880 |
# File 'lib/cisco_node_utils/interface.rb', line 875 def ipv6_dhcp_relay_src_intf intf = config_get('interface', 'ipv6_dhcp_relay_src_intf', @get_args) # Normalize by downcasing and removing white space intf = intf.downcase.delete(' ') if intf intf end |
#ipv6_dhcp_relay_src_intf=(val) ⇒ Object
882 883 884 885 886 887 888 889 |
# File 'lib/cisco_node_utils/interface.rb', line 882 def ipv6_dhcp_relay_src_intf=(val) state = val == default_ipv6_dhcp_relay_src_intf ? 'no' : '' return false if state == 'no' && !Feature.dhcp_enabled? Feature.dhcp_enable if state.empty? intf = val == default_ipv6_dhcp_relay_src_intf ? '' : val config_set('interface', 'ipv6_dhcp_relay_src_intf', name: @name, state: state, intf: intf) end |
#ipv6_redirects ⇒ Object
895 896 897 898 |
# File 'lib/cisco_node_utils/interface.rb', line 895 def ipv6_redirects return nil if @name[/loop/i] || switchport_mode != :disabled config_get('interface', 'ipv6_redirects', @get_args) end |
#ipv6_redirects=(redirects) ⇒ Object
900 901 902 903 904 905 |
# File 'lib/cisco_node_utils/interface.rb', line 900 def ipv6_redirects=(redirects) check_switchport(:disabled) no_cmd = (redirects ? '' : 'no') config_set('interface', 'ipv6_redirects', name: @name, state: no_cmd) end |
#lacp_rate ⇒ Object
217 218 219 |
# File 'lib/cisco_node_utils/interface.rb', line 217 def lacp_rate config_get('interface', 'lacp_rate', @get_args) end |
#lacp_rate=(val) ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/cisco_node_utils/interface.rb', line 221 def lacp_rate=(val) if val state = '' else return unless lacp_rate state = 'no' val = lacp_rate end int = Interface.new(@name, false) current_state = int.shutdown int.shutdown = true if lacp_rate_shut_needed? && !current_state config_set('interface', 'lacp_rate', name: @name, state: state, type: val) int.shutdown = current_state unless current_state == int.shutdown end |
#lacp_rate_shut_needed? ⇒ Boolean
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.
213 214 215 |
# File 'lib/cisco_node_utils/interface.rb', line 213 def lacp_rate_shut_needed? config_get('interface', 'lacp_rate_shut_needed') end |
#load_interval_counter_1_delay ⇒ Object
920 921 922 923 |
# File 'lib/cisco_node_utils/interface.rb', line 920 def load_interval_counter_1_delay return nil if @name[/loop/] || @name[/ethernet.*\S+\.\d+$/] config_get('interface', 'load_interval_counter_1_delay', @get_args) end |
#load_interval_counter_1_delay=(val) ⇒ Object
925 926 927 928 929 930 |
# File 'lib/cisco_node_utils/interface.rb', line 925 def load_interval_counter_1_delay=(val) fail ArgumentError, 'Interface cannot be sub-intf or loopback' if @name[/loop/] || @name[/ethernet.*\S+\.\d+$/] config_set('interface', 'load_interval_counter_1_delay', name: @name, delay: val) end |
#load_interval_counter_2_delay ⇒ Object
942 943 944 945 |
# File 'lib/cisco_node_utils/interface.rb', line 942 def load_interval_counter_2_delay return nil if @name[/loop/] || @name[/ethernet.*\S+\.\d+$/] config_get('interface', 'load_interval_counter_2_delay', @get_args) end |
#load_interval_counter_2_delay=(val) ⇒ Object
947 948 949 950 951 952 |
# File 'lib/cisco_node_utils/interface.rb', line 947 def load_interval_counter_2_delay=(val) fail ArgumentError, 'Interface cannot be sub-intf or loopback' if @name[/loop/] || @name[/ethernet.*\S+\.\d+$/] config_set('interface', 'load_interval_counter_2_delay', name: @name, delay: val) end |
#load_interval_counter_3_delay ⇒ Object
958 959 960 961 |
# File 'lib/cisco_node_utils/interface.rb', line 958 def load_interval_counter_3_delay return nil if @name[/loop/] || @name[/ethernet.*\S+\.\d+$/] config_get('interface', 'load_interval_counter_3_delay', @get_args) end |
#load_interval_counter_3_delay=(val) ⇒ Object
963 964 965 966 967 968 969 970 |
# File 'lib/cisco_node_utils/interface.rb', line 963 def load_interval_counter_3_delay=(val) fail ArgumentError, 'Interface cannot be sub-intf or loopback' if @name[/loop/] || @name[/ethernet.*\S+\.\d+$/] state = val ? '' : 'no' delay = val ? val : '' config_set('interface', 'load_interval_counter_3_delay', name: @name, state: state, delay: delay) end |
#mtu ⇒ Object
985 986 987 |
# File 'lib/cisco_node_utils/interface.rb', line 985 def mtu config_get('interface', mtu_lookup_string, @get_args) end |
#mtu=(val) ⇒ Object
989 990 991 992 993 994 |
# File 'lib/cisco_node_utils/interface.rb', line 989 def mtu=(val) return if mtu == val check_switchport(:disabled) config_set('interface', mtu_lookup_string, name: @name, state: '', mtu: val) end |
#mtu_lookup_string ⇒ Object
976 977 978 979 980 981 982 983 |
# File 'lib/cisco_node_utils/interface.rb', line 976 def mtu_lookup_string case @name when /loopback/i return 'mtu_loopback' else return 'mtu_other_interfaces' end end |
#negotiate_auto ⇒ Object
1037 1038 1039 1040 |
# File 'lib/cisco_node_utils/interface.rb', line 1037 def negotiate_auto return nil if @name[/loop|vlan/] config_get('interface', negotiate_auto_lookup_string, @get_args) end |
#negotiate_auto=(negotiate_auto) ⇒ Object
1042 1043 1044 1045 1046 |
# File 'lib/cisco_node_utils/interface.rb', line 1042 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
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 |
# File 'lib/cisco_node_utils/interface.rb', line 1026 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 |
#pim_bfd ⇒ Object
1094 1095 1096 |
# File 'lib/cisco_node_utils/interface.rb', line 1094 def pim_bfd config_get('interface', 'pim_bfd', @get_args) end |
#pim_bfd=(val) ⇒ Object
1098 1099 1100 1101 1102 1103 1104 1105 1106 |
# File 'lib/cisco_node_utils/interface.rb', line 1098 def pim_bfd=(val) return if val == pim_bfd state = val ? '' : 'no' if val Feature.pim_enable Feature.bfd_enable end config_set('interface', 'pim_bfd', name: @name, state: state) end |
#pvlan_enable ⇒ Object
195 196 197 198 |
# File 'lib/cisco_node_utils/interface.rb', line 195 def pvlan_enable switchport_enable Feature.private_vlan_enable end |
#pvlan_mapping ⇒ Object
This is an SVI property. <state> private-vlan mapping <range> # ex. range = [‘2-4,9’] Always returns an array.
1823 1824 1825 1826 1827 |
# File 'lib/cisco_node_utils/interface.rb', line 1823 def pvlan_mapping range = config_get('interface', 'pvlan_mapping', @get_args) return default_pvlan_mapping if range.nil? range.empty? ? range : [range.delete(' ')] end |
#pvlan_mapping=(range) ⇒ Object
1829 1830 1831 1832 1833 1834 1835 1836 1837 |
# File 'lib/cisco_node_utils/interface.rb', line 1829 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
1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 |
# File 'lib/cisco_node_utils/interface.rb', line 1839 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
1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 |
# File 'lib/cisco_node_utils/interface.rb', line 1720 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
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 |
# File 'lib/cisco_node_utils/interface.rb', line 557 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
2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 |
# File 'lib/cisco_node_utils/interface.rb', line 2113 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 |
#shutdown ⇒ Object
1052 1053 1054 |
# File 'lib/cisco_node_utils/interface.rb', line 1052 def shutdown config_get('interface', 'shutdown', @get_args) end |
#shutdown=(state) ⇒ Object
1056 1057 1058 1059 |
# File 'lib/cisco_node_utils/interface.rb', line 1056 def shutdown=(state) no_cmd = (state ? '' : 'no') config_set('interface', 'shutdown', name: @name, state: no_cmd) end |
#speed ⇒ Object
1000 1001 1002 1003 |
# File 'lib/cisco_node_utils/interface.rb', line 1000 def speed return nil if @name[/loop|vlan/i] config_get('interface', 'speed', @get_args) end |
#speed=(val) ⇒ Object
1005 1006 1007 |
# File 'lib/cisco_node_utils/interface.rb', line 1005 def speed=(val) config_set('interface', 'speed', name: @name, speed: val) end |
#storm_control_broadcast ⇒ Object
1112 1113 1114 1115 |
# File 'lib/cisco_node_utils/interface.rb', line 1112 def storm_control_broadcast return nil if @name[/loop|vlan/i] config_get('interface', 'storm_control_broadcast', @get_args) end |
#storm_control_broadcast=(val) ⇒ Object
1117 1118 1119 1120 1121 1122 1123 |
# File 'lib/cisco_node_utils/interface.rb', line 1117 def storm_control_broadcast=(val) return if val == storm_control_broadcast 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_multicast ⇒ Object
1129 1130 1131 1132 |
# File 'lib/cisco_node_utils/interface.rb', line 1129 def storm_control_multicast return nil if @name[/loop|vlan/i] config_get('interface', 'storm_control_multicast', @get_args) end |
#storm_control_multicast=(val) ⇒ Object
1134 1135 1136 1137 1138 1139 1140 |
# File 'lib/cisco_node_utils/interface.rb', line 1134 def storm_control_multicast=(val) return if val == storm_control_multicast 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_unicast ⇒ Object
1146 1147 1148 1149 |
# File 'lib/cisco_node_utils/interface.rb', line 1146 def storm_control_unicast return nil if @name[/loop|vlan/i] config_get('interface', 'storm_control_unicast', @get_args) end |
#storm_control_unicast=(val) ⇒ Object
1151 1152 1153 1154 1155 1156 1157 |
# File 'lib/cisco_node_utils/interface.rb', line 1151 def storm_control_unicast=(val) return if val == storm_control_unicast 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_bpdufilter ⇒ Object
1163 1164 1165 |
# File 'lib/cisco_node_utils/interface.rb', line 1163 def stp_bpdufilter config_get('interface', 'stp_bpdufilter', @get_args) end |
#stp_bpdufilter=(val) ⇒ Object
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 |
# File 'lib/cisco_node_utils/interface.rb', line 1167 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
1183 1184 1185 |
# File 'lib/cisco_node_utils/interface.rb', line 1183 def stp_bpduguard config_get('interface', 'stp_bpduguard', @get_args) end |
#stp_bpduguard=(val) ⇒ Object
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 |
# File 'lib/cisco_node_utils/interface.rb', line 1187 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
1202 1203 1204 1205 1206 |
# File 'lib/cisco_node_utils/interface.rb', line 1202 def stp_cost return nil if switchport_mode == :disabled cost = config_get('interface', 'stp_cost', @get_args) cost == 'auto' ? cost : cost.to_i end |
#stp_cost=(val) ⇒ Object
1208 1209 1210 1211 |
# File 'lib/cisco_node_utils/interface.rb', line 1208 def stp_cost=(val) check_switchport([:access, :trunk]) config_set('interface', 'stp_cost', name: @name, cost: val) end |
#stp_guard ⇒ Object
1217 1218 1219 |
# File 'lib/cisco_node_utils/interface.rb', line 1217 def stp_guard config_get('interface', 'stp_guard', @get_args) end |
#stp_guard=(val) ⇒ Object
1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 |
# File 'lib/cisco_node_utils/interface.rb', line 1221 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
1237 1238 1239 1240 |
# File 'lib/cisco_node_utils/interface.rb', line 1237 def stp_link_type return nil if switchport_mode == :disabled config_get('interface', 'stp_link_type', @get_args) end |
#stp_link_type=(val) ⇒ Object
1242 1243 1244 1245 |
# File 'lib/cisco_node_utils/interface.rb', line 1242 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’]]
1271 1272 1273 |
# File 'lib/cisco_node_utils/interface.rb', line 1271 def stp_mst_cost config_get('interface', 'stp_mst_cost', @get_args) end |
#stp_mst_cost=(list) ⇒ Object
1275 1276 1277 1278 1279 1280 1281 |
# File 'lib/cisco_node_utils/interface.rb', line 1275 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’]]
1293 1294 1295 |
# File 'lib/cisco_node_utils/interface.rb', line 1293 def stp_mst_port_priority config_get('interface', 'stp_mst_port_priority', @get_args) end |
#stp_mst_port_priority=(list) ⇒ Object
1297 1298 1299 1300 1301 1302 1303 |
# File 'lib/cisco_node_utils/interface.rb', line 1297 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
1251 1252 1253 1254 |
# File 'lib/cisco_node_utils/interface.rb', line 1251 def stp_port_priority return nil if switchport_mode == :disabled config_get('interface', 'stp_port_priority', @get_args) end |
#stp_port_priority=(val) ⇒ Object
1256 1257 1258 1259 |
# File 'lib/cisco_node_utils/interface.rb', line 1256 def stp_port_priority=(val) check_switchport([:access, :trunk]) config_set('interface', 'stp_port_priority', name: @name, pp: val) end |
#stp_port_type ⇒ Object
1309 1310 1311 |
# File 'lib/cisco_node_utils/interface.rb', line 1309 def stp_port_type config_get('interface', 'stp_port_type', @get_args) end |
#stp_port_type=(val) ⇒ Object
1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 |
# File 'lib/cisco_node_utils/interface.rb', line 1313 def stp_port_type=(val) if val state = '' else return unless stp_port_type state = 'no' val = stp_port_type 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’]]
1335 1336 1337 |
# File 'lib/cisco_node_utils/interface.rb', line 1335 def stp_vlan_cost config_get('interface', 'stp_vlan_cost', @get_args) end |
#stp_vlan_cost=(list) ⇒ Object
1339 1340 1341 1342 1343 1344 1345 |
# File 'lib/cisco_node_utils/interface.rb', line 1339 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’]]
1357 1358 1359 |
# File 'lib/cisco_node_utils/interface.rb', line 1357 def stp_vlan_port_priority config_get('interface', 'stp_vlan_port_priority', @get_args) end |
#stp_vlan_port_priority=(list) ⇒ Object
1361 1362 1363 1364 1365 1366 1367 |
# File 'lib/cisco_node_utils/interface.rb', line 1361 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
1978 1979 1980 1981 |
# File 'lib/cisco_node_utils/interface.rb', line 1978 def svi_autostate return nil unless @name[/^vlan/i] config_get('interface', 'svi_autostate', @get_args) end |
#svi_autostate=(val) ⇒ Object
1983 1984 1985 1986 1987 1988 |
# File 'lib/cisco_node_utils/interface.rb', line 1983 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
1972 1973 1974 1975 |
# File 'lib/cisco_node_utils/interface.rb', line 1972 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
2006 2007 2008 2009 |
# File 'lib/cisco_node_utils/interface.rb', line 2006 def svi_management return nil unless @name[/^vlan/i] config_get('interface', 'svi_management', @get_args) end |
#svi_management=(val) ⇒ Object
2011 2012 2013 2014 2015 2016 |
# File 'lib/cisco_node_utils/interface.rb', line 2011 def svi_management=(val) check_switchport(:disabled) svi_cmd_allowed?('management') config_set('interface', 'svi_management', name: @name, state: val ? '' : 'no') end |
#switchport ⇒ Object
1373 1374 1375 1376 |
# File 'lib/cisco_node_utils/interface.rb', line 1373 def switchport # This is "switchport", not "switchport mode" config_get('interface', 'switchport', @get_args) end |
#switchport_autostate_exclude ⇒ Object
switchport_autostate_exclude is exclusive to switchport interfaces
1383 1384 1385 1386 |
# File 'lib/cisco_node_utils/interface.rb', line 1383 def switchport_autostate_exclude return nil if switchport_mode == :disabled config_get('interface', 'switchport_autostate_exclude', @get_args) end |
#switchport_autostate_exclude=(val) ⇒ Object
1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 |
# File 'lib/cisco_node_utils/interface.rb', line 1388 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
1378 1379 1380 |
# File 'lib/cisco_node_utils/interface.rb', line 1378 def switchport_enable(val=true) config_set('interface', 'switchport', name: @name, state: val ? '' : 'no') end |
#switchport_enable_and_mode(mode_set) ⇒ Object
1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 |
# File 'lib/cisco_node_utils/interface.rb', line 1428 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_mode ⇒ Object
1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 |
# File 'lib/cisco_node_utils/interface.rb', line 1414 def switchport_mode return nil if platform == :ios_xr mode = config_get('interface', switchport_mode_lookup_string, @get_args) 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
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 |
# File 'lib/cisco_node_utils/interface.rb', line 1440 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_string ⇒ Object
1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 |
# File 'lib/cisco_node_utils/interface.rb', line 1403 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_host ⇒ Object
<state> switchport mode private-vlan host
1533 1534 1535 1536 |
# File 'lib/cisco_node_utils/interface.rb', line 1533 def switchport_pvlan_host return nil if switchport_mode == :disabled config_get('interface', 'switchport_pvlan_host', @get_args) end |
#switchport_pvlan_host=(state) ⇒ Object
1538 1539 1540 1541 1542 |
# File 'lib/cisco_node_utils/interface.rb', line 1538 def switchport_pvlan_host=(state) pvlan_enable config_set('interface', 'switchport_pvlan_host', name: @name, state: state ? '' : 'no') end |
#switchport_pvlan_host_association ⇒ Object
<state> switchport private-vlan host-association <pri> <sec> Note this is NOT a multiple, unlike trunk association.
1568 1569 1570 |
# File 'lib/cisco_node_utils/interface.rb', line 1568 def switchport_pvlan_host_association config_get('interface', 'switchport_pvlan_host_association', @get_args) end |
#switchport_pvlan_host_association=(pri_and_sec) ⇒ Object
Input: An array of primary and secondary vlans: [‘44’, ‘244’]
1573 1574 1575 1576 1577 1578 1579 1580 1581 |
# File 'lib/cisco_node_utils/interface.rb', line 1573 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_mapping ⇒ Object
<state> switchport private-vlan mapping <primary> <vlan>
1589 1590 1591 |
# File 'lib/cisco_node_utils/interface.rb', line 1589 def switchport_pvlan_mapping config_get('interface', 'switchport_pvlan_mapping', @get_args) end |
#switchport_pvlan_mapping=(primary_and_range) ⇒ Object
Input: An array of primary vlan and range of vlans: [‘44’, ‘3-4,6’]
1594 1595 1596 |
# File 'lib/cisco_node_utils/interface.rb', line 1594 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
1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 |
# File 'lib/cisco_node_utils/interface.rb', line 1607 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
1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 |
# File 'lib/cisco_node_utils/interface.rb', line 1639 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_trunk ⇒ Object
<state> switchport private-vlan mapping trunk <primary> <vlan>
1653 1654 1655 |
# File 'lib/cisco_node_utils/interface.rb', line 1653 def switchport_pvlan_mapping_trunk config_get('interface', 'switchport_pvlan_mapping_trunk', @get_args) end |
#switchport_pvlan_mapping_trunk=(should) ⇒ Object
Input: A nested array of primary vlan and range of vlans:
- [‘44’, ‘3-4,6’], [‘99’, ‘199’]
1659 1660 1661 |
# File 'lib/cisco_node_utils/interface.rb', line 1659 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']
1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 |
# File 'lib/cisco_node_utils/interface.rb', line 1675 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_promiscuous ⇒ Object
<state> switchport mode private-vlan promiscuous
1550 1551 1552 1553 |
# File 'lib/cisco_node_utils/interface.rb', line 1550 def switchport_pvlan_promiscuous return nil if switchport_mode == :disabled config_get('interface', 'switchport_pvlan_promiscuous', @get_args) end |
#switchport_pvlan_promiscuous=(state) ⇒ Object
1555 1556 1557 1558 1559 |
# File 'lib/cisco_node_utils/interface.rb', line 1555 def switchport_pvlan_promiscuous=(state) pvlan_enable config_set('interface', 'switchport_pvlan_promiscuous', name: @name, state: state ? '' : 'no') end |
#switchport_pvlan_trunk_allowed_vlan ⇒ Object
<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.
1779 1780 1781 1782 1783 1784 1785 1786 |
# File 'lib/cisco_node_utils/interface.rb', line 1779 def switchport_pvlan_trunk_allowed_vlan return nil if switchport_mode == :disabled vlans = config_get('interface', 'switchport_pvlan_trunk_allowed_vlan', @get_args) 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
1788 1789 1790 1791 1792 1793 1794 1795 1796 |
# File 'lib/cisco_node_utils/interface.rb', line 1788 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_association ⇒ Object
<state> switchport private-vlan association trunk <pri> <sec> Supports multiple.
1704 1705 1706 |
# File 'lib/cisco_node_utils/interface.rb', line 1704 def switchport_pvlan_trunk_association config_get('interface', 'switchport_pvlan_trunk_association', @get_args) end |
#switchport_pvlan_trunk_association=(should) ⇒ Object
Input: A nested array of primary and secondary vlans:
- [‘44’, ‘244’], [‘99’, ‘299’]
1710 1711 1712 1713 1714 1715 1716 1717 1718 |
# File 'lib/cisco_node_utils/interface.rb', line 1710 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_vlan ⇒ Object
<state> switchport trunk native vlan <vlan>
1804 1805 1806 1807 |
# File 'lib/cisco_node_utils/interface.rb', line 1804 def switchport_pvlan_trunk_native_vlan return nil if switchport_mode == :disabled config_get('interface', 'switchport_pvlan_trunk_native_vlan', @get_args) end |
#switchport_pvlan_trunk_native_vlan=(vlan) ⇒ Object
1809 1810 1811 1812 1813 |
# File 'lib/cisco_node_utils/interface.rb', line 1809 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_promiscuous ⇒ Object
<state> switchport mode private-vlan trunk promiscuous
1743 1744 1745 1746 |
# File 'lib/cisco_node_utils/interface.rb', line 1743 def switchport_pvlan_trunk_promiscuous return nil if switchport_mode == :disabled config_get('interface', 'switchport_pvlan_trunk_promiscuous', @get_args) end |
#switchport_pvlan_trunk_promiscuous=(state) ⇒ Object
1748 1749 1750 1751 1752 |
# File 'lib/cisco_node_utils/interface.rb', line 1748 def switchport_pvlan_trunk_promiscuous=(state) pvlan_enable config_set('interface', 'switchport_pvlan_trunk_promiscuous', name: @name, state: state ? '' : 'no') end |
#switchport_pvlan_trunk_secondary ⇒ Object
<state> switchport mode private-vlan trunk secondary
1760 1761 1762 1763 |
# File 'lib/cisco_node_utils/interface.rb', line 1760 def switchport_pvlan_trunk_secondary return nil if switchport_mode == :disabled config_get('interface', 'switchport_pvlan_trunk_secondary', @get_args) end |
#switchport_pvlan_trunk_secondary=(state) ⇒ Object
1765 1766 1767 1768 1769 |
# File 'lib/cisco_node_utils/interface.rb', line 1765 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
2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 |
# File 'lib/cisco_node_utils/interface.rb', line 2031 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
1473 1474 1475 1476 1477 1478 1479 1480 |
# File 'lib/cisco_node_utils/interface.rb', line 1473 def switchport_trunk_allowed_vlan return nil if switchport_mode == :disabled vlans = config_get('interface', 'switchport_trunk_allowed_vlan', @get_args) 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
1482 1483 1484 1485 1486 1487 1488 1489 1490 |
# File 'lib/cisco_node_utils/interface.rb', line 1482 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
1496 1497 1498 1499 |
# File 'lib/cisco_node_utils/interface.rb', line 1496 def switchport_trunk_native_vlan return nil if switchport_mode == :disabled config_get('interface', 'switchport_trunk_native_vlan', @get_args) end |
#switchport_trunk_native_vlan=(val) ⇒ Object
1501 1502 1503 1504 1505 1506 1507 1508 1509 |
# File 'lib/cisco_node_utils/interface.rb', line 1501 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
1958 1959 1960 1961 |
# File 'lib/cisco_node_utils/interface.rb', line 1958 def switchport_vtp return nil unless switchport_vtp_mode_capable? config_get('interface', 'vtp', @get_args) end |
#switchport_vtp=(vtp_set) ⇒ Object
1963 1964 1965 1966 1967 1968 1969 1970 |
# File 'lib/cisco_node_utils/interface.rb', line 1963 def switchport_vtp=(vtp_set) # TODO: throw UnsupportedError instead of returning false? return false unless switchport_vtp_mode_capable? return false if !vtp_set && !Feature.vtp_enabled? Feature.vtp_enable if vtp_set no_cmd = (vtp_set) ? '' : 'no' config_set('interface', 'vtp', name: @name, state: no_cmd) end |
#switchport_vtp_feature? ⇒ Boolean
2027 2028 2029 |
# File 'lib/cisco_node_utils/interface.rb', line 2027 def switchport_vtp_feature? config_get('vtp', 'feature') end |
#switchport_vtp_mode_capable? ⇒ Boolean
1954 1955 1956 |
# File 'lib/cisco_node_utils/interface.rb', line 1954 def switchport_vtp_mode_capable? !switchport_mode.to_s.match(/(access|trunk)/).nil? end |
#system_default_svi_autostate ⇒ Object
1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 |
# File 'lib/cisco_node_utils/interface.rb', line 1939 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_switchport ⇒ Object
1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 |
# File 'lib/cisco_node_utils/interface.rb', line 1921 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_shutdown ⇒ Object
1934 1935 1936 1937 |
# File 'lib/cisco_node_utils/interface.rb', line 1934 def system_default_switchport_shutdown # This command is a user-configurable system default. config_get('interface', 'system_default_switchport_shutdown') end |
#to_s ⇒ Object
70 71 72 |
# File 'lib/cisco_node_utils/interface.rb', line 70 def to_s "interface #{name}" end |
#vlan_mapping ⇒ Object
1876 1877 1878 1879 1880 |
# File 'lib/cisco_node_utils/interface.rb', line 1876 def vlan_mapping match = config_get('interface', 'vlan_mapping', @get_args) match.each(&:compact!) unless match.nil? match end |
#vlan_mapping=(should_list) ⇒ Object
1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 |
# File 'lib/cisco_node_utils/interface.rb', line 1882 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_enable ⇒ Object
1908 1909 1910 |
# File 'lib/cisco_node_utils/interface.rb', line 1908 def vlan_mapping_enable config_get('interface', 'vlan_mapping_enable', @get_args) end |
#vlan_mapping_enable=(state) ⇒ Object
1912 1913 1914 1915 |
# File 'lib/cisco_node_utils/interface.rb', line 1912 def vlan_mapping_enable=(state) config_set('interface', 'vlan_mapping_enable', name: @name, state: state ? '' : 'no') end |
#vpc_id ⇒ Object
2050 2051 2052 |
# File 'lib/cisco_node_utils/interface.rb', line 2050 def vpc_id config_get('interface', 'vpc_id', @get_args) end |
#vpc_id=(num) ⇒ Object
2054 2055 2056 2057 2058 2059 2060 2061 2062 |
# File 'lib/cisco_node_utils/interface.rb', line 2054 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 |
#vpc_peer_link ⇒ Object
2068 2069 2070 2071 |
# File 'lib/cisco_node_utils/interface.rb', line 2068 def vpc_peer_link return nil unless @name[/port-channel/i] && switchport_mode != :disabled config_get('interface', 'vpc_peer_link', @get_args) end |
#vpc_peer_link=(state) ⇒ Object
2073 2074 2075 2076 2077 |
# File 'lib/cisco_node_utils/interface.rb', line 2073 def vpc_peer_link=(state) return if vpc_peer_link == state no_cmd = (state ? '' : 'no') config_set('interface', 'vpc_peer_link', name: @name, state: no_cmd) end |
#vrf ⇒ Object
2083 2084 2085 |
# File 'lib/cisco_node_utils/interface.rb', line 2083 def vrf config_get('interface', 'vrf', @get_args) end |
#vrf=(v) ⇒ Object
2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 |
# File 'lib/cisco_node_utils/interface.rb', line 2087 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 |