コード例 #1
0
    def prevent_l3_port_deletion(self, context, port_id):
        """Checks to make sure a port is allowed to be deleted.

        Raises an exception if this is not the case.  This should be called by
        any plugin when the API requests the deletion of a port, since some
        ports for L3 are not intended to be deleted directly via a DELETE
        to /ports, but rather via other API calls that perform the proper
        deletion checks.
        """
        port_db = self._get_port(context, port_id)
        if port_db['device_owner'] in [
                DEVICE_OWNER_ROUTER_INTF, DEVICE_OWNER_ROUTER_GW,
                DEVICE_OWNER_FLOATINGIP
        ]:
            # Raise port in use only if the port has IP addresses
            # Otherwise it's a stale port that can be removed
            fixed_ips = port_db['fixed_ips'].all()
            if fixed_ips:
                raise l3.L3PortInUse(port_id=port_id,
                                     device_owner=port_db['device_owner'])
            else:
                LOG.debug(
                    _("Port %(port_id)s has owner %(port_owner)s, but "
                      "no IP address, so it can be deleted"), {
                          'port_id': port_db['id'],
                          'port_owner': port_db['device_owner']
                      })
コード例 #2
0
 def prevent_l3_port_deletion(self, context, port_id):
     """ Checks to make sure a port is allowed to be deleted, raising
     an exception if this is not the case.  This should be called by
     any plugin when the API requests the deletion of a port, since
     some ports for L3 are not intended to be deleted directly via a
     DELETE to /ports, but rather via other API calls that perform the
     proper deletion checks.
     """
     port_db = self._get_port(context, port_id)
     if port_db['device_owner'] in [DEVICE_OWNER_ROUTER_INTF,
                                    DEVICE_OWNER_ROUTER_GW,
                                    DEVICE_OWNER_FLOATINGIP]:
         raise l3.L3PortInUse(port_id=port_id,
                              device_owner=port_db['device_owner'])