'Detach an interface from an instance.'

@wsgi.response(202)
@extensions.expected_errors((404, 409, 501))
def delete(self, req, server_id, id):

    context = req.environ['nova.context']
    context.can(ai_policies.BASE_POLICY_NAME)
    context.can((ai_policies.POLICY_ROOT % 'delete'))
    port_id = id
    instance = common.get_instance(self.compute_api, context, server_id, expected_attrs=['device_metadata'])
    try:
        self.compute_api.detach_interface(context, instance, port_id=port_id)
    except exception.PortNotFound as e:
        raise exc.HTTPNotFound(explanation=e.format_message())
    except exception.InstanceIsLocked as e:
        raise exc.HTTPConflict(explanation=e.format_message())
    except NotImplementedError:
        common.raise_feature_not_supported()
    except exception.InstanceInvalidState as state_error:
        common.raise_http_conflict_for_instance_invalid_state(state_error, 'detach_interface', server_id)
