which api to be used to get uuid of compute host?

asked 2014-05-08 00:56:55 -0600

manish gravatar image

I have a openstack setup with one controller and couple of compute host. is there any compute-api which can provide uuid of the host.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2014-05-08 02:30:21 -0600

SGPJ gravatar image

updated 2014-05-08 03:53:33 -0600

You can even get host using same program:

def _get_host_id(instance):
    host = instance.get("host")
    project = str(instance.get("project_id"))
    if host:
        sha_hash = hashlib.sha224(project + host)  # pylint: disable=E1101
        return sha_hash.hexdigest()

Alternative way to get list of host using single api call using dashboard api: https://github.com/openstack/horizon/... link

def hypervisor_list(request):
return novaclient(request).hypervisors.list()

def hypervisor_stats(request): return novaclient(request).hypervisors.statistics()

def hypervisor_search(request, query, servers=True): return novaclient(request).hypervisors.search(query, servers)

edit flag offensive delete link more


The function _get_host_id function is taking project id as well for generation id for host. so it defeats the purpose for me because host will be shared across tenants/projects and this code will generate different ids at cloud level for same host. so it can not be considered as UUID for host of a cloud. Can you point me to script which is called for "/v2/<tenant-id>/os-hypervisors/detail" api call.

manish gravatar imagemanish ( 2014-05-08 04:18:40 -0600 )edit

You can get all the hyper-visor list only with admin privileges. so here project is admin. With other project like demo you cannot retrieve the hyper-visor list of all tenants/ host.

SGPJ gravatar imageSGPJ ( 2014-05-08 09:51:27 -0600 )edit

answered 2014-05-08 01:27:20 -0600

SGPJ gravatar image

updated 2014-05-08 02:27:24 -0600

Yes, please look into below nova api code to get uuid of the instance. nova api link

def show(self, request, instance):
        """Detailed view of a single instance."""
        ip_v4 = instance.get('access_ip_v4')
        ip_v6 = instance.get('access_ip_v6')
        server = {
            "server": {
                "id": instance["uuid"],
                "name": instance["display_name"],
                "status": self._get_vm_status(instance),
                "tenant_id": instance.get("project_id") or "",
                "user_id": instance.get("user_id") or "",
                "metadata": self._get_metadata(instance),
                "hostId": self._get_host_id(instance) or "",
                "image": self._get_image(request, instance),
                "flavor": self._get_flavor(request, instance),
                "created": timeutils.isotime(instance["created_at"]),
                "updated": timeutils.isotime(instance["updated_at"]),
                "addresses": self._get_addresses(request, instance),
                "accessIPv4": str(ip_v4) if ip_v4 is not None else '',
                "accessIPv6": str(ip_v6) if ip_v6 is not None else '',
                "links": self._get_links(request,


edit flag offensive delete link more


Thanks for reply,

The code snippet you have provided is for VM/instance, what i am looking for is hypervisor uuid. But when i am running /v2/<tenant-id>/os-hypervisors/detail command it is displaying host name instead of uuid. { "service": { "host": "cognac", "id": 7 }, }

here in this output value o host should be uuid as per the documentation.

manish gravatar imagemanish ( 2014-05-08 01:46:46 -0600 )edit

Thanks again Ganesh for reply but here i will get the host uuid while querying for VMs. Actually what my requirement, i want to get information about all the compute hosts using one api call. So when i request hypervisor details the response should include uuid of host as well along with name. is there existing api which provide this information. The curl command which i mention should provide same as per documentation ( http://docs.openstack.org/api/opensta... ) but it isn't.

manish gravatar imagemanish ( 2014-05-08 03:01:04 -0600 )edit

I have mentioned in the answer and follow this link

SGPJ gravatar imageSGPJ ( 2014-05-08 03:27:38 -0600 )edit

Hi manish, I have the same question. Were you able to find the answer?

Tom gravatar imageTom ( 2016-01-04 07:39:29 -0600 )edit

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2014-05-08 00:56:55 -0600

Seen: 3,624 times

Last updated: May 08 '14