Always wanted to write a blog, but because of various factors have not written. Recently doing OpenStack, and OpenStack provides rest APIs to you today, briefly describe the use of the OpenStack Rest API, and refer to the following two blog posts about what a rest API can look like:
Http://www.choudan.net/2013/07/28/OpenStack-Restful-API.html
Http://www.ruanyifeng.com/blog/2011/09/restful.html
In simple terms, everything is a resource, and each resource corresponds to a URI.
We can use the rest API to send requests to OpenStack using the Linux Curl command, for example, to get tokens based on username, password, and tenant:
' Http://127.0.0.1:5000/v2.0/tokens ' " Content-type:application/json " " Accept:application/json " ' {"Auth": {"Tenantname": "admin", "passwordcredentials": {"username": "admin", "password": "Secretsecret"}}} '
But I think the use of Curl command is not very convenient, and sometimes return results are very long and long time not too good-looking, so the use of restclient, because it is in the CentOS environment to work, so under the Firefox installed a restclient plug-in, like the above request can be easily done, Add two headers, if you want to access other resources, you also need a Header:x-auth-token, select a method, and then write down in the body what you need, as follows:
Most of OpenStack's APIs are written in official documents, why most, not all, is because some are not written, and I think there are two types of things that are not written:
- Not updated in a timely manner.
- Feel no need to write, think you can guess, or can find clues from the source code. After all, it takes two brushes to get openstack.
For several APIs that are not written in the current API documentation or that do not have a detailed description of usage, such as:
- How the Admin user in OpenStack obtains all the virtual machine information under all tenant (project). The specific practice is to add the query parameter all_tenants, namely:/v2/{tenant_id}/servers/detail?all_tenants=true
- Extend the first, admin how to get a virtual machine under a tenant. /v2/{tenant_id}/servers/detail?all_tenants=true&project_id=xxx
There are a lot of APIs that can be added to the query parameter, not listed.
Another problem is that in the API documentation there is only the second half of the URL, so where the first half goes and the first half is in the endpoint created when OpenStack was installed, we can use the following command to find:
Keystone endpoint-listkeystone endpoint-get--service=xxx
In the actual coding, of course we can not write the URL in the code to die, you should check the data table to get the endpoint of each service, and then generate the full URL. Careful classmates will find that in each certification will not only return token and will return to Servicecatalog, there is the endpoint we want, we do not have to go back to the database alone.
There is a problem not to understand, I do not know whether anyone answer:
Keystone two ports, one is 5000, the other is 35357 (Adminurl). Two permissions are different, creating a user or something must be 35357. I know that OpenStack uses policy to manage the permissions of a user under a tenant. But the background is how to distinguish between 5000 and 35357, how to make 35357 can create users and 5000 cannot create users.
The OpenStack REST API uses