Authenticating the python ceilometer client against the Openstack APIs – bloody lambda functions!

We were doing some work with Ceilometer – it appears in a few of our activities – and I was trying to get up to speed with it. Playing with the python Ceilometer client proved a little more difficult then envisaged – mostly due to deficiencies in documentation. Here’s a small note on an issue I faced with authentication.

The starting point for the work was to use the approach proposed the documentation to obtain a list of meters. This was done after a basic install of the libraries locally (pip install python-ceilometerclient) to work against a remote set of APIs which are known to be stable and working.

Using this basic setup, authentication would not work when the following approach to creation of the client (see full code below) was used; this is very much in line with the approaches of other Openstack client libraries.

from ceilometerclient import client
ceilometer = Client('2', endpoint=OS_IMAGE_ENDPOINT, token=OS_AUTH_TOKEN)

The following error was produced:

“File "/usr/local/lib/python2.7/dist-packages/ceilometerclient/common/", line 137, in _http_request
auth_token = self.auth_token()
TypeError: 'unicode' object is not callable”

The problem turned out to be one of lambda functions – it was not obvious that we should make the token an anonymous function: once we called it with lambda, everything worked fine.

ceilometer = client.Client('2',endpoint = ceilo_endpoint, token = lambda: token)

Subsequently, one of our colleagues (thanks Florian!) noted that there is a simpler approach which uses get_client. (See the second file below for how we used this).

Now we’re trying to do something useful with it!


# -*- coding: utf-8 -*-
# list meters - client initialized with lambda’d auth_token
from ceilometerclient import client
from os import environ as env
import keystoneclient.v2_0.client as ksclient

#getting the credentials
keystone = {}

#creating a keystone client
ceilometer_client = client._get_ksclient(**keystone)
token = ceilometer_client.auth_token

#creating an endpoint
ceilo_endpoint = client._get_endpoint(ceilometer_client, **keystone)

#creating a ceilometer client
ceilometer = client.Client('2',endpoint = ceilo_endpoint, token = token)

meters = ceilometer.meters.list()
print meters


# -*- coding: utf-8 -*-
# list meters - client initialized with get_client
from ceilometerclient import client
from os import environ as env
from ceilometerclient.common import utils

#getting the credentials
keystone = {}

#creating an authenticated client
ceilometer_client = client.get_client(2,**keystone)

#now you should be able to use the API
meters = ceilometer_client.meters.list()
print meters


  1. Thanks it helped me alot..

  2. This kind of authentication is also necessary if you are using the Glance client.

    Check this link on my blog:

Leave a Reply

Your email address will not be published. Required fields are marked *