For some reason, the idea of direct interaction with the various OpenStack components seemed like a good idea. The aim was to create an instance, set sane security rules, and add a public key all through the API.

I struggled with the documentation. It was a little hard to find, and what I did find seemed a little thin. However with the –debug option on the cli clients, which prints out all of the calls made to the various API endpoints as it goes along, it was game on.

First things first, we need an OpenStack environment to play with. RedHat with their RDO comes to the rescue here. Out of all the one click OpenStack tools I’ve tried, RDO has been the simplest by far. Just three simple steps. Well, if you don’t include step 0 of course: http://openstack.redhat.com/Quickstart . We also installed a machine image through the dashboard to make life a little easier.

Available images:

curl -s http://10.199.0.250:8774/v2/51ad87714b86442d9a74537d6f890060/images 
-X GET 
-H "X-Auth-Project-Id: admin" 
-H "Accept: application/json" 
-H "X-Auth-Token: 6083193874684f38865b086a8a5f4b7b" | python -mjson.tool

Available flavors:

curl -s http://10.199.0.250:8774/v2/51ad87714b86442d9a74537d6f890060/flavors 
-X GET 
-H "X-Auth-Project-Id: admin" 
-H "Accept: application/json" 
-H "X-Auth-Token: 6083193874684f38865b086a8a5f4b7b" | python -mjson.tool

Which result in the following call to actually create the instance:

curl -i http://10.199.0.250:8774/v2/51ad87714b86442d9a74537d6f890060/servers 
-X POST -H "X-Auth-Project-Id: admin" 
-H "Content-Type: application/json" 
-H "Accept: application/json" 
-H "X-Auth-Token: 6083193874684f38865b086a8a5f4b7b" 
-d '{"server": {"name": "instance1", "imageRef": "992f5732-af50-40fc-987f-25951cbce943", "key_name": "damion-flybook", "flavorRef": "3", "max_count": 1, "min_count": 1}}'

Job done.

Labs

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. sayali says:

    I am trying to do this but I get stuck after getting the token id and tenant id..I am not sure what the problem is but it tells me ‘authentication required’ when I run the next command given. Could you please tell me how to go about this.

    • Damion Parry says:

      Hello, are you substituting the values returned for the tenant and admin id’s in the following urls? This was written using folsom, I’m afraid I’ve not repeated it with either grizzly or havana

  2. st says:

    Hi, when you say to import an SSH key, do you mean to use an already created key e.g. mykey.pem -> “public_key”: “mykey.pem” that we will create with a different software correct?