Update instance metadata?

Asked by Patrick Vinas on 2013-06-06

I'm running Grizzly on Ubuntu 12.04 in a small hosting company, having transitioned most of the production servers from reaaaaally old VMware images. For our internal machines that are being transitioned to openstack, because of the way we do hostnames for VMs (computer type / computer location / company division template plus the last 4 digits of the MAC address) we won't know what the hostname of the running instance should be until after the first boot. I'm working on scripting a hostname change at boot time, pulling the current hostname from the metadata service with
           curl -s -i http://169.254.169.254/latest/meta-data/hostname
and adding the mac address bit to the end. Two questions: 1) Is it possible to update the hostname in the metadata? I've tried using
           curl -X POST -d <new hostname> http://169.254.169.254/latest/meta-data/hostname
but that (obviously) won't work. So, is there another way to do it? Which brings me to my next question, 2) Is there any benefit to updating the hostname in the metadata? Or should I just not worry about it? The cloud-config script works just fine for updating the hostname in the OS internals (/etc/hosts, kernel.hostname, etc) - does the metadata even matter?

Question information

Language:
English Edit question
Status:
Solved
For:
OpenStack Compute (nova) Edit question
Assignee:
No assignee Edit question
Solved by:
Patrick Vinas
Solved:
2013-06-24
Last query:
2013-06-24
Last reply:
2013-06-16
Keith Tobin (keith-tobin) said : #1

You can update the metadata,

This is from the API document. http://api.openstack.org/api-ref.html#compute

POSTv2/{tenant_id}/servers/{server_id}/metadata
Updates metadata items.

Hope this helps.

Patrick Vinas (patrickvinas) said : #2

I may be wrong, but that reads like a mechanism to change the user-defined metadata (description, etc) from a server with access to the full nova api service. I need a mechanism to change the OpenStack in-built metadata (e.g. hostname) from a script within an instance.

Patrick Vinas (patrickvinas) said : #3

I ended up writing a script to do this indirectly by updating the SQL table