Example #1
0
    def disassociate_floating_ip(self,
                                 context,
                                 address,
                                 affect_auto_assigned=False):
        """Disassociates a floating ip from its fixed ip.

        Makes sure everything makes sense then calls _disassociate_floating_ip,
        rpc'ing to correct host if i'm not it.
        """
        floating_ip = floating_ip_obj.FloatingIP.get_by_address(
            context, address)

        # handle auto assigned
        if not affect_auto_assigned and floating_ip.auto_assigned:
            raise exception.CannotDisassociateAutoAssignedFloatingIP()

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

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

        fixed_ip = fixed_ip_obj.FixedIP.get_by_id(context,
                                                  floating_ip.fixed_ip_id)

        # send to correct host, unless i'm the correct host
        network = network_obj.Network.get_by_id(context.elevated(),
                                                fixed_ip.network_id)
        interface = floating_ip.interface
        if network.multi_host:
            instance = instance_obj.Instance.get_by_uuid(
                context, fixed_ip.instance_uuid)
            service = service_obj.Service.get_by_host_and_topic(
                context.elevated(), instance.host, CONF.network_topic)
            if service and self.servicegroup_api.service_is_up(service):
                host = instance.host
            else:
                # NOTE(vish): if the service is down just deallocate the data
                #             locally. Set the host to local so the call will
                #             not go over rpc and set interface to None so the
                #             teardown in the driver does not happen.
                host = self.host
                interface = None
        else:
            host = network.host

        if host == self.host:
            # i'm the correct host
            self._disassociate_floating_ip(context, address, interface,
                                           fixed_ip.instance_uuid)
        else:
            # send to correct host
            self.network_rpcapi._disassociate_floating_ip(
                context, address, interface, host, fixed_ip.instance_uuid)
Example #2
0
 def fake_disassociate_floating_ip(*args, **kwargs):
     raise exception.FloatingIpNotAssociated(args[3])