def _delete_switch_entry(self, port, vlan_id, device_id, host_id, vni,
                             is_provider_vlan):
        """Delete the nexus switch entry.

        By accessing the current db entries determine if switch
        configuration can be removed.

        Called during delete postcommit port event.
        """

        connections = self._get_active_port_connections(port, host_id)

        # (nexus_port,switch_ip) will be unique in each iteration.
        # But switch_ip will repeat if host has >1 connection to same switch.
        # So track which switch_ips already have vlan removed in this loop.
        vlan_already_removed = []
        for switch_ip, intf_type, nexus_port, is_native, _ in connections:

            # if there are no remaining db entries using this vlan on this
            # nexus switch port then remove vlan from the switchport trunk.
            port_id = nexus_help.format_interface_name(intf_type, nexus_port)
            auto_create = True
            auto_trunk = True
            if is_provider_vlan:
                auto_create = cfg.CONF.ml2_cisco.provider_vlan_auto_create
                auto_trunk = cfg.CONF.ml2_cisco.provider_vlan_auto_trunk

            try:
                nxos_db.get_port_vlan_switch_binding(port_id, vlan_id,
                                                     switch_ip)
            except excep.NexusPortBindingNotFound:
                pass
            else:
                continue

            if auto_trunk:
                self.driver.disable_vlan_on_trunk_int(
                    switch_ip, vlan_id, intf_type, nexus_port,
                    is_native)

            # if there are no remaining db entries using this vlan on this
            # nexus switch then remove the vlan.
            if auto_create:
                try:
                    nxos_db.get_nexusvlan_binding(vlan_id, switch_ip)
                except excep.NexusPortBindingNotFound:
                    # Do not perform a second time on same switch
                    if switch_ip not in vlan_already_removed:
                        self.driver.delete_vlan(switch_ip, vlan_id)
                        vlan_already_removed.append(switch_ip)

            self._delete_port_channel_resources(
                host_id, switch_ip, intf_type, nexus_port, port_id)

        if nexus_help.is_baremetal(port):
            connections = self._get_baremetal_connections(
                port, False, True)
            for switch_ip, intf_type, nexus_port, is_native, _ in connections:
                if_id = nexus_help.format_interface_name(
                    intf_type, nexus_port)
                try:
                    mapping = nxos_db.get_switch_if_host_mappings(
                        switch_ip, if_id)
                    ch_grp = mapping[0].ch_grp
                except excep.NexusHostMappingNotFound:
                    ch_grp = 0
                bind_port_id = nexus_help.format_interface_name(
                    intf_type, nexus_port, ch_grp)
                binding = nxos_db.get_port_switch_bindings(
                    bind_port_id,
                    switch_ip)
                if not binding:
                    nxos_db.remove_host_mapping(if_id, switch_ip)
def _delete_switch_entry ( self , port , vlan_id , device_id , host_id , vni , is_provider_vlan ) : connections = self . _get_active_port_connections ( port , host_id ) vlan_already_removed = [ ] for switch_ip , intf_type , nexus_port , is_native , _ in connections : port_id = nexus_help . format_interface_name ( intf_type , nexus_port ) auto_create = True auto_trunk = True if is_provider_vlan : auto_create = cfg . CONF . ml2_cisco . provider_vlan_auto_create auto_trunk = cfg . CONF . ml2_cisco . provider_vlan_auto_trunk try : nxos_db . get_port_vlan_switch_binding ( port_id , vlan_id , switch_ip ) except excep . NexusPortBindingNotFound : pass else : continue if auto_trunk : self . driver . disable_vlan_on_trunk_int ( switch_ip , vlan_id , intf_type , nexus_port , is_native ) if auto_create : try : nxos_db . get_nexusvlan_binding ( vlan_id , switch_ip ) except excep . NexusPortBindingNotFound : if switch_ip not in vlan_already_removed : self . driver . delete_vlan ( switch_ip , vlan_id ) vlan_already_removed . append ( switch_ip ) self . _delete_port_channel_resources ( host_id , switch_ip , intf_type , nexus_port , port_id ) if nexus_help . is_baremetal ( port ) : connections = self . _get_baremetal_connections ( port , False , True ) for switch_ip , intf_type , nexus_port , is_native , _ in connections : if_id = nexus_help . format_interface_name ( intf_type , nexus_port ) try : mapping = nxos_db . get_switch_if_host_mappings ( switch_ip , if_id ) ch_grp = mapping [ 0 ] . ch_grp except excep . NexusHostMappingNotFound : ch_grp = 0 bind_port_id = nexus_help . format_interface_name ( intf_type , nexus_port , ch_grp ) binding = nxos_db . get_port_switch_bindings ( bind_port_id , switch_ip ) if not binding : nxos_db . remove_host_mapping ( if_id , switch_ip )
Delete the nexus switch entry.

        By accessing the current db entries determine if switch
        configuration can be removed.

        Called during delete postcommit port event.