def check(auth_ref, args):
    keystone = get_keystone_client(auth_ref)
    auth_token = keystone.auth_token

    VOLUME_ENDPOINT = (
        'http://{hostname}:8776/v1/{tenant}'.format(hostname=args.hostname,
                                                    tenant=keystone.tenant_id)
    )

    s = requests.Session()

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

    try:
        # We cannot do /os-services?host=X as cinder returns a hostname of
        # X@lvm for cinder-volume binary
        r = s.get('%s/os-services' % VOLUME_ENDPOINT, verify=False, timeout=10)
    except (exc.ConnectionError,
            exc.HTTPError,
            exc.Timeout) as e:
        status_err(str(e))

    if not r.ok:
        status_err('Could not get response from Cinder API')

    services = r.json()['services']

    # We need to match against a host of X and X@lvm (or whatever backend)
    if args.host:
        backend = ''.join((args.host, '@'))
        services = [service for service in services
                    if (service['host'].startswith(backend) or
                        service['host'] == args.host)]

    if len(services) == 0:
        status_err('No host(s) found in the service list')

    status_ok()

    if args.host:
        all_services_are_up = True

        for service in services:
            service_is_up = True

            if service['status'] == 'enabled' and service['state'] != 'up':
                service_is_up = False
                all_services_are_up = False

            if '@' in service['host']:
                [host, backend] = service['host'].split('@')
                name = '%s-%s_status' % (service['binary'], backend)
                metric_bool(name, service_is_up)

        name = '%s_status' % service['binary']
        metric_bool(name, all_services_are_up)
    else:
        for service in services:
            service_is_up = True
            if service['status'] == 'enabled' and service['state'] != 'up':
                service_is_up = False

            name = '%s_on_host_%s' % (service['binary'], service['host'])
            metric_bool(name, service_is_up)
dataset/ETHPy150Open rcbops/rpc-openstack/maas/plugins/cinder_service_check.py/check/original