diff --git a/lib/cisco_node_utils/cmd_ref/interface.yaml b/lib/cisco_node_utils/cmd_ref/interface.yaml index aacab245..49b9b04d 100644 --- a/lib/cisco_node_utils/cmd_ref/interface.yaml +++ b/lib/cisco_node_utils/cmd_ref/interface.yaml @@ -127,7 +127,7 @@ hsrp_mac_refresh: kind: int get_value: '/^hsrp mac-refresh (\d+)$/' set_value: ' hsrp mac-refresh ' - default_value: false + default_value: ~ hsrp_use_bia: _exclude: [ios_xr, N5k, N6k] @@ -137,7 +137,7 @@ hsrp_use_bia: # optional match to get the whole config get_value: '/^hsrp use-bia(?:\s+\S+\s+\S+)?$/' set_value: ' hsrp use-bia' - default_value: false + default_value: ~ hsrp_version: _exclude: [ios_xr, N5k, N6k] @@ -211,7 +211,7 @@ ipv4_dhcp_relay_src_intf: _exclude: [ios_xr] get_value: '/^ip dhcp relay source-interface (.*)$/' set_value: " ip dhcp relay source-interface " - default_value: false + default_value: ~ ipv4_dhcp_relay_subnet_broadcast: _exclude: [ios_xr] @@ -258,7 +258,7 @@ ipv4_proxy_arp: ipv4_redirects_loopback: kind: boolean nexus: - default_only: false + default_only: ~ ios_xr: get_value: '/^((?:no )?ipv4 redirects)$/' set_value: " ipv4 redirects" @@ -304,7 +304,7 @@ ipv6_dhcp_relay_src_intf: _exclude: [ios_xr] get_value: '/^ipv6 dhcp relay source-interface (.*)$/' set_value: " ipv6 dhcp relay source-interface " - default_value: false + default_value: ~ ipv6_redirects: _exclude: [ios_xr] @@ -336,7 +336,7 @@ load_interval_counter_3_delay: kind: int get_value: '/^load-interval counter 3 (\d+)$/' set_value: " load-interval counter 3 " - default_value: false + default_value: ~ mtu_loopback: kind: boolean @@ -384,6 +384,7 @@ purge_config: set_value: "default interface " get_command: "show running interface" get_value: '/(.*)/' + default_value: ~ pvlan_any: multiple: @@ -469,13 +470,13 @@ stp_bpdufilter: kind: string get_value: '/^spanning-tree bpdufilter (.*)$/' set_value: " spanning-tree bpdufilter " - default_value: false + default_value: ~ stp_bpduguard: kind: string get_value: '/^spanning-tree bpduguard (.*)$/' set_value: " spanning-tree bpduguard " - default_value: false + default_value: ~ stp_cost: kind: string @@ -487,7 +488,7 @@ stp_guard: kind: string get_value: '/^spanning-tree guard (.*)$/' set_value: " spanning-tree guard " - default_value: false + default_value: ~ stp_link_type: kind: string @@ -524,7 +525,7 @@ stp_port_type: get_command: "show running interface" get_value: '/^spanning-tree port type (.*)$/' set_value: " spanning-tree port type " - default_value: false + default_value: ~ stp_vlan_cost: multiple: @@ -632,7 +633,7 @@ switchport_pvlan_trunk_allowed_vlan: multiple: true get_value: '/^switchport private-vlan trunk allowed vlan (?:add )?(\S+)$/' set_value: "switchport private-vlan trunk allowed vlan " - default_value: 'none' + default_value: none switchport_pvlan_trunk_association: _exclude: [ios_xr, N3k, N3k-F, N9k-F] @@ -735,7 +736,7 @@ vpc_id: kind: int get_value: '/^vpc (\d+)$/' set_value: ' vpc ' - default_value: false + default_value: ~ vpc_peer_link: kind: boolean diff --git a/lib/cisco_node_utils/interface.rb b/lib/cisco_node_utils/interface.rb index f4fb7719..e2dd3d95 100644 --- a/lib/cisco_node_utils/interface.rb +++ b/lib/cisco_node_utils/interface.rb @@ -192,6 +192,7 @@ def pvlan_enable # are left untouched. def access_vlan + return nil if switchport_mode == :disabled config_get('interface', 'access_vlan', name: @name) end @@ -275,6 +276,7 @@ def fabric_forwarding_anycast_gateway end def fabric_forwarding_anycast_gateway=(state) + return if fabric_forwarding_anycast_gateway == state no_cmd = (state ? '' : 'no') config_set('interface', 'fabric_forwarding_anycast_gateway', @@ -325,6 +327,7 @@ def default_hsrp_delay end 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 @@ -342,6 +345,7 @@ def default_hsrp_delay_minimum end 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 @@ -413,6 +417,7 @@ def default_hsrp_use_bia end def hsrp_version + return nil if switchport_mode != :disabled || @name[/loop/i] config_get('interface', 'hsrp_version', name: @name) end @@ -604,6 +609,7 @@ def default_ipv4_dhcp_relay_addr end def ipv4_dhcp_relay_info_trust + return nil if @name[/loop/i] || switchport_mode != :disabled config_get('interface', 'ipv4_dhcp_relay_info_trust', name: @name) end @@ -654,6 +660,7 @@ def default_ipv4_dhcp_relay_src_intf end def ipv4_dhcp_relay_subnet_broadcast + return nil if @name[/loop/i] || switchport_mode != :disabled config_get('interface', 'ipv4_dhcp_relay_subnet_broadcast', name: @name) end @@ -669,6 +676,7 @@ def default_ipv4_dhcp_relay_subnet_broadcast end def ipv4_dhcp_smart_relay + return nil if @name[/loop/i] || switchport_mode != :disabled config_get('interface', 'ipv4_dhcp_smart_relay', name: @name) end @@ -698,6 +706,7 @@ def default_ipv4_forwarding end def ipv4_pim_sparse_mode + return nil unless switchport_mode == :disabled config_get('interface', 'ipv4_pim_sparse_mode', name: @name) end @@ -713,6 +722,7 @@ def default_ipv4_pim_sparse_mode end def ipv4_proxy_arp + return nil if @name[/loop/i] || switchport_mode != :disabled config_get('interface', 'ipv4_proxy_arp', name: @name) end @@ -736,6 +746,7 @@ def ipv4_redirects_lookup_string end def ipv4_redirects + return nil unless switchport_mode == :disabled config_get('interface', ipv4_redirects_lookup_string, name: @name) end @@ -835,6 +846,7 @@ def default_ipv6_dhcp_relay_src_intf end def ipv6_redirects + return nil if @name[/loop/i] || switchport_mode != :disabled config_get('interface', 'ipv6_redirects', name: @name) end @@ -928,6 +940,7 @@ def mtu end def mtu=(val) + return if mtu == val check_switchport(:disabled) config_set('interface', mtu_lookup_string, name: @name, state: '', mtu: val) @@ -938,6 +951,7 @@ def default_mtu end def speed + return nil if @name[/loop|vlan/i] config_get('interface', 'speed', name: @name) end @@ -950,6 +964,7 @@ def default_speed end def duplex + return nil if @name[/loop|vlan/i] config_get('interface', 'duplex', name: @name) end @@ -973,6 +988,7 @@ def negotiate_auto_lookup_string end def negotiate_auto + return nil if @name[/loop|vlan/] config_get('interface', negotiate_auto_lookup_string, name: @name) end @@ -1047,10 +1063,12 @@ def default_pim_bfd end def storm_control_broadcast + return nil if @name[/loop|vlan/i] config_get('interface', 'storm_control_broadcast', name: @name) end 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', @@ -1062,10 +1080,12 @@ def default_storm_control_broadcast end def storm_control_multicast + return nil if @name[/loop|vlan/i] config_get('interface', 'storm_control_multicast', name: @name) end def storm_control_multicast=(val) + return if val == storm_control_broadcast state = val == default_storm_control_multicast ? 'no' : '' level = val == default_storm_control_multicast ? '' : val config_set('interface', 'storm_control_multicast', @@ -1077,10 +1097,12 @@ def default_storm_control_multicast end def storm_control_unicast + return nil if @name[/loop|vlan/i] config_get('interface', 'storm_control_unicast', name: @name) end def storm_control_unicast=(val) + return if val == storm_control_broadcast state = val == default_storm_control_unicast ? 'no' : '' level = val == default_storm_control_unicast ? '' : val config_set('interface', 'storm_control_unicast', @@ -1131,6 +1153,7 @@ def default_stp_bpduguard end def stp_cost + return nil if switchport_mode == :disabled cost = config_get('interface', 'stp_cost', name: @name) cost == 'auto' ? cost : cost.to_i end @@ -1165,6 +1188,7 @@ def default_stp_guard end def stp_link_type + return nil if switchport_mode == :disabled config_get('interface', 'stp_link_type', name: @name) end @@ -1178,6 +1202,7 @@ def default_stp_link_type end def stp_port_priority + return nil if switchport_mode == :disabled config_get('interface', 'stp_port_priority', name: @name) end @@ -1309,6 +1334,7 @@ def switchport_enable(val=true) # switchport_autostate_exclude is exclusive to switchport interfaces def switchport_autostate_exclude + return nil if switchport_mode == :disabled config_get('interface', 'switchport_autostate_exclude', name: @name) end @@ -1399,6 +1425,7 @@ def default_switchport_mode end def switchport_trunk_allowed_vlan + return nil if switchport_mode == :disabled vlans = config_get('interface', 'switchport_trunk_allowed_vlan', name: @name) vlans = vlans.join(',') if vlans.is_a?(Array) @@ -1421,6 +1448,7 @@ def default_switchport_trunk_allowed_vlan end def switchport_trunk_native_vlan + return nil if switchport_mode == :disabled config_get('interface', 'switchport_trunk_native_vlan', name: @name) end @@ -1457,6 +1485,7 @@ def cli_error_check(result) # -------------------------- # switchport mode private-vlan host def switchport_pvlan_host + return nil if switchport_mode == :disabled config_get('interface', 'switchport_pvlan_host', name: @name) end @@ -1473,6 +1502,7 @@ def default_switchport_pvlan_host # -------------------------- # switchport mode private-vlan promiscuous def switchport_pvlan_promiscuous + return nil if switchport_mode == :disabled config_get('interface', 'switchport_pvlan_promiscuous', name: @name) end @@ -1665,6 +1695,7 @@ def default_switchport_pvlan_trunk_association # -------------------------- # switchport mode private-vlan trunk promiscuous def switchport_pvlan_trunk_promiscuous + return nil if switchport_mode == :disabled config_get('interface', 'switchport_pvlan_trunk_promiscuous', name: @name) end @@ -1681,6 +1712,7 @@ def default_switchport_pvlan_trunk_promiscuous # -------------------------- # switchport mode private-vlan trunk secondary def switchport_pvlan_trunk_secondary + return nil if switchport_mode == :disabled config_get('interface', 'switchport_pvlan_trunk_secondary', name: @name) end @@ -1699,6 +1731,7 @@ def default_switchport_pvlan_trunk_secondary # Note that range is handled as a string because the entire range is # replaced instead of individually adding or removing vlans from the range. def switchport_pvlan_trunk_allowed_vlan + return nil if switchport_mode == :disabled vlans = config_get('interface', 'switchport_pvlan_trunk_allowed_vlan', name: @name) vlans = vlans.join(',') if vlans.is_a?(Array) @@ -1723,6 +1756,7 @@ def default_switchport_pvlan_trunk_allowed_vlan # -------------------------- # switchport trunk native vlan def switchport_pvlan_trunk_native_vlan + return nil if switchport_mode == :disabled config_get('interface', 'switchport_pvlan_trunk_native_vlan', name: @name) end @@ -1986,10 +2020,12 @@ def default_vpc_id end def vpc_peer_link + return nil unless @name[/port-channel/i] && switchport_mode != :disabled config_get('interface', 'vpc_peer_link', name: @name) end def vpc_peer_link=(state) + return if vpc_peerlink == state no_cmd = (state ? '' : 'no') config_set('interface', 'vpc_peer_link', name: @name, state: no_cmd) end @@ -2052,8 +2088,14 @@ def purge_config=(val) end def purge_config + # This getter is only supported on ethernet interfaces + return nil unless @name[/ethernet/] state = config_get('interface', 'purge_config', name: @name) - state.nil? ? true : false + state.nil? ? true : default_purge_config + end + + def default_purge_config + config_get_default('interface', 'purge_config') end end # Class end # Module diff --git a/lib/cisco_node_utils/interface_DEPRECATED.rb b/lib/cisco_node_utils/interface_DEPRECATED.rb index 38e46b38..652d9961 100644 --- a/lib/cisco_node_utils/interface_DEPRECATED.rb +++ b/lib/cisco_node_utils/interface_DEPRECATED.rb @@ -65,6 +65,7 @@ def switchport_enable_and_mode_private_vlan_host(mode_set) end def switchport_mode_private_vlan_host + return nil if switchport_mode == :disabled mode = config_get('DEPRECATED', 'switchport_mode_private_vlan_host', name: @name) @@ -299,6 +300,7 @@ def default_switchport_mode_private_vlan_host_promisc end def switchport_mode_private_vlan_trunk_promiscuous + return nil if switchport_mode == :disabled config_get('DEPRECATED', 'switchport_mode_private_vlan_trunk_promiscuous', name: @name) @@ -331,6 +333,7 @@ def default_switchport_mode_private_vlan_trunk_promiscuous end def switchport_mode_private_vlan_trunk_secondary + return nil if switchport_mode == :disabled config_get('DEPRECATED', 'switchport_mode_private_vlan_trunk_secondary', name: @name) @@ -361,6 +364,7 @@ def default_switchport_mode_private_vlan_trunk_secondary end def switchport_private_vlan_trunk_allowed_vlan + return nil if switchport_mode == :disabled result = config_get('DEPRECATED', 'switchport_private_vlan_trunk_allowed_vlan', name: @name) @@ -400,6 +404,7 @@ def default_switchport_private_vlan_trunk_allowed_vlan end def switchport_private_vlan_trunk_native_vlan + return nil if switchport_mode == :disabled config_get('DEPRECATED', 'switchport_private_vlan_trunk_native_vlan', name: @name)