how to impliment auth_token in Ceilometer Python Client API

557 Views Asked by At

I am really having a hard time understanding Ceilometerclient. I dont not understand why does it not recognize auth_token attribute, it is written in their documentation, what am i doing wrong

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

Error

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

There are 1 best solutions below

2
On BEST ANSWER

Try this code:

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()