openstacksdk 如何更改当前用户密码

how openstacksdk change current user password

我找到了 CLIAPI 请求 方法,它们对我有用,如下所示:

# 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

Change password for user方法在API请求的最后documentation.

但我需要通过使用 openstacksdk in our project, I found the last method in the openstacksdk documentation -- update_user(user, **attrs), it seems the most like I look for. Unfortunately, the openstack.identity.v3.user instance 来实现,但没有 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更改当前用户密码?提前致谢。

这样解决:

import openstack
conn = openstack.connect(
    ...
)
user_args = {
    "id":"e1c5cc75489f4e0cbb05c39d03b46097"
}
user = conn.identity.get_user(user_args)
user.description = "test_update_psw"
user.password="123456"
conn.identity.update_user(user)

更新用户信息应该使用 user 对象而不是问题代码中的 dictionary

我糟糕的程序语言技能和缺乏 API 文档知识的耻辱。

And thank you very very much for one people who called tanjin.