Skip to content

Making Web API Calls

Revanth Kumar edited this page Dec 11, 2015 · 1 revision

How to make REST Calls to various openstack nodes?

Step 1

  • Know where various nodes are placed ie. the endpoints.
  • Go to horizon, go to Access and Security tab in the Compute tab. Click on API Access tab.

finding endpoints.png

Step 2

  • We have to request a authentication token (If we haven't done in the past) that we need to send in every call to the REST API.
#!bash
$ curl -s -X POST http://<keystone endpoint>/v2.0/tokens \
            -H "Content-Type: application/json" \
            -d '{"auth": {"tenantName": "'"$OS_TENANT_NAME"'", "passwordCredentials":
            {"username": "'"$OS_USERNAME"'", "password": "'"$OS_PASSWORD"'"}}}' \
            | python -m json.tool

#!

Note: For more information regarding authentication please look for appropriate wiki page.

Step 3

  • Since now we have the authentication token, we can start using the REST API.
#!

Note: If we encounter a 401 error while using the API, request a new token.
  • Go to the API Reference to fetch the API you need for your task and get the end point from horizon. Use the endpoint and API string to get the data.

Syntax:

#!

endpoint/API
  • For example: Use the Compute API to list flavors, as follows:
#!bash

$ curl -s -H \
            "X-Auth-Token:token" \
            <compute endpoint>/v2/tenant_id/flavors \
            | python -m json.tool

Example

Getting a token

#!bash

curl -s -X POST http://10.0.0.10:5000/v2.0/tokens \
            -H "Content-Type: application/json" \
            -d '{"auth": {"tenantName": "'"$OS_TENANT_NAME"'", "passwordCredentials":
            {"username": "'"$OS_USERNAME"'", "password": "'"$OS_PASSWORD"'"}}}' \
            | python -m json.tool

Response

#!bash

{
    "access": {
        "metadata": {
            "is_admin": 0,
            "roles": [
                "9fe2ff9ee4384b1894a90878d3e92bab",
                "aca2a975a4004ee4b00b0c2967ccfa31"
            ]
        },
        "serviceCatalog": [
            {
                "endpoints": [
                    {
                        "adminURL": "http://2.2.2.10:8774/v2/0c4234a80a9c47bdb7fa6f5b65cb7f70",
                        "id": "3185b21f4daa437ea397de4478ba8f68",
                        "internalURL": "http://2.2.2.10:8774/v2/0c4234a80a9c47bdb7fa6f5b65cb7f70",
                        "publicURL": "http://10.0.0.10:8774/v2/0c4234a80a9c47bdb7fa6f5b65cb7f70",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "nova",
                "type": "compute"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://2.2.2.10:9696",
                        "id": "c2e7e4fbc44848feb04907da68b085ec",
                        "internalURL": "http://2.2.2.10:9696",
                        "publicURL": "http://10.0.0.10:9696",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "neurton",
                "type": "network"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://2.2.2.10:8776/v2/0c4234a80a9c47bdb7fa6f5b65cb7f70",
                        "id": "53d32e579c45432d85e13812391b608e",
                        "internalURL": "http://2.2.2.10:8776/v2/0c4234a80a9c47bdb7fa6f5b65cb7f70",
                        "publicURL": "http://10.0.0.10:8776/v2/0c4234a80a9c47bdb7fa6f5b65cb7f70",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "cinderv2",
                "type": "volumev2"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://2.2.2.10:9292",
                        "id": "a38d87d73f924f50870e0a3d1d8f5ff5",
                        "internalURL": "http://2.2.2.10:9292",
                        "publicURL": "http://10.0.0.10:9292",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "glance",
                "type": "image"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://2.2.2.10:8777",
                        "id": "030689349fd5465481bc14714c2a350d",
                        "internalURL": "http://2.2.2.10:8777",
                        "publicURL": "http://10.0.0.10:8777",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "ceilometer",
                "type": "metering"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://2.2.2.10:8000/v1",
                        "id": "3c9d2c6c9f6346c1878533019c07f5c8",
                        "internalURL": "http://2.2.2.10:8000/v1",
                        "publicURL": "http://10.0.0.10:8000/v1",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "heat-cfn",
                "type": "cloudformation"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://2.2.2.10:8776/v1/0c4234a80a9c47bdb7fa6f5b65cb7f70",
                        "id": "a6e0a4e28a00413d994bb1eb110470ec",
                        "internalURL": "http://2.2.2.10:8776/v1/0c4234a80a9c47bdb7fa6f5b65cb7f70",
                        "publicURL": "http://10.0.0.10:8776/v1/0c4234a80a9c47bdb7fa6f5b65cb7f70",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "cinder",
                "type": "volume"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://2.2.2.10:8773/services/Admin",
                        "id": "0bb6788bf60d4c29be6a9e5cb5153247",
                        "internalURL": "http://2.2.2.10:8773/services/Cloud",
                        "publicURL": "http://10.0.0.10:8773/services/Cloud",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "ec2",
                "type": "ec2"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://2.2.2.10:8004/v1/0c4234a80a9c47bdb7fa6f5b65cb7f70",
                        "id": "5cc47f6fcb1041fbad65fb683d5e82bf",
                        "internalURL": "http://2.2.2.10:8004/v1/0c4234a80a9c47bdb7fa6f5b65cb7f70",
                        "publicURL": "http://10.0.0.10:8004/v1/0c4234a80a9c47bdb7fa6f5b65cb7f70",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "heat",
                "type": "orchestration"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://2.2.2.10:8080",
                        "id": "12018761ddfb498ba5a79e22e79975e0",
                        "internalURL": "http://2.2.2.10:8080/v1/AUTH_0c4234a80a9c47bdb7fa6f5b65cb7f70",
                        "publicURL": "http://10.0.0.10:8080/v1/AUTH_0c4234a80a9c47bdb7fa6f5b65cb7f70",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "swift",
                "type": "object-store"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://2.2.2.10:35357/v2.0",
                        "id": "186503409564463a9c925470f63ac765",
                        "internalURL": "http://2.2.2.10:5000/v2.0",
                        "publicURL": "http://10.0.0.10:5000/v2.0",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "keystone",
                "type": "identity"
            }
        ],
        "token": {
            "audit_ids": [
                "Ul-pQPycTCmRr3wEHKJysg"
            ],
            "expires": "2015-10-17T00:07:01Z",
            "id": "eb16343427cb47f889bfb2045ac4c1b5",
            "issued_at": "2015-10-16T23:07:01.073788",
            "tenant": {
                "description": "",
                "enabled": true,
                "id": "0c4234a80a9c47bdb7fa6f5b65cb7f70",
                "name": "UTD"
            }
        },
        "user": {
            "id": "2049797c7ee1430081469889512dd8e6",
            "name": "revanth-admin",
            "roles": [
                {
                    "name": "_member_"
                },
                {
                    "name": "admin"
                }
            ],
            "roles_links": [],
            "username": "revanth-admin"
        }
    }
}

Clone this wiki locally