Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically setting instance name with the OpenStack Nova API

I have resigned myself to the fact that many of the features that EC2 users are accustomed to (in particular, tagging) do not exist in OpenStack. There is, however, one piece of functionality whose absence is driving me crazy.

Although OpenStack doesn't have full support for instance tags (like EC2 does), it does have the notion of an instance name. This name is exposed by the Web UI, which even allows you to set it:

Instance Name in the instance list

Editing the Instance Name

This name is also exposed through the nova list command line utility.

However (and this is my problem) this field is not exposed through the nova-ec2 API layer. The cleanest way for them to integrate this with existing EC2 platform tools would be to simulate an instance Tag with name "Name", but they don't do this. What's more, I can't figure out which Nova API endpoint I can use to read and write the name (it doesn't seem to be documented on the API reference); but of course it must be somehow possible since the web client and nova-client can both somehow do it.

At the moment, I'm forced to change it manually from the website every time I launch a new instance. (I can't do it during instance creation because I use the nova-ec2 API, not the nova command line client).

My question is:

  1. Is there a way to read/write the instance name through the EC2 API layer?
  2. Failing that, what is the REST endpoint to set it programmatically?
  3. (BONUS): What is Nova's progress on supporting general instance tagging?
like image 887
Adrian Petrescu Avatar asked Oct 07 '22 15:10

Adrian Petrescu


1 Answers

The Python novaclient.v1_1 package has a method on the server object:

def update(self, server, name=None):
    """
    Update the name or the password for a server.

    :param server: The :class:`Server` (or its ID) to update.
    :param name: Update the server's name.
    """
    if name is None:
        return

    body = {
        "server": {
            "name": name,
        },
    }

    self._update("/servers/%s" % base.getid(server), body)

This indicates that you can update the name of a server by POST-ing the following JSON to http://nova-api:port/v2.0/servers/{server-id}:

{
  "server": {
      "name": "new_name"
  }
}

Of course, all of the usual authentication headers (namely X-Auth-Token from your Keystone server) are still required, so it is probably easier to use a client library for whatever language you prefer to manage all that.

like image 91
Drewch Avatar answered Oct 12 '22 12:10

Drewch