共计 7733 个字符,预计需要花费 20 分钟才能阅读完成。
如何进行 keystone rest api V3 版本测试,针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。
用户认证,默认域的 token
curl -i \
-H Content-Type: application/json \
-d
auth : {
identity : {
methods : [
password
],
password : {
user : { domain : { id : default},
name : admin ,
password : openstack
}
}
}
}
} \
http://localhost:5000/v3/auth/tokens ; echo
HTTP/1.1 201 Created
X-Subject-Token: ecfc51857b5747d2b6438f17e5e2fe0c
Vary: X-Auth-Token
Content-Type: application/json
Content-Length: 297
X-Openstack-Request-Id: req-86ba31ca-0d90-4130-b6cc-01ebfeb74b31
Date: Fri, 15 Jan 2016 02:20:34 GMT
{token : { methods : [ password], expires_at : 2016-01-15T03:20:34.170384Z , extras : {}, user : { domain : { id : default , name : Default}, id : ddce55e5af8241ec96e39e511a4928a1 , name : admin }, audit_ids : [lJW70I0bTcOl5tQ27kKP0Q], issued_at : 2016-01-15T02:20:34.170469Z }}
保存返回的 Header,
X-Subject-Token: ecfc51857b5747d2b6438f17e5e2fe0c
带上 token 和 project,获取另一个 token
curl -i \
-H Content-Type: application/json \
-d
auth : {
identity : {
methods : [
token
],
token : {
id : ecfc51857b5747d2b6438f17e5e2fe0c
}
},
scope : {
project : {
name : admin ,
domain : {
name : default
}
}
}
}
} \
http://localhost:5000/v3/auth/tokens ; echo
HTTP/1.1 201 Created
X-Subject-Token: 76d45acefa7d4b928a5573db3a5ff39e
Vary: X-Auth-Token
Content-Type: application/json
Content-Length: 4858
X-Openstack-Request-Id: req-1b637a94-66bb-4a05-83b5-b1531c85a56d
Date: Fri, 15 Jan 2016 02:32:02 GMT
{token : { methods : [ token , password], roles : [{id : a7db951cbc0040bfab9f1b9124b9e6a9 , name : admin}], expires_at : 2016-01-15T03:20:34.170384Z , project : {domain : { id : default , name : Default}, id : 9c2b1ae7eb0d48e2b7ed3b4399ee4d3d , name : admin }, catalog : [{endpoints : [{ region_id : RegionOne , url : http://172.16.10.33:8776/v1/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d , region : RegionOne , interface : internal , id : 62c8ac942c8b4930936ebc15d02016ea}, {region_id : RegionOne , url : http://172.16.10.33:8776/v1/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d , region : RegionOne , interface : public , id : 95fac1cf199345a6b30cf216ada6114a}, {region_id : RegionOne , url : http://172.16.10.33:8776/v1/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d , region : RegionOne , interface : admin , id : c8b4bd03de5b494b8dad82b811af883b}], type : volume , id : 58f08b76576c4d13b79c691fbc7cae11 , name : cinder }, {endpoints : [{ region_id : RegionOne , url : http://172.16.10.33:35357/v2.0 , region : RegionOne , interface : admin , id : 04ae0815504e4b01bb69096de2655ed7}, {region_id : RegionOne , url : http://172.16.10.33:5000/v2.0 , region : RegionOne , interface : public , id : a3e08f9bf91845cbb01ee17b4381fef8}, {region_id : RegionOne , url : http://172.16.10.33:5000/v2.0 , region : RegionOne , interface : internal , id : c4d004f6ff9449ecb4beb3a3ade79a5b}], type : identity , id : 5a7e533e712b46dcbc1b520dadc1d17f , name : keystone }, {endpoints : [{ region_id : RegionOne , url : http://172.16.10.33:8774/v2/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d , region : RegionOne , interface : public , id : 4e09a9f6eb8342feac18753b47f34014}, {region_id : RegionOne , url : http://172.16.10.33:8774/v2/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d , region : RegionOne , interface : admin , id : 96685c58c74c408fa2eb30555cd9e4e5}, {region_id : RegionOne , url : http://172.16.10.33:8774/v2/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d , region : RegionOne , interface : internal , id : e8802a42ed664c25af8f60998c503240}], type : compute_legacy , id : 7ec54c4e744c44d48e3f9fa435daabbe , name : nova_legacy }, {endpoints : [{ region_id : RegionOne , url : http://172.16.10.33:8776/v2/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d , region : RegionOne , interface : internal , id : 1ef7bbe882bf4a04a33332de35c70e84}, {region_id : RegionOne , url : http://172.16.10.33:8776/v2/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d , region : RegionOne , interface : public , id : 64b1b4be5a8548e5b1e7343feec38c3d}, {region_id : RegionOne , url : http://172.16.10.33:8776/v2/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d , region : RegionOne , interface : admin , id : 7f1635373c9b4651867bdccda1a0f8d1}], type : volumev2 , id : 874e95350ad84f0998d4a809ad4925ea , name : cinderv2 }, {endpoints : [{ region_id : RegionOne , url : http://172.16.10.33:9696/ , region : RegionOne , interface : internal , id : 4bb75d5dea254955ab0e237f44572ddf}, {region_id : RegionOne , url : http://172.16.10.33:9696/ , region : RegionOne , interface : admin , id : 6f8c2b0902a54ec39ecbeea8877ec9a7}, {region_id : RegionOne , url : http://172.16.10.33:9696/ , region : RegionOne , interface : public , id : cf888a8965944479a5df1b8007eb84db}], type : network , id : 9d207ba3d5c248fd911cfcce51ef814a , name : neutron }, {endpoints : [{ region_id : RegionOne , url : http://172.16.10.33:8774/v2.1/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d , region : RegionOne , interface : internal , id : 1b7f94fa75964ee7aa501d28573333a2}, {region_id : RegionOne , url : http://172.16.10.33:8774/v2.1/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d , region : RegionOne , interface : public , id : 3217e1bb5f114c268c74e8d1550912d6}, {region_id : RegionOne , url : http://172.16.10.33:8774/v2.1/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d , region : RegionOne , interface : admin , id : d0796d4c2ddb4a67a339908158945d49}], type : compute , id : df1c318a37ec432c82571c15ac6442c8 , name : nova }, {endpoints : [{ region_id : RegionOne , url : http://172.16.10.33:9292 , region : RegionOne , interface : admin , id : 15baf7fdf5e348e59294f1eda171dc67}, {region_id : RegionOne , url : http://172.16.10.33:9292 , region : RegionOne , interface : public , id : 1acb1f06c7d44885969e4facd2e478ae}, {region_id : RegionOne , url : http://172.16.10.33:9292 , region : RegionOne , interface : internal , id : 8c775c8498684cb1847b79a640849427}], type : image , id : e5a05e1e70894013a4533e748c9c5e87 , name : glance }], extras : {}, user : { domain : { id : default , name : Default}, id : ddce55e5af8241ec96e39e511a4928a1 , name : admin }, audit_ids : [qa8u-5naTXiolgh6vXM2Dg , lJW70I0bTcOl5tQ27kKP0Q], issued_at : 2016-01-15T02:32:02.755979Z }}
返回一个在 project 范围内的 token:X-Subject-Token: 76d45acefa7d4b928a5573db3a5ff39e
body 内包含许多 endpoint
这时就可以使用 token 向其他服务发起请求。例如:获取 flavors
curl -i -H X-Auth-Token: 76d45acefa7d4b928a5573db3a5ff39e http://localhost:8774/v2.1/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d/flavors; echo
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 1692
X-Openstack-Nova-Api-Version: 2.1
Vary: X-OpenStack-Nova-API-Version
X-Compute-Request-Id: req-58676e13-4aea-4152-acca-00ea3f87e923
Date: Fri, 15 Jan 2016 02:46:50 GMT
{flavors : [{ id : 1 , links : [{ href : http://localhost:8774/v2.1/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d/flavors/1 , rel : self}, {href : http://localhost:8774/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d/flavors/1 , rel : bookmark}], name : m1.tiny }, {id : 2 , links : [{ href : http://localhost:8774/v2.1/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d/flavors/2 , rel : self}, {href : http://localhost:8774/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d/flavors/2 , rel : bookmark}], name : m1.small }, {id : 3 , links : [{ href : http://localhost:8774/v2.1/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d/flavors/3 , rel : self}, {href : http://localhost:8774/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d/flavors/3 , rel : bookmark}], name : m1.medium }, {id : 4 , links : [{ href : http://localhost:8774/v2.1/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d/flavors/4 , rel : self}, {href : http://localhost:8774/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d/flavors/4 , rel : bookmark}], name : m1.large }, {id : 42 , links : [{ href : http://localhost:8774/v2.1/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d/flavors/42 , rel : self}, {href : http://localhost:8774/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d/flavors/42 , rel : bookmark}], name : m1.nano }, {id : 5 , links : [{ href : http://localhost:8774/v2.1/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d/flavors/5 , rel : self}, {href : http://localhost:8774/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d/flavors/5 , rel : bookmark}], name : m1.xlarge }, {id : 84 , links : [{ href : http://localhost:8774/v2.1/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d/flavors/84 , rel : self}, {href : http://localhost:8774/9c2b1ae7eb0d48e2b7ed3b4399ee4d3d/flavors/84 , rel : bookmark}], name : m1.micro }]}
关于如何进行 keystone rest api V3 版本测试问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注丸趣 TV 行业资讯频道了解更多相关知识。
正文完