Ask Your Question
0

How to create query filter for python ceilometer client

asked 2014-11-11 04:27:58 -0500

chitranshi-shubham gravatar image

updated 2014-11-11 22:02:43 -0500

I am trying to get all the samples of cpu_util for a resource using ceilometer client. I have done that from CLI using the following format.

ceilometer sample-list -m cpu_util -q "resource_id=<resource id here>"

when I try to do the same using ceilometer client it gives

AttributeError: 'str' object has no attribute 'get'

the problem is in creating the query filter, I am using this method

ceilometerClient.sample.list("cpu_util", q="resource_id='resourceid here'")

alternatively I have also tried creating a seperate json string and passing, but its not working too. this page

How do I create a query (of query class) to pass as parameter ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-11-11 23:56:40 -0500

chitranshi-shubham gravatar image

found this method in horizon_ceilometer_api.py, it is used to make the query (data structure) for ceilometer client.

def make_query(user_id=None, tenant_id=None, resource_id=None,
user_ids=None, tenant_ids=None, resource_ids=None):
"""Returns query built form given parameters.
This query can be then used for querying resources, meters and
statistics.
:Parameters:
- `user_id`: user_id, has a priority over list of ids
- `tenant_id`: tenant_id, has a priority over list of ids
- `resource_id`: resource_id, has a priority over list of ids
- `user_ids`: list of user_ids
- `tenant_ids`: list of tenant_ids
- `resource_ids`: list of resource_ids
"""
user_ids = user_ids or []
tenant_ids = tenant_ids or []
resource_ids = resource_ids or []
query = []
if user_id:
user_ids = [user_id]
for u_id in user_ids:
query.append({"field": "user_id", "op": "eq", "value": u_id})
if tenant_id:
tenant_ids = [tenant_id]
for t_id in tenant_ids:
query.append({"field": "project_id", "op": "eq", "value": t_id})
if resource_id:
resource_ids = [resource_id]
for r_id in resource_ids:
query.append({"field": "resource_id", "op": "eq", "value": r_id})
return query

the link to github is here

it works for the pyhon-ceilometerclient.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2014-11-11 04:27:58 -0500

Seen: 848 times

Last updated: Nov 11 '14