Add get_volume_limits() support

Add the ability for a user (nodepool) to get the volume limits of a
cloud.

Change-Id: Id568d3ad408dd8976211c0576c45e8c9471d1849
Depends-On: https://review.openstack.org/564279
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
Paul Belanger 2018-04-25 11:10:57 -04:00
parent 3c3132285f
commit f5e8ac20c7
No known key found for this signature in database
GPG Key ID: 611A80832067AF38
2 changed files with 39 additions and 2 deletions

View File

@ -5188,6 +5188,32 @@ class OpenStackCloud(
volumes.append(volume)
return volumes
def get_volume_limits(self, name_or_id=None):
""" Get volume limits for a project
:param name_or_id: (optional) project name or ID to get limits for
if different from the current project
:raises: OpenStackCloudException if it's not a valid project
:returns: Munch object with the limits
"""
params = {}
project_id = None
error_msg = "Failed to get limits"
if name_or_id:
proj = self.get_project(name_or_id)
if not proj:
raise OpenStackCloudException("project does not exist")
project_id = proj.id
params['tenant_id'] = project_id
error_msg = "{msg} for the project: {project} ".format(
msg=error_msg, project=name_or_id)
data = self._volume_client.get('/limits', params=params)
limits = self._get_and_munchify('limits', data)
return limits
def get_volume_id(self, name_or_id):
volume = self.get_volume(name_or_id)
if volume:

View File

@ -21,7 +21,7 @@ from shade.tests.functional import base
class TestUsage(base.BaseFunctionalTestCase):
def test_get_our_limits(self):
def test_get_our_compute_limits(self):
'''Test quotas functionality'''
limits = self.user_cloud.get_compute_limits()
self.assertIsNotNone(limits)
@ -30,7 +30,7 @@ class TestUsage(base.BaseFunctionalTestCase):
# Test normalize limits
self.assertFalse(hasattr(limits, 'maxImageMeta'))
def test_get_other_limits(self):
def test_get_other_compute_limits(self):
'''Test quotas functionality'''
limits = self.operator_cloud.get_compute_limits('demo')
self.assertIsNotNone(limits)
@ -38,3 +38,14 @@ class TestUsage(base.BaseFunctionalTestCase):
# Test normalize limits
self.assertFalse(hasattr(limits, 'maxImageMeta'))
def test_get_our_volume_limits(self):
'''Test quotas functionality'''
limits = self.user_cloud.get_volume_limits()
self.assertIsNotNone(limits)
self.assertFalse(hasattr(limits, 'maxTotalVolumes'))
def test_get_other_volume_limits(self):
'''Test quotas functionality'''
limits = self.operator_cloud.get_volume_limits('demo')
self.assertFalse(hasattr(limits, 'maxTotalVolumes'))