コード例 #1
0
    def deallocate_floating_ip(self, context, address,
                               affect_auto_assigned=False):
        """Returns a floating IP to the pool."""
        floating_ip = objects.FloatingIP.get_by_address(context, address)

        # handle auto_assigned
        if not affect_auto_assigned and floating_ip.auto_assigned:
            return

        # make sure project owns this floating ip (allocated)
        self._floating_ip_owned_by_project(context, floating_ip)

        # make sure floating ip is not associated
        if floating_ip.fixed_ip_id:
            floating_address = floating_ip.address
            raise exception.FloatingIpAssociated(address=floating_address)

        # clean up any associated DNS entries
        self._delete_all_entries_for_ip(context,
                                        floating_ip.address)
        payload = dict(project_id=floating_ip.project_id,
                       floating_ip=str(floating_ip.address))
        self.notifier.info(context, 'network.floating_ip.deallocate', payload)

        objects.FloatingIP.deallocate(context, address)
コード例 #2
0
    def deallocate_floating_ip(self,
                               context,
                               address,
                               affect_auto_assigned=False):
        """Returns a floating ip to the pool."""
        floating_ip = floating_ip_obj.FloatingIP.get_by_address(
            context, address)

        # handle auto_assigned
        if not affect_auto_assigned and floating_ip.auto_assigned:
            return
        use_quota = not floating_ip.auto_assigned

        # make sure project owns this floating ip (allocated)
        self._floating_ip_owned_by_project(context, floating_ip)

        # make sure floating ip is not associated
        if floating_ip.fixed_ip_id:
            floating_address = floating_ip.address
            raise exception.FloatingIpAssociated(address=floating_address)

        # clean up any associated DNS entries
        self._delete_all_entries_for_ip(context, floating_ip.address)
        payload = dict(project_id=floating_ip.project_id,
                       floating_ip=str(floating_ip.address))
        self.notifier.info(context, 'network.floating_ip.deallocate', payload)

        project_id = floating_ip.project_id
        # Get reservations...
        try:
            if use_quota:
                reservations = QUOTAS.reserve(context,
                                              project_id=project_id,
                                              floating_ips=-1)
            else:
                reservations = None
        except Exception:
            reservations = None
            LOG.exception(
                _("Failed to update usages deallocating "
                  "floating IP"))

        floating_ip_ref = floating_ip_obj.FloatingIP.deallocate(
            context, address)
        # floating_ip_ref will be None if concurrently another
        # API call has also deallocated the same floating ip
        if floating_ip_ref is None:
            if reservations:
                QUOTAS.rollback(context, reservations, project_id=project_id)
        else:
            # Commit the reservations
            if reservations:
                QUOTAS.commit(context, reservations, project_id=project_id)
コード例 #3
0
ファイル: floating_ips.py プロジェクト: yuans/nova
    def deallocate_floating_ip(self,
                               context,
                               address,
                               affect_auto_assigned=False):
        """Returns a floating ip to the pool."""
        floating_ip = self.db.floating_ip_get_by_address(context, address)

        # handle auto_assigned
        if not affect_auto_assigned and floating_ip.get('auto_assigned'):
            return
        use_quota = not floating_ip.get('auto_assigned')

        # make sure project owns this floating ip (allocated)
        self._floating_ip_owned_by_project(context, floating_ip)

        # make sure floating ip is not associated
        if floating_ip['fixed_ip_id']:
            floating_address = floating_ip['address']
            raise exception.FloatingIpAssociated(address=floating_address)

        # clean up any associated DNS entries
        self._delete_all_entries_for_ip(context, floating_ip['address'])
        payload = dict(project_id=floating_ip['project_id'],
                       floating_ip=floating_ip['address'])
        notifier.notify(context,
                        notifier.publisher_id("network"),
                        'network.floating_ip.deallocate',
                        notifier.INFO,
                        payload=payload)

        # Get reservations...
        try:
            if use_quota:
                reservations = QUOTAS.reserve(context, floating_ips=-1)
            else:
                reservations = None
        except Exception:
            reservations = None
            LOG.exception(
                _("Failed to update usages deallocating "
                  "floating IP"))

        self.db.floating_ip_deallocate(context, address)

        # Commit the reservations
        if reservations:
            QUOTAS.commit(context, reservations)
コード例 #4
0
    def release_floating_ip(self, context, address,
                            affect_auto_assigned=False):
        """Remove a floating ip with the given address from a project."""

        # Note(amotoki): We cannot handle a case where multiple pools
        # have overlapping IP address range. In this case we cannot use
        # 'address' as a unique key.
        # This is a limitation of the current nova.

        # Note(amotoki): 'affect_auto_assigned' is not respected
        # since it is not used anywhere in nova code and I could
        # find why this parameter exists.

        client = neutronv2.get_client(context)
        fip = self._get_floating_ip_by_address(client, address)
        if fip['port_id']:
            raise exception.FloatingIpAssociated(address=address)
        client.delete_floatingip(fip['id'])