RHV: Restful API of version 4 under RHV 4.1 does not print same output when collecting disks, nics and statistics in contrast with version 3.

Solution Verified - Updated -

Environment

Red Hat Virtualization 4.0, 4.1

Issue

Application developed using Restful API of version 4 in RHV print different output in contrast with version 3 as below since migrating it from 3 to 4.
_Version 4

$ curl -X GET --header 'Version: 4; HTTP/1.1' --header 'Accept: application/json;detail=disks+nics+statistics;charset=utf-8' \
-u 'admin@internal:xxxxxxxxxx' --cacert '/etc/pki/ovirt-engine/ca.pem' \
https://rhv4-manager.test.redhat.com/ovirt-engine/api/v4/vms/
-- skip
}, {
  "href" : "/ovirt-engine/api/v4/vms/bc12667a-b202-41d1-8f65-3945e6e05793/nics",
  "rel" : "nics"
}, {
  "href" : "/ovirt-engine/api/v4/vms/bc12667a-b202-41d1-8f65-3945e6e05793/numanodes",
  "rel" : "numanodes"
}, {
  "href" : "/ovirt-engine/api/v4/vms/bc12667a-b202-41d1-8f65-3945e6e05793/graphicsconsoles",
  "rel" : "graphicsconsoles"
}, {
  "href" : "/ovirt-engine/api/v4/vms/bc12667a-b202-41d1-8f65-3945e6e05793/diskattachments",
  "rel" : "diskattachments"
}, {

_Version 3

$ curl -X GET --header 'Version: 3; HTTP/1.1' --header 'Accept: application/json;detail=disks+nics+statistics;charset=utf-8' \
-u 'admin@internal:xxxxxxxxxx' --cacert '/etc/pki/ovirt-engine/ca.pem' https://rhv4-manager.test.redhat.com/ovirt-engine/api/v3/vms
-- skip
    "disks" : {
      "disk" : [ {
        "alias" : "test-vm01_Disk1",
        "image_id" : "7ee1c421-1587-4be6-b79b-d74412c4829d",
        "storage_domains" : {
          "storage_domain" : [ {
            "href" : "/ovirt-engine/api/v3/storagedomains/5829238c-1edd-43d9-8dad-5f63e1b6378b",
            "id" : "5829238c-1edd-43d9-8dad-5f63e1b6378b"
          } ]
        },
        "size" : 5368709120,
        "provisioned_size" : 5368709120,
        "actual_size" : 2147483648,
        "status" : {
          "state" : "ok"
        },
        "interface" : "virtio_scsi",
        "format" : "cow",
        "sparse" : "true",
        "bootable" : "true",
        "shareable" : "false",
        "wipe_after_delete" : "true",
        "propagate_errors" : "false",
        "active" : "true",
        "quota" : {
          "id" : "30fe40f0-d359-4895-9c50-21ad3a1195a3"
        },
        "uses_scsi_reservation" : "false",
        "disk_profile" : {
          "href" : "/ovirt-engine/api/v3/diskprofiles/61f9b991-134f-4dfe-86e7-785d6b7351b6",
          "id" : "61f9b991-134f-4dfe-86e7-785d6b7351b6"
        },
        "storage_type" : "image",
        "actions" : {
          "link" : [ {
            "href" : "/ovirt-engine/api/v3/vms/bc12667a-b202-41d1-8f65-3945e6e05793/disks/a716a01b-0fe7-49e2-b13c-b31286ffa68e/activate",
            "rel" : "activate"
          }, {
            "href" : "/ovirt-engine/api/v3/vms/bc12667a-b202-41d1-8f65-3945e6e05793/disks/a716a01b-0fe7-49e2-b13c-b31286ffa68e/deactivate",
            "rel" : "deactivate"
          }, {
            "href" : "/ovirt-engine/api/v3/vms/bc12667a-b202-41d1-8f65-3945e6e05793/disks/a716a01b-0fe7-49e2-b13c-b31286ffa68e/export",
            "rel" : "export"
          }, {
            "href" : "/ovirt-engine/api/v3/vms/bc12667a-b202-41d1-8f65-3945e6e05793/disks/a716a01b-0fe7-49e2-b13c-b31286ffa68e/move",
            "rel" : "move"
          } ]
        },
        "name" : "test-vm01_Disk1",
        "href" : "/ovirt-engine/api/v3/vms/bc12667a-b202-41d1-8f65-3945e6e05793/disks/a716a01b-0fe7-49e2-b13c-b31286ffa68e",
        "id" : "a716a01b-0fe7-49e2-b13c-b31286ffa68e",
        "link" : [ {
          "href" : "/ovirt-engine/api/v3/vms/bc12667a-b202-41d1-8f65-3945e6e05793/disks/a716a01b-0fe7-49e2-b13c-b31286ffa68e/permissions",
          "rel" : "permissions"
        }, {
          "href" : "/ovirt-engine/api/v3/vms/bc12667a-b202-41d1-8f65-3945e6e05793/disks/a716a01b-0fe7-49e2-b13c-b31286ffa68e/statistics",
          "rel" : "statistics"
        } ]
      } ]
    },
    "nics" : {
      "nic" : [ {
        "network" : {
          "id" : "9d12266d-01e9-4ee8-aa8b-fd5e0887e21f"
        },
        "linked" : "true",
        "interface" : "virtio",
        "mac" : {
          "address" : "00:1a:4a:16:01:51"
        },
        "statistics" : {
          "statistic" : [ {
            "values" : {
              "value" : [ {
                "datum" : 0
              } ],
              "type" : "DECIMAL"
            },
            "type" : "GAUGE",
            "unit" : "BYTES_PER_SECOND",
            "nic" : {
              "href" : "/ovirt-engine/api/v3/vms/bc12667a-b202-41d1-8f65-3945e6e05793/nics/533a8774-79c6-4899-b4ba-be83e42e2c1f",
              "id" : "533a8774-79c6-4899-b4ba-be83e42e2c1f"
            },
-- skip

How can we get same output?

Resolution

In 4.2 the query including VM and NIC statistics as stated as below would be something like and possible to achieve same output in version 3 an 4 both:

/ovirt-engine/api/vms?follow=statistics,disk_attachments.disk,nics.statistics

However, "link-following" is not possible in previous version of RHV 4.2 so the only way I could find is to iterate VM's attributes. The simplest way to achieve this is using any of the provided SDKs.
For example, using old Python SDK:

from ovirtsdk.api import API

api = API ( url="https://rhv4-manager.test.redhat.com/ovirt-engine/api",
                     username="admin@internal",
                     password="xxxxxxx",
                     ca_file="/etc/pki/ovirt-engine/apache-ca.pem", debug=False)

for vm in api.vms.list():
    print('VM: %s' % (vm.get_name(),))

    for stat in vm.statistics.list():
       print('   %s: %s' % (stat.get_name(), stat.get_values().value[0].get_datum()))

    for disk in vm.disks.list():
        print('   disk: %s' %(disk.get_alias(),))
        for stat in disk.statistics.list():
            print('      %s: %s' % (stat.get_name(), stat.get_values().value[0].get_datum()))

    for nic in vm.nics.list():
        print('   nic: %s' %(nic.get_name(),))
        for stat in nic.statistics.list():
            print('      %s: %s' % (stat.get_name(), stat.get_values().value[0].get_datum()))

Similar examples could be provided in other languages like Java/Ruby using their SDK.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.