在运行身份管理服务的典型OpenStack部署中,可以指定用于认证的项目名、用户名和密码凭证。下面以使用cURL命令为例进行示范。
(1)首先导出环境变量OS_PROJECT_NAME(项目名)、OS_PROJECT_DOMAIN_NAME(项目域名)、OS_USERNAME(用户名)、OS_PASSWORD(密码)和OS__USER_DOMAIN_NAME(用户域名)。最简单的方式是使用客户端环境脚本文件来设置导出所需的客户端环境变量,示例如下。
首先查看下这个demo文件的内容
[root@xxh ~]# source keystonerc_demo [root@xxh ~(keystone_demo)]# env | grep OS HOSTNAME=xxh OS_USER_DOMAIN_NAME=Default OS_PROJECT_NAME=demo OS_IDENTITY_API_VERSION=3 OS_PASSWORD=9fd3b0fbb99249a0 OS_AUTH_URL=http://192.168.208.41:5000/v3 OS_USERNAME=demo OS_PROJECT_DOMAIN_NAME=Default
然后运行CURL命令向OpenStack 云平台请求一个令牌。
[root@xxh ~(keystone_demo)]# curl -v -s -X POST $OS_AUTH_URL/auth/tokens?nocatalog -H"Content-Type: applicationljson" -d'{"auth": { "identity": { "methods": ["password"],"password": {"user"{"domain": {"name": """$OS_USER_ DOMAIN_NAME"""]},"name": """$OS_USERNAME""", "password":"""$O_PASRD"""} } },"scope": { "project": { "domain": { "name": """$OS_PROJECT,DOMAIN_NAME""" }, "name": """$OS_PROJECT_NAME"""} } }' | python-m json.tool
查看令牌id
[root@xxh ~(keystone_demo)]# openstack token issue +------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Field | Value | +------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | expires | 2022-12-10T15:19:42+0000 | | id | gAAAAABjlJV-_fqt9MmiWeRG__K2DfwwSbO8GSf5NK5gY9dcyV4xQz_YJ47Q-sXZb-AlrMb6wKGnvTXB4nq0t-IvddTbAVPLzlEj2vHmmiG5D86vnttNgsKffN_xlujSeVDg4-dqIlfEipgfd7u4PODNuVeEIlZvBqMQkyKUQdEYosipN_sVYAc | | project_id | a01d69d7f54f44eca1466fef065dad76 | | user_id | 099d0ef3570a4bf0a96052649ae07de7 | +------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
执行以下命令导出环境变量OS_TOKEN,将其值设为令牌ID(上例中X-Subject-Token值
[root@xxh ~(keystone_demo)]# export OS_TOKEN=gAAAAABjlJV-_fqt9MmiWeRG__K2DfwwSbO8GSf5NK5gY9dcyV4xQz_YJ47Q-sXZb-AlrMb6wKGnvTXB4nq0t-IvddTbAVPLzlEj2vHmmiG5D86vnttNgsKffN_xlujSeVDg4-dqIlfEipgfd7u4PODNuVeEIlZvBqMQkyKUQdEYosipN_sVYAc
执行以下命令导出环境变量OS_PROJECT_NAME
export OS_PROJECT_NAME=demo
执行以下命令导出环境变量OS_COMPUTE_APl
[root@xxh ~(keystone_demo)]# export OS_COMPUTE_API=http://192.168.208.41:8774/v2.1
执行以下命令访问计算服务API,列出可用的实例
[root@xxh ~(keystone_demo)]# curl -s -H "X-Auth-Token: $OS_TOKEN" $OS_COMPUTE_API/servers | python -m json.tool
E_API/servers | python -m json.tool
{
"servers": [
{
"id": "1f11c42d-27cd-44ff-8c24-c20aec7c49c0",
"links": [
{
"href": "http://192.168.208.41:8774/v2.1/servers/1f11c42d-27cd-44ff-8c24-c20aec7c49c0",
"rel": "self"
},
{
"href": "http://192.168.208.41:8774/servers/1f11c42d-27cd-44ff-8c24-c20aec7c49c0",
"rel": "bookmark"
}
],
"name": "cirros_mko" 这个是你的实例的名称
}
]
}
标签:令牌,NAME,demo,root,认证,PROJECT,Openstack,xxh,OS From: https://www.cnblogs.com/xxh12/p/16972542.html