OpenStack获取token值的两种方式

方法一:

使用openstack命令获取
(id的值就是token)

[root@controller1 ~]# source admin-openrc 
[root@controller1 ~]# openstack token issue
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field      | Value                                                                                                                                                                                   |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| expires    | 2020-09-03T08:51:45+0000                                                                                                                                                                |
| id         | gAAAAABfUKCRWnhK45jhOC87pxl-hH1zNuzDUTv6mQLjEXUqpTwqJ5qsr6rMUVchi30a01v3gb0Z5M5DrmKV6zkfei2o8t4pi4uVJ1EBFRVx1JEeXwx6szncV_F_i_vd6c4SVlZ5u2jhehhLVoNk71lQuZzxJZ2fgh4L3PAenEvvGnylR_gYR68 |
| project_id | 4ffc35534ae342629b9068d43ab715b8                                                                                                                                                        |
| user_id    | 82d8883b243a4d44a101179ab6b1176b                                                                                                                                                        |
+-----
方法二:

通过api的方式
(X-Subject-Token的值是token,使用admin用户获取)

[root@controller1 ~]# curl -i -X POST http://192.168.61.105:35357/v3/auth/tokens -H "Content-type: application/json" -d '{"auth": {"identity": {"methods": ["password"],"password": {"user": {"domain": {"name": "Default"},"name": "admin","password": "devops"}}},"scope": {"project": {"domain": {"name": "Default"},"name": "admin"}}}}'
HTTP/1.1 201 Created
Date: Thu, 03 Sep 2020 07:48:01 GMT
Server: Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5
X-Subject-Token: gAAAAABfUJ-xmjHJgWNckNxtUH3OyowgjoAJPF-g4hYhhsYLJIOiNX-YsG9RSdVjodFRruYX8GxRwHxQ6RX3aIuoxHPPqjgYB7D1cNmuotVyA2RYHHUyq0bhoG1hBZntqwADhXY4eei0OSeC_6q-cofYcZnGXcs-kDgS0yqncbfslgkpN_AyPzI
Vary: X-Auth-Token
x-openstack-request-id: req-cbf4efff-4efb-4a67-b262-926130ff0855
Content-Length: 4714
Content-Type: application/json

{"token": {"is_domain": false, "methods": ["password"], "roles": [{"id": "933a22c3384c4b7288df6efd76afec06", "name": "admin"}], "expires_at": "2020-09-03T08:48:01.000000Z", "project": {"domain": {"id": "default", "name": "Default"}, "id": "4ffc35534ae342629b9068d43ab715b8", "name": "admin"}, "catalog": [{"endpoints": [{"region_id": "RegionOne", "url": "http://controller1:8778", "region": "RegionOne", "interface": "public", "id": "6cffe3922f4e41c19d0d38c36a49b172"}, {"region_id": "RegionOne", "url": "http://controller1:8778", "region": "RegionOne", "interface": "internal", "id": "c3acf25b73154a159ea4b3f61e40714b"}, {"region_id": "RegionOne", "url": "http://controller1:8778", "region": "RegionOne", "interface": "admin", "id": "ff5dfa2118094ff5bb53bb9aff73bd3d"}], "type": "placement", "id": "1f2090728167429aafac127723c01930", "name": "placement"}, {"endpoints": [{"region_id": "RegionOne", "url": "http://controller1:9696", "region": "RegionOne", "interface": "admin", "id": "3b8089f6df284345920a30f023a153e1"}, {"region_id": "RegionOne", "url": "http://controller1:9696", "region": "RegionOne", "interface": "internal", "id": "44410081885a4772b1051a46499f0637"}, {"region_id": "RegionOne", "url": "http://controller1:9696", "region": "RegionOne", "interface": "public", "id": "f79ae15829d847fb9c7aa3bc375a398c"}], "type": "network", "id": "208ae53e99a14de8a18b96c92cda4fcc", "name": "neutron"}, {"endpoints": [{"region_id": "RegionOne", "url": "http://controller1:8776/v1/4ffc35534ae342629b9068d43ab715b8", "region": "RegionOne", "interface": "admin", "id": "36124846793747da9087fcb60693828c"}, {"region_id": "RegionOne", "url": "http://controller1:8776/v1/4ffc35534ae342629b9068d43ab715b8", "region": "RegionOne", "interface": "public", "id": "60abdc37d0614fa78016ed7d7f6ba570"}, {"region_id": "RegionOne", "url": "http://controller1:8776/v1/4ffc35534ae342629b9068d43ab715b8", "region": "RegionOne", "interface": "internal", "id": "b7653dad04ae4c83b56b5409246d80c5"}], "type": "volume", "id": "4f59b8f68d52472195a3520b67bf35e0", "name": "cinder"}, {"endpoints": [{"region_id": "RegionOne", "url": "http://controller1:8776/v2/4ffc35534ae342629b9068d43ab715b8", "region": "RegionOne", "interface": "internal", "id": "2699f9fc8a58443499cdf1b5bdeca1ed"}, {"region_id": "RegionOne", "url": "http://controller1:8776/v2/4ffc35534ae342629b9068d43ab715b8", "region": "RegionOne", "interface": "admin", "id": "27f01ffb97c745e39c364b09f61e7a7b"}, {"region_id": "RegionOne", "url": "http://controller1:8776/v2/4ffc35534ae342629b9068d43ab715b8", "region": "RegionOne", "interface": "public", "id": "eb560c8f37ee44d2b1864c8d0ca1c691"}], "type": "volumev2", "id": "58b2213df2eb48cf91ad935a1d3af342", "name": "cinderv2"}, {"endpoints": [{"region_id": "RegionOne", "url": "http://controller1:9292", "region": "RegionOne", "interface": "admin", "id": "23f26aa035b845429637fbc89d97667e"}, {"region_id": "RegionOne", "url": "http://controller1:9292", "region": "RegionOne", "interface": "internal", "id": "67731fc14ea649d2b8267d0174409b08"}, {"region_id": "RegionOne", "url": "http://controller1:9292", "region": "RegionOne", "interface": "public", "id": "a476bf95afae4b8b87dcca3bf2b85cdf"}], "type": "image", "id": "6498d35058324b5cac1e707381533c1b", "name": "glance"}, {"endpoints": [{"region_id": "RegionOne", "url": "http://controller1:8774/v2.1/4ffc35534ae342629b9068d43ab715b8", "region": "RegionOne", "interface": "internal", "id": "089b8db47a494e7e95a3b0462ad7ba7f"}, {"region_id": "RegionOne", "url": "http://controller1:8774/v2.1/4ffc35534ae342629b9068d43ab715b8", "region": "RegionOne", "interface": "public", "id": "4de86f6447544753a43004dbf86a7b19"}, {"region_id": "RegionOne", "url": "http://controller1:8774/v2.1/4ffc35534ae342629b9068d43ab715b8", "region": "RegionOne", "interface": "admin", "id": "ad0fc00e9fc043bbb0abc9311df495bc"}], "type": "compute", "id": "9a2ba79c1879463a9b815958eb740f9a", "name": "nova"}, {"endpoints": [{"region_id": "RegionOne", "url": "http://controller1:5000/v3", "region": "RegionOne", "interface": "public", "id": "6f599f39ee1146439c883c459096242c"}, {"region_id": "RegionOne", "url": "http://controller1:35357/v3", "region": "RegionOne", "interface": "internal", "id": "7c14797a64cd48398ba91e4e752a1158"}, {"region_id": "RegionOne", "url": "http://controller1:35357/v3", "region": "RegionOne", "interface": "admin", "id": "dabc2d45dc3a4313967ce6d511581ffa"}], "type": "identity", "id": "b52a43941f524327b1a9645e70362497", "name": "keystone"}], "user": {"password_expires_at": null, "domain": {"id": "default", "name": "Default"}, "id": "82d8883b243a4d44a101179ab6b1176b", "name": "admin"}, "audit_ids": ["2cuiQmX9RSiXMegAzBXW4A"], "issued_at": "2020-09-03T07:48:01.000000Z"}}[root@controller1 ~]# ^C
[root@controller1 ~]# curl -i -X POST http://192.168.61.105:35357/v3/auth/tokens -H "Content-type: application/json" -d '{"auth": {"identity": {"methods": ["password"],"password": {"user": {"domain": {"name": "Default"},"name": "admin","password": "devops"}}},"scope": {"project": {"domain": {"name": "Default"},"name": "admin"}}}}'^C

posted @ 2020-09-03 16:49  一毛丶丶  阅读(1987)  评论(0编辑  收藏  举报