gpt4 book ai didi

python - 如何在 Ceilometer Python 客户端 API 中实现身份验证 token

转载 作者:行者123 更新时间:2023-11-30 23:13:28 60 4
gpt4 key购买 nike

我真的很难理解 Ceilometerclient。我不明白为什么它不识别auth_token属性,它写在他们的documentation中,我做错了什么

import ceilometerclient
import ceilometerclient.client
import keystoneclient.v2_0.client as ksclient
import ceilometerclient.v2 as c_client
from ceilometerclient import client

OS_USERNAME="username"
OS_PASSWORD="pass"
OS_TENANT_NAME="project"
OS_AUTH_URL="hosturl:5000/v2.0/"
CEILOMETER_ENDPOINT="hosturl:8777"

ceilometer_client= ceilometerclient.client.get_client(2, os_username=OS_USERNAME, os_password=OS_PASSWORD, os_tenant_name=OS_TENANT_NAME, os_auth_url=OS_AUTH_URL)


auth_token = ceilometer_client.auth_token
ceilometer = c_client.Client(endpoint=CEILOMETER_ENDPOINT, token= lambda : auth_token )

meterlist = ceilometer_client.meters.list()

cpu_util_sample = ceilometer.samples.list('cpu_util')
for each in cpu_util_sample:
print each.timestamp, each.resource_id, each.counter_volume

错误

auth_token = ceilometer_client.auth_token
AttributeError: 'Client' object has no attribute 'auth_token'

最佳答案

试试这个代码:

from keystoneclient.auth.identity import v2
from keystoneclient import session
from ceilometerclient import client

auth=v2.Password(auth_url="hosturl:5000/v2.0/", username="admin", password="pass", tenant_id='123456')

sess = session.Session(auth=auth,verify=False) # verify=False may not be required for you
token = auth.get_token(sess)

cclient = client.get_client(2, ceilometer_url="hosturl:8777/", token=token,verify=False)
cclient.meters.list()

关于python - 如何在 Ceilometer Python 客户端 API 中实现身份验证 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29302584/

60 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com