Search code examples
javaopenstack-novajclouds

Getting Tags List for OpenStack Nova Instance


I'm using Java and Jclouds SDK to interact with OpenStack Nova, i tried to get the "Tags list" for nova instances, i used the following code

String region = novaApi.getConfiguredRegions().iterator().next();
ServerApi serverApi = novaApi.getServerApi(region);
Server novaInstance = serverApi.get(TEMP_SERVERNAME);
tags = novaInstance.getMetadata();

the variable tags is a Map<String, String> but as i saw over the OpenStack documentation there is an API (/servers/{server_id}/tags) that returns list Tags here is the API link which is more of what i need than the Map<String, String>

the question is, what function in the jclouds SDK that returns that type? i couldn't find any function in the Server class that return that type

Thanks


Solution

  • The current version of jclouds doesn't support directly List Tags as per ServerApi implementation, so you can't use NovaApi to retrieve tags, directly.

    Using jclouds portable abstraction for compute, instead, you can list nodes on your OpenStack installation and retrieve the list of tags attached to the nodes in userMetadata field, as long as other details with something like:

    Set<? extends ComputeMetadata> nodes = computeService.listNodes();
    

    or

    NodeMetadata node = computeService.getNodeMetadata(id)