1.首先通过编辑器将如下内容写入token-requset.json
{
"auth": {
"identity": {
"methods": [
"password"
],
"password": {
"user": {
"domain": {
"name": "Default"
},
"name": "admin",
"password": "$PASSWORD"
}
}
},
"scope": {
"project": {
"domain": {
"name": "Default"
},
"name": "admin"
}
}
}
}
2.为了方便将token设为变量TOKEN
TOKEN=`curl -si -d @token-request.json -H "Content-type: application/json" http://localhost:35357/v3/auth/tokens | awk '/X-Subject-Token/ {print $2}'`
3.举例
#列出domain
curl -si -H"X-Auth-Token:$TOKEN" -H "Content-type: application/json" http://localhost:35357/v3/domains
结果:
HTTP/1.1 200 OK
Date: Thu, 09 Feb 2017 06:03:15 GMT
Server: Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5
Vary: X-Auth-Token
x-openstack-request-id: req-666baa76-025f-406a-a4c9-3433d209b3b3
Content-Length: 303
Content-Type: application/json
{"domains": [{"links": {"self": "http://localhost:35357/v3/domains/28b49b2aab5745e3b70bcaae31d6c7ca"}, "description": "Default Domain", "name": "default", "enabled": true, "id": "28b49b2aab5745e3b70bcaae31d6c7ca"}], "links": {"self": "http://localhost:35357/v3/domains", "previous": null, "next": null}}
#列出user
curl -si -H"X-Auth-Token:$TOKEN" -H "Content-type: application/json" http://localhost:35357/v3/users
结果:
HTTP/1.1 200 OK
Date: Thu, 09 Feb 2017 06:04:28 GMT
Server: Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5
Vary: X-Auth-Token
x-openstack-request-id: req-e164b49e-1ba3-4ddd-9962-6fae3ae86936
Content-Length: 1129
Content-Type: application/json
{"users": [{"name": "glance", "links": {"self": "http://localhost:35357/v3/users/6c347306068b45078e888071062d967b"}, "domain_id": "28b49b2aab5745e3b70bcaae31d6c7ca", "enabled": true, "id": "6c347306068b45078e888071062d967b", "default_project_id": "b5f70a0341ea4e20a454b4d0b72aebb5"}, {"name": "nova", "links": {"self": "http://localhost:35357/v3/users/6d6471538d824a6685f8ce970ae49f6b"}, "domain_id": "28b49b2aab5745e3b70bcaae31d6c7ca", "enabled": true, "id": "6d6471538d824a6685f8ce970ae49f6b", "default_project_id": "b5f70a0341ea4e20a454b4d0b72aebb5"}, {"name": "neutron", "links": {"self": "http://localhost:35357/v3/users/723241a45b9748be9136c1df15da47b6"}, "domain_id": "28b49b2aab5745e3b70bcaae31d6c7ca", "enabled": true, "id": "723241a45b9748be9136c1df15da47b6", "default_project_id": "b5f70a0341ea4e20a454b4d0b72aebb5"}, {"name": "admin", "links": {"self": "http://localhost:35357/v3/users/df9e6dce8f0a479c874a324a8c0a3ce5"}, "enabled": true, "id": "df9e6dce8f0a479c874a324a8c0a3ce5", "domain_id": "28b49b2aab5745e3b70bcaae31d6c7ca"}], "links": {"self": "http://localhost:35357/v3/users", "previous": null, "next": null}}