Tuesday, April 19, 2016

REST API samples on RDO Mitaka

Actually , down here I have followed
http://developer.openstack.org/api-guide/quick-start/api-quick-start.html
to get samples working I was forced update URI from document above.
Any URI update highlighted "green" samples provided by official Howto
failed.

File kestonerc_admin was sourced before issue REST API request,
it may be done on Controller or Compute result will be the same

[root@ip-192-169-142-127 ~(keystone_admin)]# cat  keystonerc_admin
unset OS_SERVICE_TOKEN
export OS_USERNAME=admin
export OS_PASSWORD=7049f834927e4468
export OS_AUTH_URL=http://192.169.142.127:5000/v2.0
export PS1='[\u@\h \W(keystone_admin)]\$ '

export OS_TENANT_NAME=admin
export OS_REGION_NAME=RegionOne

**************************************************************************
First run REST API request   to get OS_TOKEN ( highlighted "Yellow")
**************************************************************************

[root@ip-192-169-142-127 ~(keystone_admin)]# curl -s -X POST http://192.169.142.127: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

{
    "access": {
        "metadata": {
            "is_admin": 0,
            "roles": [
                "1cdf9d47d7104b6f986ca765f1bd645f"
            ]
        },
        "serviceCatalog": [
            {
                "endpoints": [
                    {
                        "adminURL": "http://192.169.142.127:8774/v2/b47473d8953d49b29910fc681a2ff773",
                        "id": "97b30266582041e493b97c1c4c4607e0",
                        "internalURL": "http://192.169.142.127:8774/v2/b47473d8953d49b29910fc681a2ff773",
                        "publicURL": "http://192.169.142.127:8774/v2/b47473d8953d49b29910fc681a2ff773",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "nova",
                "type": "compute"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://192.169.142.127:9696",
                        "id": "0c317d48b6f04842affe435b836c753e",
                        "internalURL": "http://192.169.142.127:9696",
                        "publicURL": "http://192.169.142.127:9696",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "neutron",
                "type": "network"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://192.169.142.127:8776/v2/b47473d8953d49b29910fc681a2ff773",
                        "id": "0c1fecafd84743cebe7840dc70ab4988",
                        "internalURL": "http://192.169.142.127:8776/v2/b47473d8953d49b29910fc681a2ff773",
                        "publicURL": "http://192.169.142.127:8776/v2/b47473d8953d49b29910fc681a2ff773",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "cinderv2",
                "type": "volumev2"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://192.169.142.127:8774/v3",
                        "id": "02aa574672bc438aaeca1b62404f4725",
                        "internalURL": "http://192.169.142.127:8774/v3",
                        "publicURL": "http://192.169.142.127:8774/v3",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "novav3",
                "type": "computev3"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://192.169.142.127:8042",
                        "id": "070aa616f054492997a5b40678dfc988",
                        "internalURL": "http://192.169.142.127:8042",
                        "publicURL": "http://192.169.142.127:8042",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "aodh",
                "type": "alarming"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://192.169.142.127:9292",
                        "id": "32b93805cacf41e68e5ce96f783c485d",
                        "internalURL": "http://192.169.142.127:9292",
                        "publicURL": "http://192.169.142.127:9292",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "Image Service",
                "type": "image"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://127.0.0.1:8776/v3/b47473d8953d49b29910fc681a2ff773",
                        "id": "1f0bb25d054c463e842a2b236c56b3fe",
                        "internalURL": "http://127.0.0.1:8776/v3/b47473d8953d49b29910fc681a2ff773",
                        "publicURL": "http://127.0.0.1:8776/v3/b47473d8953d49b29910fc681a2ff773",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "cinderv3",
                "type": "volumev3"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://192.169.142.127:8777",
                        "id": "2ba4ceef2f6b42c5bf601cc7a2a92674",
                        "internalURL": "http://192.169.142.127:8777",
                        "publicURL": "http://192.169.142.127:8777",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "ceilometer",
                "type": "metering"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://192.169.142.127:8776/v1/b47473d8953d49b29910fc681a2ff773",
                        "id": "1c2192149d0e414ab6b0a41d0469d2e4",
                        "internalURL": "http://192.169.142.127:8776/v1/b47473d8953d49b29910fc681a2ff773",
                        "publicURL": "http://192.169.142.127:8776/v1/b47473d8953d49b29910fc681a2ff773",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "cinder",
                "type": "volume"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://192.169.142.127:8080/v1/AUTH_b47473d8953d49b29910fc681a2ff773",
                        "id": "5d548d206adb429c87245b502884a68b",
                        "internalURL": "http://192.169.142.127:8080/v1/AUTH_b47473d8953d49b29910fc681a2ff773",
                        "publicURL": "http://192.169.142.127:8080/v1/AUTH_b47473d8953d49b29910fc681a2ff773",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "swift",
                "type": "object-store"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://192.169.142.127:8041",
                        "id": "4707fa88cc86495798770713d74b9bd5",
                        "internalURL": "http://192.169.142.127:8041",
                        "publicURL": "http://192.169.142.127:8041",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "gnocchi",
                "type": "metric"
            },
            {
                "endpoints": [
                    {
                        "adminURL": "http://192.169.142.127:35357/v2.0",
                        "id": "13544e1b0fcd4631aab057694f9b18bf",
                        "internalURL": "http://192.169.142.127:5000/v2.0",
                        "publicURL": "http://192.169.142.127:5000/v2.0",
                        "region": "RegionOne"
                    }
                ],
                "endpoints_links": [],
                "name": "keystone",
                "type": "identity"
            }
        ],
        "token": {
            "audit_ids": [
                "sTEp_tC3SRafHXV_SDqW5A"
            ],
            "expires": "2016-04-19T18:59:44Z",
            "id": "27c680cc964b4585bd335ea8a856ba64",   <== OS_TOKEN
            "issued_at": "2016-04-19T17:59:44.831957Z",
            "tenant": {
                "description": "admin tenant",
                "enabled": true,
                "id": "b47473d8953d49b29910fc681a2ff773", <== admin's tenant-id
                "name": "admin"
            }
        },
        "user": {
            "id": "13f372cb2598427d894c48b07b1934a6",
            "name": "admin",
            "roles": [
                {
                    "name": "admin"
                }
            ],
            "roles_links": [],
            "username": "admin"
        }
    }
}
*********************************
Now export OS_TOKEN
********************************
[root@ip-192-169-142-127 ~(keystone_admin)]# export OS_TOKEN=27c680cc964b4585bd335ea8a856ba64


**************************************************************************
Here we issue REST API request for all images uploaded to glance
**************************************************************************

[root@ip-192-169-142-127 ~(keystone_admin)]# curl -s -H "X-Auth-Token: $OS_TOKEN"   http://192.169.142.127:8774/v2/b47473d8953d49b29910fc681a2ff773/images | python -m json.tool{
    "images": [
        {
            "id": "50ada525-e618-4ee4-9268-4bfbd8396b70",
            "links": [
                {
                    "href": "http://192.169.142.127:8774/v2/b47473d8953d49b29910fc681a2ff773/images/50ada525-e618-4ee4-9268-4bfbd8396b70",
                    "rel": "self"
                },
                {
                    "href": "http://192.169.142.127:8774/b47473d8953d49b29910fc681a2ff773/images/50ada525-e618-4ee4-9268-4bfbd8396b70",
                    "rel": "bookmark"
                },
                {
                    "href": "http://192.169.142.127:9292/images/50ada525-e618-4ee4-9268-4bfbd8396b70",
                    "rel": "alternate",
                    "type": "application/vnd.openstack.image"
                }
            ],
            "name": "CentOS72Cloud-image"
        },
        {
            "id": "5b00b1a8-30d1-4e9d-bf7d-5f1abed5173b",
            "links": [
                {
                    "href": "http://192.169.142.127:8774/v2/b47473d8953d49b29910fc681a2ff773/images/5b00b1a8-30d1-4e9d-bf7d-5f1abed5173b",
                    "rel": "self"
                },
                {
                    "href": "http://192.169.142.127:8774/b47473d8953d49b29910fc681a2ff773/images/5b00b1a8-30d1-4e9d-bf7d-5f1abed5173b",
                    "rel": "bookmark"
                },
                {
                    "href": "http://192.169.142.127:9292/images/5b00b1a8-30d1-4e9d-bf7d-5f1abed5173b",
                    "rel": "alternate",
                    "type": "application/vnd.openstack.image"
                }
            ],
            "name": "VF23Cloud-image"
        },
        {
            "id": "9eafeb20-526b-43d3-af18-a20bd5bd8815",
            "links": [
                {
                    "href": "http://192.169.142.127:8774/v2/b47473d8953d49b29910fc681a2ff773/images/9eafeb20-526b-43d3-af18-a20bd5bd8815",
                    "rel": "self"
                },
                {
                    "href": "http://192.169.142.127:8774/b47473d8953d49b29910fc681a2ff773/images/9eafeb20-526b-43d3-af18-a20bd5bd8815",
                    "rel": "bookmark"
                },
                {
                    "href": "http://192.169.142.127:9292/images/9eafeb20-526b-43d3-af18-a20bd5bd8815",
                    "rel": "alternate",
                    "type": "application/vnd.openstack.image"
                }
            ],
            "name": "Ubuntu1510-image"
        },
        {
            "id": "edd00da8-4713-4b3a-83f2-40a53d930e5a",
            "links": [
                {
                    "href": "http://192.169.142.127:8774/v2/b47473d8953d49b29910fc681a2ff773/images/edd00da8-4713-4b3a-83f2-40a53d930e5a",
                    "rel": "self"
                },
                {
                    "href": "http://192.169.142.127:8774/b47473d8953d49b29910fc681a2ff773/images/edd00da8-4713-4b3a-83f2-40a53d930e5a",
                    "rel": "bookmark"
                },
                {
                    "href": "http://192.169.142.127:9292/images/edd00da8-4713-4b3a-83f2-40a53d930e5a",
                    "rel": "alternate",
                    "type": "application/vnd.openstack.image"
                }
            ],
            "name": "cirros"
        }
    ]
}

**************************************************************************
Here we issue REST API request for all  flavors in system
**************************************************************************

[root@ip-192-169-142-127 ~(keystone_admin)]# curl -s -H "X-Auth-Token: $OS_TOKEN"   http://192.169.142.127:8774/v2/b47473d8953d49b29910fc681a2ff773/flavors  | python -m json.tool
{
    "flavors": [
        {
            "id": "1",
            "links": [
                {
                    "href": "http://192.169.142.127:8774/v2/b47473d8953d49b29910fc681a2ff773/flavors/1",
                    "rel": "self"
                },
                {
                    "href": "http://192.169.142.127:8774/b47473d8953d49b29910fc681a2ff773/flavors/1",
                    "rel": "bookmark"
                }
            ],
            "name": "m1.tiny"
        },
        {
            "id": "2",
            "links": [
                {
                    "href": "http://192.169.142.127:8774/v2/b47473d8953d49b29910fc681a2ff773/flavors/2",
                    "rel": "self"
                },
                {
                    "href": "http://192.169.142.127:8774/b47473d8953d49b29910fc681a2ff773/flavors/2",
                    "rel": "bookmark"
                }
            ],
            "name": "m1.small"
        },
        {
            "id": "3",
            "links": [
                {
                    "href": "http://192.169.142.127:8774/v2/b47473d8953d49b29910fc681a2ff773/flavors/3",
                    "rel": "self"
                },
                {
                    "href": "http://192.169.142.127:8774/b47473d8953d49b29910fc681a2ff773/flavors/3",
                    "rel": "bookmark"
                }
            ],
            "name": "m1.medium"
        },
        {
            "id": "4",
            "links": [
                {
                    "href": "http://192.169.142.127:8774/v2/b47473d8953d49b29910fc681a2ff773/flavors/4",
                    "rel": "self"
                },
                {
                    "href": "http://192.169.142.127:8774/b47473d8953d49b29910fc681a2ff773/flavors/4",
                    "rel": "bookmark"
                }
            ],
            "name": "m1.large"
        },
        {
            "id": "5",
            "links": [
                {
                    "href": "http://192.169.142.127:8774/v2/b47473d8953d49b29910fc681a2ff773/flavors/5",
                    "rel": "self"
                },
                {
                    "href": "http://192.169.142.127:8774/b47473d8953d49b29910fc681a2ff773/flavors/5",
                    "rel": "bookmark"
                }
            ],
            "name": "m1.xlarge"
        }
    ]
}

*************************************************
Now ssh to Compute 192.169.142.137
**************************************************

  
  


   Same via Chrome RESTful Client