diff options
| author | Lianhao Lu <lianhao.lu@intel.com> | 2013-02-20 15:57:50 +0800 |
|---|---|---|
| committer | Lianhao Lu <lianhao.lu@intel.com> | 2013-02-20 16:03:25 +0800 |
| commit | 8b3ef28c752fa96a1019900d3b9b9a80ede3eeec (patch) | |
| tree | f532b10162cd62188c90f13abd53fcdc3f9fb5f7 /ceilometerclient | |
| parent | feb4bcc6148a166676bbff2718590ea2291a2de5 (diff) | |
| download | python-ceilometerclient-8b3ef28c752fa96a1019900d3b9b9a80ede3eeec.tar.gz | |
v1-api: Added timestamp support.
Added timestamp support for resource/sample api. Fixed bug #1118542.
Change-Id: I644c480ca00f57549dc66bd387721c25d3b353c4
Diffstat (limited to 'ceilometerclient')
| -rw-r--r-- | ceilometerclient/v1/meters.py | 35 | ||||
| -rw-r--r-- | ceilometerclient/v1/shell.py | 18 |
2 files changed, 44 insertions, 9 deletions
diff --git a/ceilometerclient/v1/meters.py b/ceilometerclient/v1/meters.py index 960e65d..e95e001 100644 --- a/ceilometerclient/v1/meters.py +++ b/ceilometerclient/v1/meters.py @@ -16,6 +16,21 @@ from ceilometerclient.common import base +def _get_opt_path(simple_params=[], **kwargs): + l = [] + #get simple paramters + for key in simple_params: + val = kwargs.get(key) + if val: + l.append(key + '=' + val) + #get metadata query paramters + metaquery = kwargs.get('metaquery') + if metaquery: + l.extend(metaquery.split(':')) + + return '&'.join(l) + + class User(base.Resource): def __init__(self, manager, info, loaded=False): _d = {unicode('user_id'): info} @@ -80,7 +95,8 @@ class ResourceManager(base.Manager): u = kwargs.get('user_id') s = kwargs.get('source') p = kwargs.get('project_id') - opts = kwargs.get('metaquery') + opts_path = _get_opt_path(['start_timestamp', 'end_timestamp'], + **kwargs) if u: path = '/users/%s/resources' % (u) elif s: @@ -89,8 +105,8 @@ class ResourceManager(base.Manager): path = '/projects/%s/resources' % (p) else: path = '/resources' - if opts: - path = '/v1%s?%s' % (path, '&'.join(opts.split(':'))) + if opts_path: + path = '/v1%s?%s' % (path, opts_path) else: path = '/v1%s' % (path) return self._list(path, 'resources') @@ -118,7 +134,8 @@ class SampleManager(base.Manager): u = kwargs.get('user_id') p = kwargs.get('project_id') s = kwargs.get('source') - opts = kwargs.get('metaquery') + opts_path = _get_opt_path(['start_timestamp', 'end_timestamp'], + **kwargs) if r: path = '/resources/%s/meters/%s' % (r, c) elif u: @@ -130,8 +147,8 @@ class SampleManager(base.Manager): else: path = '/meters' - if opts: - path = '/v1%s?%s' % (path, '&'.join(opts.split(':'))) + if opts_path: + path = '/v1%s?%s' % (path, opts_path) else: path = '/v1%s' % (path) return self._list(path, 'events') @@ -153,7 +170,7 @@ class MeterManager(base.Manager): u = kwargs.get('user_id') p = kwargs.get('project_id') s = kwargs.get('source') - opts = kwargs.get('metaquery') + opts_path = _get_opt_path(**kwargs) if u: path = '/users/%s/meters' % u elif r: @@ -164,8 +181,8 @@ class MeterManager(base.Manager): path = '/sources/%s/meters' % s else: path = '/meters' - if opts: - path = '/v1%s?%s' % (path, '&'.join(opts.split(':'))) + if opts_path: + path = '/v1%s?%s' % (path, opts_path) else: path = '/v1%s' % (path) return self._list(path, 'meters') diff --git a/ceilometerclient/v1/shell.py b/ceilometerclient/v1/shell.py index f4ad973..bc9362f 100644 --- a/ceilometerclient/v1/shell.py +++ b/ceilometerclient/v1/shell.py @@ -29,6 +29,12 @@ import ceilometerclient.exc as exc help='ID of the project to show samples for.') @utils.arg('-c', '--counter_name', metavar='<NAME>', help='Name of meter to show samples for.') +@utils.arg('--start', metavar='<START_TIMESTAMP>', + help='ISO date in UTC which limits events by ' + 'timestamp >= this value') +@utils.arg('--end', metavar='<END_TIMESTAMP>', + help='ISO date in UTC which limits events by ' + 'timestamp <= this value') def do_sample_list(cc, args): '''List the samples for this meters''' fields = {'counter_name': args.counter_name, @@ -36,6 +42,8 @@ def do_sample_list(cc, args): 'user_id': args.user_id, 'project_id': args.project_id, 'source': args.source, + 'start_timestamp': args.start, + 'end_timestamp': args.end, 'metaquery': args.metaquery} try: samples = cc.samples.list(**fields) @@ -49,6 +57,8 @@ def do_sample_list(cc, args): sortby=0) +@utils.arg('-m', '--metaquery', metavar='<METAQUERY>', + help='Query into the metadata metadata.key=value:..') @utils.arg('-s', '--source', metavar='<SOURCE>', help='ID of the resource to show samples for.') @utils.arg('-r', '--resource_id', metavar='<RESOURCE_ID>', @@ -91,11 +101,19 @@ def do_user_list(cc, args={}): help='ID of the project to show samples for.') @utils.arg('-m', '--metaquery', metavar='<METAQUERY>', help='Query into the metadata metadata.key=value:..') +@utils.arg('--start', metavar='<START_TIMESTAMP>', + help='ISO date in UTC which limits resouces by ' + 'last update time >= this value') +@utils.arg('--end', metavar='<END_TIMESTAMP>', + help='ISO date in UTC which limits resouces by ' + 'last update time <= this value') def do_resource_list(cc, args={}): '''List the users''' kwargs = {'source': args.source, 'user_id': args.user_id, 'project_id': args.project_id, + 'start_timestamp': args.start, + 'end_timestamp': args.end, 'metaquery': args.metaquery} resources = cc.resources.list(**kwargs) |
