~ubuntu-branches/ubuntu/wily/python-ceilometerclient/wily

« back to all changes in this revision

Viewing changes to ceilometerclient/v2/samples.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-03-01 12:47:39 UTC
  • Revision ID: package-import@ubuntu.com-20130301124739-0in66psacnqpksch
Tags: upstream-0.1~dde86a3
ImportĀ upstreamĀ versionĀ 0.1~dde86a3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2012 OpenStack LLC.
 
2
# All Rights Reserved.
 
3
#
 
4
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
5
#    not use this file except in compliance with the License. You may obtain
 
6
#    a copy of the License at
 
7
#
 
8
#         http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
10
#    Unless required by applicable law or agreed to in writing, software
 
11
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
12
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
13
#    License for the specific language governing permissions and limitations
 
14
#    under the License.
 
15
 
 
16
import urllib
 
17
 
 
18
from ceilometerclient.common import base
 
19
 
 
20
 
 
21
class Sample(base.Resource):
 
22
    def __repr__(self):
 
23
        return "<Sample %s>" % self._info
 
24
 
 
25
 
 
26
class SampleManager(base.Manager):
 
27
    resource_class = Sample
 
28
 
 
29
    @staticmethod
 
30
    def build_url(path, q):
 
31
        if q:
 
32
            query_params = {'q.field': [],
 
33
                            'q.value': [],
 
34
                            'q.op': []}
 
35
 
 
36
            for query in q:
 
37
                for name in ['field', 'op', 'value']:
 
38
                    query_params['q.%s' % name].append(query.get(name, ''))
 
39
 
 
40
            path += "?" + urllib.urlencode(query_params, doseq=True)
 
41
 
 
42
        return path
 
43
 
 
44
    def list(self, meter_name=None, q=None):
 
45
        path = '/v2/meters'
 
46
        if meter_name:
 
47
            path += '/' + meter_name
 
48
        return self._list(self.build_url(path, q))