Counting virtual machines

Method and URI

To count all protected and unprotected virtual machines registered by IBM Spectrum Protect Plus, use a POST method and a URI:

POST    https://{hostname|IP}/api/endeavour/catalog/hypervisor/vm

Parameters

Parameter 1: action

Invoke aggregate functions. For more information about aggregate functions, see Aggregate functions.

  • Value: aggregate

  • Type: Array. Required. Available in the web user interface.

Parameter 2: filter

Optionally, you may use a filter to specify the virtualized system type: VMware vCenter, Hyper-V, or Amazon EC2. If this parameter is not used, IBM Spectrum Protect Plus counts all virtual machines. You can use the filter operation parameters that are described in Filter.

  • Example value: To search within instances that are associated with no SLA policies, use the following filter parameter:

[
    {
        "op":       "=",
        "property": "hypervisorType",
        "value":    "vmware"
    }
]

Choose one of the following virtualized systems and use the value in the filter.

Virtualized system

Value

VMware vCenter

vmware

Hyper-V

hyperv

Amazon EC2

awsec2

  • Type: JSON object. Available in the web user interface.

Data

Data 1: op

Use the COUNT() function to count the pk objects. For more information about the COUNT() function, see COUNT(). Name the output variable count.

  • Value:

[
    {
        "operation":  "count",
        "fieldname":  "pk",
        "outputname": "count"
    }
]
  • Type: Array. Required. Available in the web user interface.

Example: Count virtual machines that are managed on VMware vCenter

A Python snippet that is similar to the following example can be used to count the virtual machines that are managed by VMware vCenter Server, and registered with IBM Spectrum Protect Plus. The number includes both protected virtual machines and unprotected virtual machines.

hypevisor_type = "vmware"     # VMware vCenter
# hypevisor_type = "hyperv"   # Hyper-V
# hypevisor_type = "awsec2"   # Amazon EC2

_params = {
    "action": "aggregate",
    "filter": f'''[
        {{
             "op":       "=",
             "property": "hypervisorType",
             "value":    {hypervisor_type}
        }}
    ]'''
}

_data = f'''{{
    "op": [
        {{
            "operation":  "count",
            "fieldname":  "pk",
            "outputname": "count"
        }}
    ],
}}'''

requests.post('https://' + spp_ipv4
    + '/api/endeavour/catalog/hypervisor/vm',
    headers={...}, params=_params, data=_data, verify=...)

The request prompts a response that is structured as shown, with the HTTP status of 200 (OK).

{
    "links": {...},
    "results": [
        {
            "_id": null,
            "count": 600
        }
    ]
}