使用curl来调试rest是十分方便高效的
http://www.cnblogs.com/gbyukg/p/3326825.html
这篇文章不错
使用curl打印出来的格式看起来比较乱,这个时候使用
http://blog.youkuaiyun.com/caomiao2006/article/details/19923509
使用 curl http://xxx | python -m json.tool 格式化输出
将打印出来的json和xml数据格式化的显示
要访问某一个服务,比如ironic需要拿到对应token,token是会过期的,24小时
第一步,拿到一个token,也包含该tenant对应tenantid
curl -d '{"auth": {"tenantName": "admin", "passwordCredentials": {"username": "admin", "password": "xxx"}}}' -H "Content-type: application/json" http://xxx:5000/v2.0/tokens | python -m json.tool
更多的信息可以参照上面curl教程中所述,加入更多的参数。
返回的数据中包含:
"token": {
"audit_ids": [
"2fZjgJTlR5ynzgciJBYptQ"
],
"expires": "2015-03-19T10:03:12Z",
"id": "f3df359ca33f40af9990aceb82574f71",
"issued_at": "2015-03-19T09:03:12.550554",
"tenant": {
"description": "admin tenant",
"enabled": true,
"id": "d63f0cca2367489780c2e29e1034c02b",
"name": "admin"
}
},
第二步,拿着这个token去访问ironic对应的服务:
curl -H "X-Auth-Token:f3df359ca33f40af9990aceb82574f71" http://xxx:6385/v1/ports/detail | python -m json.tool
输出为:
{
"ports": [
{
"address": "00:90:fa:6c:7d:7c",
"created_at": "2015-03-19T04:46:03+00:00",
"extra": {},
"links": [
{
"href": "http://xxx:6385/v1/ports/9f10c0b8-4400-4e04-8db0-e42c7f689425",
"rel": "self"
},
{
"href": "http://xxx:6385/ports/9f10c0b8-4400-4e04-8db0-e42c7f689425",
"rel": "bookmark"
}
],
"node_uuid": "8cdc7750-9d66-4353-ab3e-99fe82e739e2",
"updated_at": null,
"uuid": "9f10c0b8-4400-4e04-8db0-e42c7f689425"
}
]
}
新的keystone直接在拿token的时候舒服tenantname,比原来的keystone需要先拿到unscoped的tenant的token再拿scoped的token方便。如果没记错的话:)
ps:
对于ironic使用pecan,方法
def get_all(self, node_uuid=None, address=None, marker=None, limit=None,sort_key='id', sort_dir='asc'):
对应的rest call是:
curl -H "X-Auth-Token:791d6350c9f74d6f8d1fdce28e9c768a" http://xxxx:6385/v1/ports/?node_uuid=8cdc7750-9d66-4353-ab3e-99fe82e739e2 | python -m json.tool
方法 def get_one(self, port_uuid): 对应rest call是:
curl -H "X-Auth-Token:791d6350c9f74d6f8d1fdce28e9c768a" http://xxxx:6385/v1/ports/9f10c0b8-4400-4e04-8db0-e42c7f689425 | python -m json.tool