Esempio n. 1
0
def get_response_body(resp):
    body = resp.content
    if "application/json" in resp.headers.get("content-type", ""):
        try:
            body = resp.json()
        except ValueError:
            LOG.error(_LE("Could not decode response body as JSON"))
    else:
        body = None
    return body
Esempio n. 2
0
def get_response_body(resp):
    body = resp.content
    if 'application/json' in resp.headers.get('content-type', ''):
        try:
            body = resp.json()
        except ValueError:
            LOG.error(_LE('Could not decode response body as JSON'))
    else:
        body = None
    return body
Esempio n. 3
0
def get_response_body(resp):
    body = resp.content
    if 'application/json' in resp.headers.get('content-type', ''):
        try:
            body = resp.json()
        except ValueError:
            LOG.error(_LE('Could not decode response body as JSON'))
    else:
        body = None
    return body
Esempio n. 4
0
 def clear_hook(stack_id, resource_name, hook_type):
     try:
         hc.resources.signal(
             stack_id=stack_id,
             resource_name=resource_name,
             data={'unset_hook': hook_type})
     except exc.HTTPNotFound:
         logger.error(
             _LE("Stack %(stack)s or resource %(resource)s not found"),
             {'resource': resource_name, 'stack': stack_id})
Esempio n. 5
0
def clear_hook(hc, stack_id, resource_name, hook_type):
    try:
        hc.resources.signal(stack_id=stack_id,
                            resource_name=resource_name,
                            data={'unset_hook': hook_type})
    except exc.HTTPNotFound:
        logger.error(
            _LE("Stack %(stack)s or resource %(resource)s"
                "not found for hook %(hook_type)"), {
                    'resource': resource_name,
                    'stack': stack_id,
                    'hook_type': hook_type
                })
Esempio n. 6
0
    def json_request(self, method, url, **kwargs):
        kwargs.setdefault('headers', {})
        kwargs['headers'].setdefault('Content-Type', 'application/json')
        kwargs['headers'].setdefault('Accept', 'application/json')

        if 'data' in kwargs:
            kwargs['data'] = jsonutils.dumps(kwargs['data'])

        resp = self._http_request(url, method, **kwargs)
        body = resp.content
        if 'application/json' in resp.headers.get('content-type', ''):
            try:
                body = resp.json()
            except ValueError:
                LOG.error(_LE('Could not decode response body as JSON'))
        else:
            body = None

        return resp, body
Esempio n. 7
0
    def json_request(self, method, url, **kwargs):
        kwargs.setdefault('headers', {})
        kwargs['headers'].setdefault('Content-Type', 'application/json')
        kwargs['headers'].setdefault('Accept', 'application/json')

        if 'data' in kwargs:
            kwargs['data'] = jsonutils.dumps(kwargs['data'])

        resp = self._http_request(url, method, **kwargs)
        body = resp.content
        if 'application/json' in resp.headers.get('content-type', ''):
            try:
                body = resp.json()
            except ValueError:
                LOG.error(_LE('Could not decode response body as JSON'))
        else:
            body = None

        return resp, body