Obtain Compute Hosts/Hypervisor Info Using API

Problem

A user would like to use the OpenStack API to obtain information about Hosts/Hypervisors in OpenStack environment, such as current CPU usage/allocation, Memory usage/allocation, Storage usage/allocation, etc, similar to what is shown in the Clarity UI.

Environment

  • Platform9 Managed OpenStack - v3.6.0 and Higher

Procedure

  1. The following curl command using your Management Plane's Nova API endpoint can be used to get the details of a hypervisor in Platform9 Managed OpenStack.

$ curl -s -H "X-Auth-Token: $TOKEN" https://[Management Plane FQDN]/nova/v2.1/[project id]/os-hypervisors/detail |jq '.[][]'

The above will list all the details of all the hypervisors in the environment. 2. One can apply jq filters to obtain the required information from the list of hypervisors.

$ curl -s -H "X-Auth-Token: $TOKEN" https://[Management Plane FQDN]/nova/v2.1/[project id]/os-hypervisors/detail |jq '.[][]| { cpu_information: .cpu_info, hostname: .hypervisor_hostname, Memory_Used: .memory_mb_used,Free_RAM: .free_ram_mb, Free_Disk: .free_disk_gb, CPU_util: .["OS-EXT-PF9-HYP-RES"].cpu_util_percent }'

Additional Information

One can get the TOKEN and [Project Id] to be used in the command mentioned above by running the following command.

$ openstack token issue

Last updated