Ask Your Question
1

Nova REST API: --user-data equivalent

asked 2013-11-03 11:42:12 -0500

monitorjbl gravatar image

This is probably going to turn out to be a silly question, but I've been unable to figure it out myself. I can create a new server and have a script run at create time from the command line like this:

nova boot --user-data ./run.sh --image Ubuntu-Basic --flavor m1.small myinstance

And I can create a new server from the REST API by encoding the script in Base64 and sending this:

{
   "server": {
      "flavorRef": "http://192.168.1.200:8774/65b1d52d220c4599a1211d13b46c9b8e/flavors/2",
      "imageRef": "http://192.168.1.200:8774/v2/65b1d52d220c4599a1211d13b46c9b8e/images/a3253101-3421-48b4-9d4d-78ae45bec1c9",
      "name": "test-2",
      "personality": [
         {
            "contents":"<Base64 encoded script>",
            "path":"/tmp/run.sh"
         }
       ]
    }
}

When I do it from the command line, the script gets run at create time. However, when I do it from the REST API, it just gets copied into the provided path and never seems to get run. Is there a way to mimic the --user-data behavior from the REST API? Or is there a better/different way of getting scripts into the server to run at create time?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2013-11-03 14:52:04 -0500

monitorjbl gravatar image

I dug through the source code for Nova's API, and I found that it's looking for a field called "user_data". I didn't see this in the API documentation for server creation, but I may have been looking in the wrong place. The beautiful thing about open source is that you can always go find what you need in the code :)

At any rate, this is what the JSON looks like. Hope it helps someone in the future!

{
   "server": {
      "flavorRef": "http://192.168.1.200:8774/65b1d52d220c4599a1211d13b46c9b8e/flavors/2",
      "imageRef": "http://192.168.1.200:8774/v2/65b1d52d220c4599a1211d13b46c9b8e/images/a3253101-3421-48b4-9d4d-78ae45bec1c9",
      "name": "test-2",
      "user_data":"<Base64 encoded script>",
    }
}
edit flag offensive delete link more

Comments

1

In future if you want to see what the REST API equivalent of the nova command line is, add the --debug flag to the nova command line arguments. It will then show you the detail of the REST API requests it make.

cyeoh-0 gravatar imagecyeoh-0 ( 2013-11-22 07:16:30 -0500 )edit

It'd also be worth submitting a bug report about the missing documentation here https://bugs.launchpad.net/openstack-manuals%3C/p%3E (https://bugs.launchpad.net/openstack-manuals)

cyeoh-0 gravatar imagecyeoh-0 ( 2013-11-22 07:16:43 -0500 )edit
0

answered 2014-04-13 09:37:50 -0500

gpanda gravatar image

A good way to find the request/response details is to open debug option of OpenStack CLI, which is --debug, just like cyeoh-0 said.

nova --debug boot --config-drive=true --user-data ./cloud.cfg --key-name cloud_init_test --file ~/gpanda/person_file_1=person_files/person_file_1 --image ci_image_x --flavor 3 --nic net-id=81100ebe-46b3-4a20-8e67-d4d0ef7e5dc8,v4-fixed-ip=IP vm_a

Then a series of curl http REQ/RESP show up, the major one for this nova boot is like:

REQ: curl -i 'https://"HOST"/openstack/compute/v2/17c760d7e8144f8cabf01ef260c80e85/servers' -X POST -H "X-Auth-Project-Id: ibm-default" -H "User-Agent: python-novaclient" -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token: 330af453c51e4923b7f8e74cc354c2c2" -d '{"server": {"name": "vm_a", "imageRef": "62b91d66-4ec9-41ea-b6f7-cc6eb556b10d", "key_name": "cloud_init_test", "flavorRef": "3", "user_data": "base64_encoded_user_data_file_content", "max_count": 1, "min_count": 1, "personality": [{"path": "/root/gpanda/person_file_1", "contents": ""}], "networks": [{"fixed_ip": "THE_IP", "uuid": "81100ebe-46b3-4a20-8e67-d4d0ef7e5dc8"}], "config_drive": true}}'

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2013-11-03 11:42:12 -0500

Seen: 3,351 times

Last updated: Apr 13 '14