Updating user-data for existing Openstack VMs
I recently had the need to update the user-data assigned to many virtual machines in Openstack. There's no direct way to do this through the API. However, it can be done through the backend database. The actual user-data content is base64 encoded in the database, and there's probably a way to take the script you want and convert it, but I went with a different approach.
- Deploy a VM using the user-data you wish your pre-existing VM had
- Get the UUID for your new "good" VM - we'll call it good-uuid
- nova show goodvm | awk '$2=="id" {print}'
- Get the UUID for your old "bad" VM - we'll call it bad-uuid
- Then, in the database, set the user-data of the "bad" VM to the corresponding value of the "good" VM using a temporary table.
mysql> use nova; mysql> create temporary table instances1 like instances; mysql> insert into instances1 select * from instances where uuid = 'good-uuid'; mysql> update instances set user_data = ( select user_data from instances1 ) where uuid = 'bad-uuid' limit 1;
And that's it. You should be able to hop on your "bad" VM and check the new user-data with: curl http://169.254.169.254/latest/user-data
Naturally you can change multiple VMs by using different where clauses as needed. I confirmed this process works on grizzly and havana.