diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-02-09 10:05:27 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-02-09 10:05:28 +0000 |
commit | 75aa9a6ed495b6969df8b0c99c0770c7f4e7f159 (patch) | |
tree | 094edbde1ac7310f47e252e428355b585a61c645 | |
parent | 2fa47e454b5a2ba63f38dcf0692417128caf5078 (diff) | |
parent | c45000c7594ad6fbfabf44c0615dce3021f43605 (diff) | |
download | python-ceilometerclient-75aa9a6ed495b6969df8b0c99c0770c7f4e7f159.tar.gz |
Merge "Enhances client to support unique meter retrieval"
-rw-r--r-- | ceilometerclient/tests/unit/v2/test_shell.py | 22 | ||||
-rw-r--r-- | ceilometerclient/v2/meters.py | 11 | ||||
-rw-r--r-- | ceilometerclient/v2/shell.py | 6 |
3 files changed, 35 insertions, 4 deletions
diff --git a/ceilometerclient/tests/unit/v2/test_shell.py b/ceilometerclient/tests/unit/v2/test_shell.py index 053936b..8f518b2 100644 --- a/ceilometerclient/tests/unit/v2/test_shell.py +++ b/ceilometerclient/tests/unit/v2/test_shell.py @@ -1846,6 +1846,7 @@ class ShellMeterListCommandTest(utils.BaseTestCase): self.cc.meters.list = mock.Mock() self.args = mock.MagicMock() self.args.limit = None + self.args.unique = False @mock.patch('sys.stdout', new=six.StringIO()) def test_meter_list(self): @@ -1853,7 +1854,26 @@ class ShellMeterListCommandTest(utils.BaseTestCase): self.cc.meters.list.return_value = [meter] ceilometer_shell.do_meter_list(self.cc, self.args) - self.cc.meters.list.assert_called_once_with(q=[], limit=None) + self.cc.meters.list.assert_called_once_with(q=[], limit=None, + unique=False) + + self.assertEqual('''\ ++-------+-------+-------+-------------+---------+------------+ +| Name | Type | Unit | Resource ID | User ID | Project ID | ++-------+-------+-------+-------------+---------+------------+ +| image | gauge | image | resource-id | | project | ++-------+-------+-------+-------------+---------+------------+ +''', sys.stdout.getvalue()) + + @mock.patch('sys.stdout', new=six.StringIO()) + def test_unique_meter_list(self): + self.args.unique = True + meter = meters.Meter(mock.Mock(), self.METER) + self.cc.meters.list.return_value = [meter] + + ceilometer_shell.do_meter_list(self.cc, self.args) + self.cc.meters.list.assert_called_once_with(q=[], limit=None, + unique=True) self.assertEqual('''\ +-------+-------+-------+-------------+---------+------------+ diff --git a/ceilometerclient/v2/meters.py b/ceilometerclient/v2/meters.py index ddb2134..015c04c 100644 --- a/ceilometerclient/v2/meters.py +++ b/ceilometerclient/v2/meters.py @@ -25,7 +25,14 @@ class Meter(base.Resource): class MeterManager(base.Manager): resource_class = Meter - def list(self, q=None, limit=None): + def list(self, q=None, limit=None, unique=False): path = '/v2/meters' - params = ['limit=%s' % limit] if limit else None + params = [] + + if limit: + params.append('limit=%s' % limit) + + if unique: + params.append('unique=%s' % str(unique)) + return self._list(options.build_url(path, q, params)) diff --git a/ceilometerclient/v2/shell.py b/ceilometerclient/v2/shell.py index b1f8734..95dcf11 100644 --- a/ceilometerclient/v2/shell.py +++ b/ceilometerclient/v2/shell.py @@ -266,10 +266,14 @@ def do_sample_create(cc, args={}): 'but if supplied must be string, integer, float, or boolean.') @utils.arg('-l', '--limit', metavar='<NUMBER>', help='Maximum number of meters to return. %s' % DEFAULT_API_LIMIT) +@utils.arg('--unique', dest='unique', + metavar='{True|False}', + type=lambda v: strutils.bool_from_string(v, True), + help='Retrieves unique list of meters.') def do_meter_list(cc, args={}): """List the user's meters.""" meters = cc.meters.list(q=options.cli_to_array(args.query), - limit=args.limit) + limit=args.limit, unique=args.unique) field_labels = ['Name', 'Type', 'Unit', 'Resource ID', 'User ID', 'Project ID'] fields = ['name', 'type', 'unit', 'resource_id', 'user_id', |