<commit_before>#!/usr/bin/env python

from maas_common import (get_auth_ref, get_glance_client, status_err,
                         status_ok, metric)
import sys

IMAGE_ENDPOINT = 'http://127.0.0.1:9292'


def check(token):
    glance = get_glance_client(token, IMAGE_ENDPOINT)
    if glance is None:
        status_err('Unable to obtain valid glance client, cannot proceed')

    status_ok()
    metric('glance_api_local_status', 'uint32', 1)


def main():
    auth_ref = get_auth_ref()
    token = auth_ref['token']['id']
    check(token)


if __name__ == "__main__":
    main()<commit_msg>Make a direct call to glance-api using requests<commit_after>#!/usr/bin/env python

from maas_common import (status_ok, status_err, metric, get_keystone_client,
                         get_auth_ref)
from requests import Session
from requests import exceptions as exc


def check(auth_ref):
    keystone = get_keystone_client(auth_ref)
    tenant_id = keystone.tenant_id
    auth_token = keystone.auth_token
    registry_endpoint = 'http://127.0.0.1:9292/v2'

    api-status = 1
    milliseconds = 0

    s = Session()

    s.headers.update(
        {'Content-type': 'application/json',
         'x-auth-token': auth_token})

    try:
        # Hit something that isn't querying the glance-registry, since we
        # query glance-registry in separate checks
        r = s.get('%s/schemas/image' % registry_endpoint, verify=False,
                  timeout=10)
    except (exc.ConnectionError, exc.HTTPError, exc.Timeout):
        api_status = 0
        milliseconds = -1
    except Exception as e:
        status_err(str(e))
    else:
        milliseconds = r.elapsed.total_seconds() * 1000

        if not r.ok:
            api_status = 0

    status_ok()
    metric('glance_registry_local_status', 'uint32', api_status)
    metric('glance_registry_local_response_time', 'int32', milliseconds)


def main():
    auth_ref = get_auth_ref()
    check(auth_ref)


if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.10637230306071249, 'fraction_numerical': 0.019568489713998997, 'mean_word_length': 2.925196850393701, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3796070', 'n_tokens_mistral': 674, 'n_tokens_neox': 633, 'n_words': 152}