openstack curl get token in v3.0

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}}


  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值