Monday, October 9, 2017

Provisioning an OpenStack Instance by making a CURL REST API call to NOVA API Openstack Ocata

Provisioning an OpenStack Instance by making a CURL REST API call to NOVA API Openstack Ocata


# make a rest API call to the keystone to get an authentication token 
# first get an authentication token making an API call to Keystone REST API
# This Auth token will be used in the further REST API calls in the POST header as X-Auth-Token

# get an auth tokem
curl -d '
   {"auth": {
      "tenantName": "admin",
      "passwordCredentials": {
        "username": "admin",
        "password": "secretpassword"
       }
     }
   }' \
   -H "Content-type: application/json" \
   "http://11.11.1.158:5000/v2.0/tokens" | python -mjson.tool

# the above CURL command generates an AUTH token. This Auth token is used in the subsequent CURL request as needed. Please note that the Auth tokens are valid for 1 hour.
# this also generates the endpoint information to which the username (above admin) has access to

this is a string as "gAAAAABZ2b60ayDnimL-T8Mxmpu195zodM3772pl6n6eb_1rZWS5H-3MUrMZm6rQqk4juJ3DymcfCGETm3jw__JKY2yfD8UkINGdq7a0aXUzbNDoCQnXJjVGTjjchYpsxjGC_eWD2MyUZwo5ITp_0NPNWxpbUw12hn2GX85umjqIgbqOEvV3BpM"




# Make an API call to Nova REST API
# the URL contains the Nova Port 8774 and the admin tenant project ID as f4b62d0d71f44126bd22c2f04251b3f1
# Also the -H for Content-type application/json is here 
# the -d shows the JSON body data that has to be sent by the CURL POST call to the Nova API
# Please note that the appropriate security group for the instance can be sent to the NOVA API in the JSON data 


curl -X POST http://11.11.1.158:8774/v2.1/f4b62d0d71f44126bd22c2f04251b3f1/servers -H "X-Auth-Token: gAAAAABZ2b60ayDnimL-T8Mxmpu195zodM3772pl6n6eb_1rZWS5H-3MUrMZm6rQqk4juJ3DymcfCGETm3jw__JKY2yfD8UkINGdq7a0aXUzbNDoCQnXJjVGTjjchYpsxjGC_eWD2MyUZwo5ITp_0NPNWxpbUw12hn2GX85umjqIgbqOEvV3BpM" -H "Content-Type: application/json" -d '{"server": {"min_count": 1, "flavorRef": "1", "name": "foobar", "imageRef": "d66b73e7-cb0c-42c5-bf73-d5bbdf245da5", "max_count": 1, "networks": [ { "uuid": "13e0d04f-9f41-46ae-8dfa-adea11dea898"} ] }}'


# Get the list of all the Floating IP currently if you want to use an existing free Floating IP
# Make an API call to Neutron REST API
# the URL contains the Nova Port 9696 and the admin tenant project ID as f4b62d0d71f44126bd22c2f04251b3f1
# Also the -H for Content-type application/json is here 


curl -X GET "http://11.11.1.158:9696/v2.0/floatingips" -H "X-Auth-Token: gAAAAABZ2b60ayDnimL-T8Mxmpu195zodM3772pl6n6eb_1rZWS5H-3MUrMZm6rQqk4juJ3DymcfCGETm3jw__JKY2yfD8UkINGdq7a0aXUzbNDoCQnXJjVGTjjchYpsxjGC_eWD2MyUZwo5ITp_0NPNWxpbUw12hn2GX85umjqIgbqOEvV3BpM"


#Creation of a floating IP also the association


# Make an API call to Neutron REST API
# the URL contains the Nova Port 9696 and the admin tenant project ID as f4b62d0d71f44126bd22c2f04251b3f1
# Also the -H for Content-type application/json is here
# This has the X-Auth-Token with the Authentication token that is sent as the header

curl -X POST http://11.11.1.158:9696/v2.0/floatingips -H "X-Auth-Token: gAAAAABZ2b60ayDnimL-T8Mxmpu195zodM3772pl6n6eb_1rZWS5H-3MUrMZm6rQqk4juJ3DymcfCGETm3jw__JKY2yfD8UkINGdq7a0aXUzbNDoCQnXJjVGTjjchYpsxjGC_eWD2MyUZwo5ITp_0NPNWxpbUw12hn2GX85umjqIgbqOEvV3BpM" -d '{
    "floatingip": {
        "floating_network_id": "27d8c6cd-f905-48db-bcc7-d36f36bfecc7",
        "port_id": "9f761f26-c49b-40ef-a568-18a2d0ff25bb",
        "description": "floating ip for testing"
    }
}'


No comments:

Post a Comment