コード例 #1
0
ファイル: mech_cisco_nexus.py プロジェクト: ChengZuo/neutron
    def delete_port_precommit(self, context):
        """Delete port pre-database commit event.

        Delete port bindings from the database and scan whether the network
        is still required on the interfaces trunked.
        """

        if not self._is_deviceowner_compute(context.current):
            return

        port = context.current
        device_id = port['device_id']
        vlan_id = self._get_vlanid(context)

        if not vlan_id or not device_id:
            return

        # Delete DB row for this port
        try:
            row = nxos_db.get_nexusvm_binding(vlan_id, device_id)
        except excep.NexusPortBindingNotFound:
            return

        switch_ip = row.switch_ip
        nexus_port = None
        if row.port_id != 'router':
            nexus_port = row.port_id

        nxos_db.remove_nexusport_binding(row.port_id, row.vlan_id,
                                         row.switch_ip, row.instance_id)

        # Check for any other bindings with the same vlan_id and switch_ip
        try:
            nxos_db.get_nexusvlan_binding(row.vlan_id, row.switch_ip)
        except excep.NexusPortBindingNotFound:
            try:
                # Delete this vlan from this switch
                if nexus_port:
                    self.driver.disable_vlan_on_trunk_int(switch_ip,
                                                          row.vlan_id,
                                                          nexus_port)
                self.driver.delete_vlan(switch_ip, row.vlan_id)
            except Exception:
                # The delete vlan operation on the Nexus failed,
                # so this delete_port request has failed. For
                # consistency, roll back the Nexus database to what
                # it was before this request.
                with excutils.save_and_reraise_exception():
                    nxos_db.add_nexusport_binding(row.port_id,
                                                  row.vlan_id,
                                                  row.switch_ip,
                                                  row.instance_id)
コード例 #2
0
ファイル: mech_cisco_nexus.py プロジェクト: rhel-osp/neutron
    def delete_port_precommit(self, context):
        """Delete port pre-database commit event.

        Delete port bindings from the database and scan whether the network
        is still required on the interfaces trunked.
        """

        if not self._is_deviceowner_compute(context.current):
            return

        port = context.current
        device_id = port['device_id']
        vlan_id = self._get_vlanid(context)

        if not vlan_id or not device_id:
            return

        # Delete DB row for this port
        try:
            row = nxos_db.get_nexusvm_binding(vlan_id, device_id)
        except excep.NexusPortBindingNotFound:
            return

        switch_ip = row.switch_ip
        nexus_port = None
        if row.port_id != 'router':
            nexus_port = row.port_id

        nxos_db.remove_nexusport_binding(row.port_id, row.vlan_id,
                                         row.switch_ip, row.instance_id)

        # Check for any other bindings with the same vlan_id and switch_ip
        try:
            nxos_db.get_nexusvlan_binding(row.vlan_id, row.switch_ip)
        except excep.NexusPortBindingNotFound:
            try:
                # Delete this vlan from this switch
                if nexus_port:
                    self.driver.disable_vlan_on_trunk_int(
                        switch_ip, row.vlan_id, nexus_port)
                self.driver.delete_vlan(switch_ip, row.vlan_id)
            except Exception:
                # The delete vlan operation on the Nexus failed,
                # so this delete_port request has failed. For
                # consistency, roll back the Nexus database to what
                # it was before this request.
                with excutils.save_and_reraise_exception():
                    nxos_db.add_nexusport_binding(row.port_id, row.vlan_id,
                                                  row.switch_ip,
                                                  row.instance_id)
コード例 #3
0
 def _remove_binding_from_db(self, npb):
     """Removes a port binding from the Nexus database."""
     return nexus_db_v2.remove_nexusport_binding(
         npb.port, npb.vlan, npb.switch, npb.instance)