Support fetching network project default quota
Add new API support to get project default quota of networking resources(GET /quotas/$project_id/default), related unit test cases are added in the patch. Change-Id: I6a4e2a146351dd1e7d652442511f1ef2c279da42 Closes-Bug: #1204956
This commit is contained in:
@@ -1174,6 +1174,22 @@ class Proxy(proxy.BaseProxy):
|
||||
"""
|
||||
return self._get(_quota.Quota, quota)
|
||||
|
||||
def get_quota_default(self, quota):
|
||||
"""Get a default quota
|
||||
|
||||
:param quota: The value can be the ID of a default quota or a
|
||||
:class:`~openstack.network.v2.quota.QuotaDefault`
|
||||
instance. The ID of a default quota is the same
|
||||
as the project ID for the default quota.
|
||||
|
||||
:returns: One :class:`~openstack.network.v2.quota.QuotaDefault`
|
||||
:raises: :class:`~openstack.exceptions.ResourceNotFound`
|
||||
when no resource can be found.
|
||||
"""
|
||||
project_id = resource.Resource.get_id(quota)
|
||||
return self._get(_quota.QuotaDefault,
|
||||
path_args={'project': project_id})
|
||||
|
||||
def quotas(self, **query):
|
||||
"""Return a generator of quotas
|
||||
|
||||
|
||||
@@ -57,3 +57,13 @@ class Quota(resource.Resource):
|
||||
security_group_rules = resource.prop('security_group_rule', type=int)
|
||||
#: The maximum amount of security groups you can create. *Type: int*
|
||||
security_groups = resource.prop('security_group', type=int)
|
||||
|
||||
|
||||
class QuotaDefault(Quota):
|
||||
base_path = '/quotas/%(project)s/default'
|
||||
|
||||
# capabilities
|
||||
allow_retrieve = True
|
||||
allow_update = False
|
||||
allow_delete = False
|
||||
allow_list = False
|
||||
|
||||
@@ -391,6 +391,13 @@ class TestNetworkProxy(test_proxy_base.TestProxyBase):
|
||||
def test_quota_get(self):
|
||||
self.verify_get(self.proxy.get_quota, quota.Quota)
|
||||
|
||||
def test_quota_default_get(self):
|
||||
self.verify_get(self.proxy.get_quota_default, quota.QuotaDefault,
|
||||
value=[mock.sentinel.project_id],
|
||||
expected_args=[quota.QuotaDefault],
|
||||
expected_kwargs={"path_args": {
|
||||
"project": mock.sentinel.project_id}})
|
||||
|
||||
def test_quotas(self):
|
||||
self.verify_list(self.proxy.quotas, quota.Quota, paginated=False)
|
||||
|
||||
|
||||
@@ -66,3 +66,37 @@ class TestQuota(testtools.TestCase):
|
||||
self.assertEqual(EXAMPLE['loadbalancer'], sot.load_balancers)
|
||||
self.assertEqual(EXAMPLE['l7policy'], sot.l7_policies)
|
||||
self.assertEqual(EXAMPLE['pool'], sot.pools)
|
||||
|
||||
|
||||
class TestQuotaDefault(testtools.TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
default = quota.QuotaDefault()
|
||||
self.assertEqual('quota', default.resource_key)
|
||||
self.assertEqual('quotas', default.resources_key)
|
||||
self.assertEqual('/quotas/%(project)s/default', default.base_path)
|
||||
self.assertEqual('network', default.service.service_type)
|
||||
self.assertFalse(default.allow_create)
|
||||
self.assertTrue(default.allow_retrieve)
|
||||
self.assertFalse(default.allow_update)
|
||||
self.assertFalse(default.allow_delete)
|
||||
self.assertFalse(default.allow_list)
|
||||
|
||||
def test_make_it(self):
|
||||
default = quota.Quota(EXAMPLE)
|
||||
self.assertEqual(EXAMPLE['floatingip'], default.floating_ips)
|
||||
self.assertEqual(EXAMPLE['network'], default.networks)
|
||||
self.assertEqual(EXAMPLE['port'], default.ports)
|
||||
self.assertEqual(EXAMPLE['tenant_id'], default.project_id)
|
||||
self.assertEqual(EXAMPLE['router'], default.routers)
|
||||
self.assertEqual(EXAMPLE['subnet'], default.subnets)
|
||||
self.assertEqual(EXAMPLE['subnetpool'], default.subnet_pools)
|
||||
self.assertEqual(EXAMPLE['security_group_rule'],
|
||||
default.security_group_rules)
|
||||
self.assertEqual(EXAMPLE['security_group'], default.security_groups)
|
||||
self.assertEqual(EXAMPLE['rbac_policy'], default.rbac_policies)
|
||||
self.assertEqual(EXAMPLE['healthmonitor'], default.health_monitors)
|
||||
self.assertEqual(EXAMPLE['listener'], default.listeners)
|
||||
self.assertEqual(EXAMPLE['loadbalancer'], default.load_balancers)
|
||||
self.assertEqual(EXAMPLE['l7policy'], default.l7_policies)
|
||||
self.assertEqual(EXAMPLE['pool'], default.pools)
|
||||
|
||||
Reference in New Issue
Block a user