我找到了CLI或API 请求方法,它们对我有用,如下所示:
# source /etc/kolla/admin-openrc.sh
# openstack user password set --password newpsw --original-password oripsw
Or
# source /etc/kolla/admin-openrc.sh
# curl -v -s -X POST $OS_AUTH_URL/auth/tokens?nocatalog \
-H "Content-Type: application/json" \
-d '{ "auth": { "identity": { "methods": ["password"], \
"password": {"user": {"domain": {"name": "'"$OS_USER_DOMAIN_NAME"'"}, \
"name": "'"$OS_USERNAME"'", "password": "'"$OS_PASSWORD"'"} } }, \
"scope": { "project": { "domain": { "name": "'"$OS_PROJECT_DOMAIN_NAME"'" }, \
"name": "'"$OS_PROJECT_NAME"'" } } }}'
< HTTP/1.1 201 CREATED
< Date: Mon, 18 Oct 2021 11:44:39 GMT
< Server: Apache
< Content-Length: 720
< X-Subject-Token: gAAAAABhbV4o9WvatToB4Z7dUhaNqyYqpwUt4T3wwOmnN2-YCioaSYZ-HpqdWNDvAq0pvnSe6qIuvoZXOIUjmxxUu03tWk2mp2TOJ_LTLECXOHqlQT22vqNvgJj_YTgOWbwHVlrrqbkcUWM4WDvbsD1HjM8xiEYidSNMzpw2LOHtO43cIN0nyvs
< Vary: X-Auth-Token
# export OS_TOKEN=gAAAAABhbV4o9WvatToB4Z7dUhaNqyYqpwUt4T3wwOmnN2-YCioaSYZ-HpqdWNDvAq0pvnSe6qIuvoZXOIUjmxxUu03tWk2mp2TOJ_LTLECXOHqlQT22vqNvgJj_YTgOWbwHVlrrqbkcUWM4WDvbsD1HjM8xiEYidSNMzpw2LOHtO43cIN0nyvs
# curl --header "Content-Type: application/json" --request POST --data '{"user":{"password":"123","original_password":"aaa"}}' http://10.32.17.172:5000/v3/users/e1c5cc75489f4e0cbb05c39d03b46097/password
API请求文档Change password for user
最后的方法。
但是我需要通过在我们的项目中使用openstacksdk来实现这一点,我在文档中找到了最后一个方法openstacksdk
-- update_user(user, **attrs)
,这似乎是我最喜欢的。不幸的是,openstack.identity.v3.user 实例没有original_password
,我的代码无法工作:
import openstack
conn = openstack.connect(
region_name = 'RegionOne',
auth_url = 'http://10.32.17.172:35357/v3',
domain_name = 'Default',
project_name = 'admin',
username = 'admin',
password = '123'
)
user_args = {
"name":"admin",
"pasword":'aaa', # new password
"password_expires_at":None,
"links":{u'self': u'http://10.32.17.172:5000/v3/users/e1c5cc75489f4e0cbb05c39d03b46097'},
"enabled":True,
"domain_id":"default",
"original_password": "123",
}
conn.identity.update_user(user_args)
我如何实现更改当前用户密码openstacksdk
?提前谢谢。