1

我希望你今天过得很好。我有一个关于我目前正在处理的 Rancher Python 客户端的问题。我正在尝试访问这个单节点容器并修改所述容器的各个方面,但我真的不知道从哪里开始。我能够应用 API 密钥并使用 print(client) 打印出客户端。

问题:有人可以通过模拟调用这个rancher api,特别是有没有办法改变管理员访问权限,即谁可以从api访问哪个容器?

太感谢了。

GitHub链接:https ://github.com/rancher/client-python

import rancher

client = rancher.Client(url='https://localhost:8443/v3',
                        access_key='<some valid access key>',
                        secret_key='<some valid secret key>')

# curl -s https://localhost:8443/v3/users?me=true
client.list_user(me='true')

# curl -s -X POST https://localhost:8443/v3/users -H 'Content-Type: application/json' -d '{ "username" : "user1", "password": "Password1" }'
client.create_user(username='user1', password='Password1')

# curl -s -X PUT https://localhost:8443/v3/users/user-xyz123 -H 'Content-Type: application/json' -d '{ "description" : "A user" }'
user = client.by_id_user('user-xyz123')
client.update(user, description='A user')

# curl -s -X DELETE https://localhost:8443/v3/users/user-xyz123
user = client.by_id_user('user-xyz123')
client.delete(user)

# Links
# curl -s https://localhost:8443/v3/clusterRoleTemplateBindings?userId=user-xyz123
user = client.by_id_user('user-xyz123')
user.clusterRoleTemplateBindings()
4

2 回答 2

0

我找到了答案,我一直在使用 Rancher 1.6 而不是 Rancher 2.x。该 API 不适用于 rancher 1.6。

于 2020-06-30T15:16:47.677 回答
0

要与客户端进行调用(get/post/put/delete),请使用如下方法:

text_response = client._get(url=[ranchercluster/v3/clusters], access_key, secret_key)

对于其他人,只有 client._post()、client._put() 和 client._delete()

于 2022-01-18T09:30:20.587 回答