0

我找到了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

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?提前谢谢。

4

1 回答 1

0

以此解决:

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 文档知识感到羞耻。

非常非常感谢一位打电话给tanjin的人

于 2021-10-30T06:51:44.717 回答