'Dissociate floating_ip from an instance.'

@wsgi.Controller.api_version('2.1', '2.43')
@extensions.expected_errors((400, 403, 404, 409))
@wsgi.action('removeFloatingIp')
@validation.schema(floating_ips.remove_floating_ip)
def _remove_floating_ip(self, req, id, body):

    context = req.environ['nova.context']
    context.can(fi_policies.BASE_POLICY_NAME)
    address = body['removeFloatingIp']['address']
    try:
        floating_ip = self.network_api.get_floating_ip_by_address(context, address)
    except exception.FloatingIpNotFoundForAddress:
        msg = _('floating    IP    not    found')
        raise webob.exc.HTTPNotFound(explanation=msg)
    instance = get_instance_by_floating_ip_addr(self, context, address)
    if (instance and floating_ip.get('fixed_ip_id') and ((uuidutils.is_uuid_like(id) and [(instance.uuid == id)]) or [(instance.id == id)])[0]):
        try:
            disassociate_floating_ip(self, context, instance, address)
        except exception.FloatingIpNotAssociated:
            msg = _('Floating    IP    is    not    associated')
            raise webob.exc.HTTPBadRequest(explanation=msg)
        return webob.Response(status_int=202)
    else:
        msg = (_('Floating    IP    %(address)s    is    not    associated    with    instance    %(id)s.') % {'address': address, 'id': id})
        raise webob.exc.HTTPConflict(explanation=msg)
