Skip to content

Commit bd60aa4

Browse files
Jenkinsopenstack-gerrit
Jenkins
authored andcommitted
Merge "Add support for network quota details command"
2 parents e5feff6 + 5eead74 commit bd60aa4

File tree

4 files changed

+75
-2
lines changed

4 files changed

+75
-2
lines changed

openstack/network/v2/_proxy.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,19 +2034,27 @@ def delete_quota(self, quota, ignore_missing=True):
20342034
"""
20352035
self._delete(_quota.Quota, quota, ignore_missing=ignore_missing)
20362036

2037-
def get_quota(self, quota):
2037+
def get_quota(self, quota, details=False):
20382038
"""Get a quota
20392039
20402040
:param quota: The value can be the ID of a quota or a
20412041
:class:`~openstack.network.v2.quota.Quota` instance.
20422042
The ID of a quota is the same as the project ID
20432043
for the quota.
2044+
:param details: If set to True, details about quota usage will
2045+
be returned.
20442046
20452047
:returns: One :class:`~openstack.network.v2.quota.Quota`
20462048
:raises: :class:`~openstack.exceptions.ResourceNotFound`
20472049
when no resource can be found.
20482050
"""
2049-
return self._get(_quota.Quota, quota)
2051+
if details:
2052+
quota_obj = self._get_resource(_quota.Quota, quota)
2053+
quota = self._get(_quota.QuotaDetails, project=quota_obj.id,
2054+
requires_id=False)
2055+
else:
2056+
quota = self._get(_quota.Quota, quota)
2057+
return quota
20502058

20512059
def get_quota_default(self, quota):
20522060
"""Get a default quota

openstack/network/v2/quota.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,47 @@ class QuotaDefault(Quota):
8282
# Properties
8383
#: The ID of the project.
8484
project = resource.URI('project')
85+
86+
87+
class QuotaDetails(Quota):
88+
base_path = '/quotas/%(project)s/details'
89+
90+
# capabilities
91+
allow_retrieve = True
92+
allow_update = False
93+
allow_delete = False
94+
allow_list = False
95+
96+
# Properties
97+
#: The ID of the project.
98+
project = resource.URI('project')
99+
#: The maximum amount of floating IPs you can have. *Type: dict*
100+
floating_ips = resource.Body('floatingip', type=dict)
101+
#: The maximum amount of health monitors you can create. *Type: dict*
102+
health_monitors = resource.Body('healthmonitor', type=dict)
103+
#: The maximum amount of listeners you can create. *Type: dict*
104+
listeners = resource.Body('listener', type=dict)
105+
#: The maximum amount of load balancers you can create. *Type: dict*
106+
load_balancers = resource.Body('loadbalancer', type=dict)
107+
#: The maximum amount of L7 policies you can create. *Type: dict*
108+
l7_policies = resource.Body('l7policy', type=dict)
109+
#: The maximum amount of networks you can create. *Type: dict*
110+
networks = resource.Body('network', type=dict)
111+
#: The maximum amount of pools you can create. *Type: dict*
112+
pools = resource.Body('pool', type=dict)
113+
#: The maximum amount of ports you can create. *Type: dict*
114+
ports = resource.Body('port', type=dict)
115+
#: The ID of the project these quota values are for.
116+
project_id = resource.Body('tenant_id', alternate_id=True)
117+
#: The maximum amount of RBAC policies you can create. *Type: dict*
118+
rbac_policies = resource.Body('rbac_policy', type=dict)
119+
#: The maximum amount of routers you can create. *Type: int*
120+
routers = resource.Body('router', type=dict)
121+
#: The maximum amount of subnets you can create. *Type: dict*
122+
subnets = resource.Body('subnet', type=dict)
123+
#: The maximum amount of subnet pools you can create. *Type: dict*
124+
subnet_pools = resource.Body('subnetpool', type=dict)
125+
#: The maximum amount of security group rules you can create. *Type: dict*
126+
security_group_rules = resource.Body('security_group_rule', type=dict)
127+
#: The maximum amount of security groups you can create. *Type: dict*
128+
security_groups = resource.Body('security_group', type=dict)

openstack/tests/functional/network/v2/test_quota.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ def test_list(self):
2020
self.assertIsNotNone(qot.project_id)
2121
self.assertIsNotNone(qot.networks)
2222

23+
def test_list_details(self):
24+
expected_keys = ['limit', 'used', 'reserved']
25+
project_id = self.conn.session.get_project_id()
26+
quota_details = self.conn.network.get_quota(project_id, details=True)
27+
for details in quota_details._body.attributes.values():
28+
for expected_key in expected_keys:
29+
self.assertTrue(expected_key in details.keys())
30+
2331
def test_set(self):
2432
attrs = {'networks': 123456789}
2533
for project_quota in self.conn.network.quotas():

openstack/tests/unit/network/v2/test_proxy.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,19 @@ def test_quota_delete_ignore(self):
686686
def test_quota_get(self):
687687
self.verify_get(self.proxy.get_quota, quota.Quota)
688688

689+
@mock.patch.object(proxy_base2.BaseProxy, "_get_resource")
690+
def test_quota_get_details(self, mock_get):
691+
fake_quota = mock.Mock(project_id='PROJECT')
692+
mock_get.return_value = fake_quota
693+
self._verify2("openstack.proxy2.BaseProxy._get",
694+
self.proxy.get_quota,
695+
method_args=['QUOTA_ID'],
696+
method_kwargs={'details': True},
697+
expected_args=[quota.QuotaDetails],
698+
expected_kwargs={'project': fake_quota.id,
699+
'requires_id': False})
700+
mock_get.assert_called_once_with(quota.Quota, 'QUOTA_ID')
701+
689702
@mock.patch.object(proxy_base2.BaseProxy, "_get_resource")
690703
def test_quota_default_get(self, mock_get):
691704
fake_quota = mock.Mock(project_id='PROJECT')

0 commit comments

Comments
 (0)