Merge "Add tenant_id parameter to limits."
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import ddt
|
||||
import mock
|
||||
|
||||
from cinderclient.tests.unit import utils
|
||||
@@ -155,8 +156,10 @@ class TestAbsoluteLimit(utils.TestCase):
|
||||
self.assertEqual("<AbsoluteLimit: name=name1>", repr(l1))
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestLimitsManager(utils.TestCase):
|
||||
def test_get(self):
|
||||
@ddt.data(None, 'test')
|
||||
def test_get(self, tenant_id):
|
||||
api = mock.Mock()
|
||||
api.client.get.return_value = (
|
||||
None,
|
||||
@@ -165,7 +168,11 @@ class TestLimitsManager(utils.TestCase):
|
||||
l1 = limits.AbsoluteLimit("name1", "value1")
|
||||
limitsManager = limits.LimitsManager(api)
|
||||
|
||||
lim = limitsManager.get()
|
||||
lim = limitsManager.get(tenant_id)
|
||||
query_str = ''
|
||||
if tenant_id:
|
||||
query_str = '?tenant_id=%s' % tenant_id
|
||||
api.client.get.assert_called_once_with('/limits%s' % query_str)
|
||||
|
||||
self.assertIsInstance(lim, limits.Limits)
|
||||
for l in lim.absolute:
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from cinderclient import base
|
||||
|
||||
|
||||
@@ -83,9 +85,15 @@ class LimitsManager(base.Manager):
|
||||
|
||||
resource_class = Limits
|
||||
|
||||
def get(self):
|
||||
def get(self, tenant_id=None):
|
||||
"""Get a specific extension.
|
||||
|
||||
:rtype: :class:`Limits`
|
||||
"""
|
||||
return self._get("/limits", "limits")
|
||||
opts = {}
|
||||
if tenant_id:
|
||||
opts['tenant_id'] = tenant_id
|
||||
|
||||
query_string = "?%s" % parse.urlencode(opts) if opts else ""
|
||||
|
||||
return self._get("/limits%s" % query_string, "limits")
|
||||
|
||||
@@ -1214,18 +1214,28 @@ def do_quota_class_update(cs, args):
|
||||
_quota_update(cs.quota_classes, args.class_name, args)
|
||||
|
||||
|
||||
@utils.arg('tenant',
|
||||
metavar='<tenant_id>',
|
||||
nargs='?',
|
||||
default=None,
|
||||
help='Display information for a single tenant (Admin only).')
|
||||
@utils.service_type('volumev3')
|
||||
def do_absolute_limits(cs, args):
|
||||
"""Lists absolute limits for a user."""
|
||||
limits = cs.limits.get().absolute
|
||||
limits = cs.limits.get(args.tenant).absolute
|
||||
columns = ['Name', 'Value']
|
||||
utils.print_list(limits, columns)
|
||||
|
||||
|
||||
@utils.arg('tenant',
|
||||
metavar='<tenant_id>',
|
||||
nargs='?',
|
||||
default=None,
|
||||
help='Display information for a single tenant (Admin only).')
|
||||
@utils.service_type('volumev3')
|
||||
def do_rate_limits(cs, args):
|
||||
"""Lists rate limits for a user."""
|
||||
limits = cs.limits.get().rate
|
||||
limits = cs.limits.get(args.tenant).rate
|
||||
columns = ['Verb', 'URI', 'Value', 'Remain', 'Unit', 'Next_Available']
|
||||
utils.print_list(limits, columns)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user