Linux serverNETWORK ADMINISTRATIONSredhat

OpenStack API Examples using curl

OpenStack API Examples using curl
http://fosshelp.blogspot.com/2014/11/openstack-api-examples-using-curl.html

1)
*Export keystone credentials
export OS_USERNAME=admin
export OS_PASSWORD=secret123
export OS_TENANT_NAME=demo
export OS_AUTH_URL=http://127.0.0.1:35357/v2.0

Run CLI commands with “–debug” option and copy the curl command from the output and execute it without using python client.

2)
Get Token

a)
*CLI command
#keystone –debug token-get

b)
*curl command
#curl -i -X POST http://127.0.0.1:35357/v2.0/tokens -H “Content-Type: application/json” -H “User-Agent: python-keystoneclient” -d ‘{“auth”: {“tenantName”: “demo”, “passwordCredentials”: {“username”: “admin”, “password”: “secret123”}}}’

3)
Save token into a shell script variable like
TOKEN=blablabla

4)
List all images

a)
CLI command
#glance –debug image-list

b)
*curl command
*Note: Use double quotes for -H “X-Auth-Token:$TOKEN”

#curl -i -X GET -H “X-Auth-Token:$TOKEN” -H ‘Content-Type: application/json’ -H ‘User-Agent: python-glanceclient’ http://127.0.0.1:9292/v1/images/detail?sort_key=name&sort_dir=asc&limit=20

*Replace the option “-i” with “-s” and filter with “python -mjson.tool” to get readable formatted json output
#curl -s -X GET -H “X-Auth-Token:$TOKEN” -H ‘Content-Type: application/json’ -H ‘User-Agent: python-glanceclient’ http://127.0.0.1:9292/v1/images/detail?sort_key=name&sort_dir=asc&limit=20 | python -mjson.tool

5)
List all Virtual Machines

a)
CLI command
#nova –debug list

b)
*curl command
#curl -i ‘http://127.0.0.1:8774/v1.1/02ef892087a640bcb66bd42a3ceccc79/servers/detail’ -X GET -H “X-Auth-Project-Id: demo” -H “User-Agent: python-novaclient” -H “Accept: application/json” -H “X-Auth-Token:$TOKEN”

*Replace the option “-i” with “-s” and filter with “python -mjson.tool” to get readable formatted json output
#curl -s ‘http://127.0.0.1:8774/v1.1/02ef892087a640bcb66bd42a3ceccc79/servers/detail’ -X GET -H “X-Auth-Project-Id: demo” -H “User-Agent: python-novaclient” -H “Accept: application/json” -H “X-Auth-Token:$TOKEN” | python -mjson.tool

6)
List all networks

a)
CLI command
#neutron –debug net-list

b)
*curl command
#curl -i http://127.0.0.1:9696/v2.0/networks.json -X GET -H “X-Auth-Token:$TOKEN” -H “Content-Type: application/json” -H “Accept: application/json” -H “User-Agent: python-neutronclient”

*Replace the option “-i” with “-s” and filter with “python -mjson.tool” to get readable formatted json output
#curl -s http://127.0.0.1:9696/v2.0/networks.json -X GET -H “X-Auth-Token:$TOKEN” -H “Content-Type: application/json” -H “Accept: application/json” -H “User-Agent: python-neutronclient” | python -mjson.tool

7)
List all volumes

a)
CLI command
#cinder –debug list

b)
*curl command
#curl -i http://127.0.0.1:8776/v1/02ef892087a640bcb66bd42a3ceccc79/volumes/detail -X GET -H “X-Auth-Project-Id: demo” -H “User-Agent: python-cinderclient” -H “Accept: application/json” -H “X-Auth-Token:$TOKEN”

*Replace the option “-i” with “-s” and filter with “python -mjson.tool” to get readable formatted json output
#curl -s http://127.0.0.1:8776/v1/02ef892087a640bcb66bd42a3ceccc79/volumes/detail -X GET -H “X-Auth-Project-Id: demo” -H “User-Agent: python-cinderclient” -H “Accept: application/json” -H “X-Auth-Token:$TOKEN” | python -mjson.tool

source

by Nucleus

openstack

Leave a Reply

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