diff --git a/shade/openstackcloud.py b/shade/openstackcloud.py index 7a7e1b661..eb5bc5f2f 100644 --- a/shade/openstackcloud.py +++ b/shade/openstackcloud.py @@ -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: diff --git a/shade/tests/functional/test_limits.py b/shade/tests/functional/test_limits.py index 015dafec0..51e0fd38b 100644 --- a/shade/tests/functional/test_limits.py +++ b/shade/tests/functional/test_limits.py @@ -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'))