summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgordon chung <gord@live.ca>2015-09-08 15:00:42 -0400
committergordon chung <gord@live.ca>2015-09-09 07:36:31 -0400
commitdaed7e59c383f1ca74d75160cbc99fbd89675648 (patch)
treed7a0cf89cefe0a7f0c7b4e45fce97e78c2310067
parentd40487643e2a069788e6f3218d946d86395a279e (diff)
downloadpython-ceilometerclient-1.5.0.tar.gz
add limit support1.5.0
limit is now a mandatory condition when querying. this patch allows users to control this value. Change-Id: Ied5f80dc8cfe8b5f85e60fb8ca1d4a8f26663456 Closes-Bug: #1493511
-rw-r--r--ceilometerclient/tests/unit/v2/test_shell.py38
-rw-r--r--ceilometerclient/v2/events.py5
-rw-r--r--ceilometerclient/v2/meters.py5
-rw-r--r--ceilometerclient/v2/resources.py4
-rw-r--r--ceilometerclient/v2/shell.py15
5 files changed, 58 insertions, 9 deletions
diff --git a/ceilometerclient/tests/unit/v2/test_shell.py b/ceilometerclient/tests/unit/v2/test_shell.py
index 22334dc..725ef66 100644
--- a/ceilometerclient/tests/unit/v2/test_shell.py
+++ b/ceilometerclient/tests/unit/v2/test_shell.py
@@ -32,6 +32,7 @@ from ceilometerclient.v2 import capabilities
from ceilometerclient.v2 import event_types
from ceilometerclient.v2 import events
from ceilometerclient.v2 import meters
+from ceilometerclient.v2 import resources
from ceilometerclient.v2 import samples
from ceilometerclient.v2 import shell as ceilometer_shell
from ceilometerclient.v2 import statistics
@@ -1160,6 +1161,7 @@ class ShellEventListCommandTest(utils.BaseTestCase):
self.args = mock.Mock()
self.args.query = None
self.args.no_traits = None
+ self.args.limit = None
@mock.patch('sys.stdout', new=six.StringIO())
def test_event_list(self):
@@ -1346,6 +1348,7 @@ class ShellMeterListCommandTest(utils.BaseTestCase):
self.cc = mock.Mock()
self.cc.meters.list = mock.Mock()
self.args = mock.MagicMock()
+ self.args.limit = None
@mock.patch('sys.stdout', new=six.StringIO())
def test_meter_list(self):
@@ -1353,7 +1356,7 @@ 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=[])
+ self.cc.meters.list.assert_called_once_with(q=[], limit=None)
self.assertEqual('''\
+-------+-------+-------+-------------+---------+------------+
@@ -1364,6 +1367,39 @@ class ShellMeterListCommandTest(utils.BaseTestCase):
''', sys.stdout.getvalue())
+class ShellResourceListCommandTest(utils.BaseTestCase):
+
+ RESOURCE = {
+ "source": "openstack",
+ "resource_id": "resource-id",
+ "project_id": "project",
+ "user_id": "user"
+ }
+
+ def setUp(self):
+ super(ShellResourceListCommandTest, self).setUp()
+ self.cc = mock.Mock()
+ self.cc.resources.list = mock.Mock()
+ self.args = mock.MagicMock()
+ self.args.limit = None
+
+ @mock.patch('sys.stdout', new=six.StringIO())
+ def test_resource_list(self):
+ resource = resources.Resource(mock.Mock(), self.RESOURCE)
+ self.cc.resources.list.return_value = [resource]
+
+ ceilometer_shell.do_resource_list(self.cc, self.args)
+ self.cc.resources.list.assert_called_once_with(q=[], limit=None)
+
+ self.assertEqual('''\
++-------------+-----------+---------+------------+
+| Resource ID | Source | User ID | Project ID |
++-------------+-----------+---------+------------+
+| resource-id | openstack | user | project |
++-------------+-----------+---------+------------+
+''', sys.stdout.getvalue())
+
+
class ShellEventTypeListCommandTest(utils.BaseTestCase):
EVENT_TYPE = {
diff --git a/ceilometerclient/v2/events.py b/ceilometerclient/v2/events.py
index 32380d6..6cd46d2 100644
--- a/ceilometerclient/v2/events.py
+++ b/ceilometerclient/v2/events.py
@@ -29,9 +29,10 @@ class Event(base.Resource):
class EventManager(base.Manager):
resource_class = Event
- def list(self, q=None):
+ def list(self, q=None, limit=None):
path = '/v2/events'
- return self._list(options.build_url(path, q))
+ params = ['limit=%s' % limit] if limit else None
+ return self._list(options.build_url(path, q, params))
def get(self, message_id):
path = '/v2/events/%s'
diff --git a/ceilometerclient/v2/meters.py b/ceilometerclient/v2/meters.py
index 938854d..ddb2134 100644
--- a/ceilometerclient/v2/meters.py
+++ b/ceilometerclient/v2/meters.py
@@ -25,6 +25,7 @@ class Meter(base.Resource):
class MeterManager(base.Manager):
resource_class = Meter
- def list(self, q=None):
+ def list(self, q=None, limit=None):
path = '/v2/meters'
- return self._list(options.build_url(path, q))
+ params = ['limit=%s' % limit] if limit else None
+ return self._list(options.build_url(path, q, params))
diff --git a/ceilometerclient/v2/resources.py b/ceilometerclient/v2/resources.py
index aa80664..d516ee1 100644
--- a/ceilometerclient/v2/resources.py
+++ b/ceilometerclient/v2/resources.py
@@ -30,9 +30,11 @@ class Resource(base.Resource):
class ResourceManager(base.Manager):
resource_class = Resource
- def list(self, q=None, links=None):
+ def list(self, q=None, links=None, limit=None):
path = '/v2/resources'
params = ['meter_links=%d' % (1 if links else 0)]
+ if limit:
+ params.append('limit=%s' % limit)
return self._list(options.build_url(path, q, params))
def get(self, resource_id):
diff --git a/ceilometerclient/v2/shell.py b/ceilometerclient/v2/shell.py
index 3bf4131..798dc45 100644
--- a/ceilometerclient/v2/shell.py
+++ b/ceilometerclient/v2/shell.py
@@ -254,9 +254,12 @@ def do_sample_create(cc, args={}):
@utils.arg('-q', '--query', metavar='<QUERY>',
help='key[op]data_type::value; list. data_type is optional, '
'but if supplied must be string, integer, float, or boolean.')
+@utils.arg('-l', '--limit', metavar='<NUMBER>',
+ help='Maximum number of meters to return.')
def do_meter_list(cc, args={}):
"""List the user's meters."""
- meters = cc.meters.list(q=options.cli_to_array(args.query))
+ meters = cc.meters.list(q=options.cli_to_array(args.query),
+ limit=args.limit)
field_labels = ['Name', 'Type', 'Unit', 'Resource ID', 'User ID',
'Project ID']
fields = ['name', 'type', 'unit', 'resource_id', 'user_id',
@@ -1050,9 +1053,12 @@ def do_alarm_history(cc, args={}):
@utils.arg('-q', '--query', metavar='<QUERY>',
help='key[op]data_type::value; list. data_type is optional, '
'but if supplied must be string, integer, float, or boolean.')
+@utils.arg('-l', '--limit', metavar='<NUMBER>',
+ help='Maximum number of resources to return.')
def do_resource_list(cc, args={}):
"""List the resources."""
- resources = cc.resources.list(q=options.cli_to_array(args.query))
+ resources = cc.resources.list(q=options.cli_to_array(args.query),
+ limit=args.limit)
field_labels = ['Resource ID', 'Source', 'User ID', 'Project ID']
fields = ['resource_id', 'source', 'user_id', 'project_id']
@@ -1081,9 +1087,12 @@ def do_resource_show(cc, args={}):
'or datetime.')
@utils.arg('--no-traits', dest='no_traits', action='store_true',
help='If specified, traits will not be printed.')
+@utils.arg('-l', '--limit', metavar='<NUMBER>',
+ help='Maximum number of events to return.')
def do_event_list(cc, args={}):
"""List events."""
- events = cc.events.list(q=options.cli_to_array(args.query))
+ events = cc.events.list(q=options.cli_to_array(args.query),
+ limit=args.limit)
field_labels = ['Message ID', 'Event Type', 'Generated', 'Traits']
fields = ['message_id', 'event_type', 'generated', 'traits']
if args.no_traits: