1

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

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'
4

1 回答 1

3

试试这个代码:

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()
于 2015-04-07T11:08:42.447 回答