Fetching a service usage of a tenant

Tenants and personal tenants provide metrics of service usage on level of offering items.

Personal tenant represents a tenant bound to a specific user account, and is used only to control user account quotas and to collect user account real usage of a service.

Tenant service usage object structure

Name

Value type

Description

tenant_uuid

UUID string

The UUID of the tenant related to this usage.

application_id

UUID string

The UUID of the service this usage belongs to.

edition

string

The edition of the usage.

infra_id

UUID string

The UUID of the storage related to this offering item. Present only if type is infra.

measurement_unit

string

The measurement unit. Refer to the list of available measurement units

name

string

The name of the usage with edition prefix.

offering_item

offering item object

An object that contains quota and status of the offering item. Present only if the usage has related offering item.

range_start

string

ISO 8601 date and time since the usage collection has been started. By default, it is the first day of current month.

usage_name

string

A name of the usage without edition prefix.

value

number

Current value of the usage.

absolute_value

number

Accumulated value of the usage.

tenant_id

number

API v1 ID of the tenant.

type

string

Type of the usage. Since the usages share the types with offering items, see the list of available offering item types.

Example tenant service usage

{
    "absolute_value": 0,
    "application_id": "6e6d758d-8e74-3ae3-ac84-50eb0dff12eb",
    "edition": "standard",
    "infra_id": "019097a6-114f-4418-bd54-e01ef049f209",
    "measurement_unit": "bytes",
    "name": "storage",
    "usage_name": "storage",
    "offering_item": {
        "quota": {
            "overage": null,
            "value": null,
            "version": 0
        },
        "status": 1
    },
    "range_start": "2019-08-01T00:00:00",
    "tenant_id": 1326401,
    "type": "infra",
    "value": 0
}

Step-by-step procedure

  1. Authenticate to the cloud platform via the Python shell.

    The following variables should be available now:

    >>> base_url  # the base URL of the API
    'https://eu2-cloud.acronis.com/api/2'
    >>> auth  # the 'Authorization' header value with the access token
    {'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6ImMwMD...'}
    >>> tenant_id  # the UUID of the tenant to which the token provides access
    'ede9f834-70b3-476c-83d9-736f9f8c7dae'
    
  2. Collect the tenant UUIDs using search and define an array to store them. The following variable will be used as an example:

    >>> tenant_ids
    ['d8515984-648a-4a38-9aeb-c91ec704ccda', '6838f6a2-42b4-44a3-8c7f-2a796185951c']
    
  3. Define a variable named params, and then assign the tenants query string parameter to this variable:

    >>> params = {
    ...     'tenants': ','.join(tenant_id)
    ... }
    

    Name

    Value type

    Required

    Description

    tenants

    string

    Yes

    Comma-separated tenant UUIDs.

  4. Send a GET request to the /tenants/usages endpoint:

    >>> response = requests.get(f'{base_url}/tenants/usages', headers=auth, params=params)
    
  5. Check the status code of the response:

    >>> response.status_code
    200
    

    Status code 200 means that the request was successful.

    A different status code means that an error has occurred. For the details, refer to “Status and error codes”.

    Also, the response body contains the items array with usages of provided tenants formatted as a JSON text. When converted to an object, it will look as follows:

    >>> pprint.pprint(response.json())
    {'items': [{'tenant': 'd8515984-648a-4a38-9aeb-c91ec704ccda',
                'usages': [{'absolute_value': 0,
                            'application_id': '6e6d758d-8e74-3ae3-ac84-50eb0dff12eb',
                            'edition': 'standard',
                            'infra_id': '019097a6-114f-4418-bd54-e01ef049f209',
                            'measurement_unit': 'bytes',
                            'name': 'storage',
                            'usage_name': 'storage',
                            'offering_item': {'quota': {'overage': None,
                                                        'value': None,
                                                        'version': 0},
                                              'status': 1},
                            'range_start': '2019-08-01T00:00:00',
                            'tenant_id': 1326401,
                            'type': 'infra',
                            'value': 0}, ...]},
                {'tenant': '6838f6a2-42b4-44a3-8c7f-2a796185951c',
                'usages': [{'absolute_value': 0,
                            'application_id': '6e6d758d-8e74-3ae3-ac84-50eb0dff12eb',
                            'edition': 'standard',
                            'infra_id': '019097a6-114f-4418-bd54-e01ef049f209',
                            'measurement_unit': 'bytes',
                            'name': 'storage',
                            'usage_name': 'storage',
                            'offering_item': {'quota': {'overage': None,
                                                        'value': None,
                                                        'version': 0},
                                              'status': 1},
                            'range_start': '2019-08-01T00:00:00',
                            'tenant_id': 1318423,
                            'type': 'infra',
                            'value': 0}, ...]}]}