add support for quotas
This commit is contained in:
parent
811ba10e51
commit
17208cec6a
@ -2,6 +2,7 @@ from novaclient import client
|
||||
from novaclient.v1_1 import flavors
|
||||
from novaclient.v1_1 import images
|
||||
from novaclient.v1_1 import servers
|
||||
from novaclient.v1_1 import quotas
|
||||
from novaclient.v1_1 import zones
|
||||
|
||||
|
||||
@ -28,6 +29,7 @@ class Client(object):
|
||||
self.images = images.ImageManager(self)
|
||||
self.servers = servers.ServerManager(self)
|
||||
self.zones = zones.ZoneManager(self)
|
||||
self.quotas = quotas.QuotaSetManager(self)
|
||||
|
||||
self.client = client.HTTPClient(username,
|
||||
api_key,
|
||||
|
58
novaclient/v1_1/quotas.py
Normal file
58
novaclient/v1_1/quotas.py
Normal file
@ -0,0 +1,58 @@
|
||||
from novaclient import base
|
||||
|
||||
|
||||
class QuotaSet(base.Resource):
|
||||
def get(self):
|
||||
self.manager.get(self)
|
||||
|
||||
def delete(self):
|
||||
self.manager.delete(self)
|
||||
|
||||
def update(self, *args, **kwargs):
|
||||
self.manager.update(self.tenant_id, *args, **kwargs)
|
||||
|
||||
|
||||
class QuotaSetManager(base.ManagerWithFind):
|
||||
resource_class = QuotaSet
|
||||
|
||||
def list(self, defaults=False):
|
||||
if defaults == True:
|
||||
return self._list('/os-quotas?defaults=True',
|
||||
'quota_set_list')
|
||||
else:
|
||||
return self._list("/os-quotas", "quota_set_list")
|
||||
|
||||
def get(self, tenant_id):
|
||||
if hasattr(tenant_id, 'tenant_id'):
|
||||
tenant_id = tenant_id.tenant_id
|
||||
return self._get("/os-quotas/%s" % (tenant_id), "quota_set")
|
||||
|
||||
def update(self, tenant_id, metadata_items=None,
|
||||
injected_file_content_bytes=None, volumes=None, gigabytes=None,
|
||||
ram=None, floating_ips=None, instances=None, injected_files=None,
|
||||
cores=None):
|
||||
|
||||
body = {'quota_set': {
|
||||
'tenant_id': tenant_id,
|
||||
'metadata_items': metadata_items,
|
||||
'injected_file_content_bytes': injected_file_content_bytes,
|
||||
'volumes': volumes,
|
||||
'gigabytes': gigabytes,
|
||||
'ram': ram,
|
||||
'floating_ips': floating_ips,
|
||||
'instances': instances,
|
||||
'injected_files': injected_files,
|
||||
'cores': cores,
|
||||
}}
|
||||
|
||||
for key in body['quota_set'].keys():
|
||||
if body['quota_set'][key] == None:
|
||||
body['quota_set'].pop(key)
|
||||
|
||||
return self._update('/os-quotas/%s' % (tenant_id), body)
|
||||
|
||||
def delete(self, tenant_id):
|
||||
if hasattr(tenant_id, 'tenant_id'):
|
||||
tenant_id = tenant_id.tenant_id
|
||||
self._delete("/os-quotas/%s" % (tenant_id))
|
||||
|
@ -32,6 +32,7 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
|
||||
# Call the method
|
||||
munged_url = url.strip('/').replace('/', '_').replace('.', '_')
|
||||
munged_url = munged_url.replace('-', '_')
|
||||
callback = "%s_%s" % (method.lower(), munged_url)
|
||||
if not hasattr(self, callback):
|
||||
raise AssertionError('Called unknown API method: %s %s' % (method,
|
||||
@ -373,3 +374,45 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
|
||||
def delete_zones_1(self, **kw):
|
||||
return (202, None)
|
||||
|
||||
#
|
||||
# Keypairs
|
||||
#
|
||||
def get_os_quotas(self, *kw):
|
||||
return (200, {'quota_set_list': [{
|
||||
'tenant_id': 'test',
|
||||
'metadata_items': [],
|
||||
'injected_file_content_bytes': 1,
|
||||
'volumes': 1,
|
||||
'gigabytes': 1,
|
||||
'ram': 1,
|
||||
'floating_ips': 1,
|
||||
'instances': 1,
|
||||
'injected_files': 1,
|
||||
'cores': 1,
|
||||
}]})
|
||||
|
||||
def get_os_quotas_test(self, *kw):
|
||||
return (200, {'quota_set': {
|
||||
'tenant_id': 'test',
|
||||
'metadata_items': [],
|
||||
'injected_file_content_bytes': 1,
|
||||
'volumes': 1,
|
||||
'gigabytes': 1,
|
||||
'ram': 1,
|
||||
'floating_ips': 1,
|
||||
'instances': 1,
|
||||
'injected_files': 1,
|
||||
'cores': 1,
|
||||
}})
|
||||
|
||||
def delete_os_quotas_test(self, **kw):
|
||||
return (202, None)
|
||||
|
||||
def put_os_quotas_test(self, body, **kw):
|
||||
assert body.keys() == ['quota_set']
|
||||
fakes.assert_has_keys(body['quota_set'],
|
||||
required=['tenant_id'])
|
||||
r = self.get_os_quotas_test()[1]
|
||||
return (200, r)
|
||||
|
||||
|
28
tests/v1_1/test_quotas.py
Normal file
28
tests/v1_1/test_quotas.py
Normal file
@ -0,0 +1,28 @@
|
||||
from novaclient import exceptions
|
||||
from novaclient.v1_1 import quotas
|
||||
from tests.v1_1 import fakes
|
||||
from tests import utils
|
||||
|
||||
|
||||
cs = fakes.FakeClient()
|
||||
|
||||
|
||||
class QuoatsTest(utils.TestCase):
|
||||
def test_list_quotas(self):
|
||||
qs = cs.quotas.list()
|
||||
cs.assert_called('GET', '/os-quotas')
|
||||
[self.assertTrue(isinstance(q, quotas.QuotaSet)) for q in qs]
|
||||
|
||||
def test_delete_quota(self):
|
||||
q = cs.quotas.list()[0]
|
||||
q.delete()
|
||||
cs.assert_called('DELETE', '/os-quotas/test')
|
||||
cs.quotas.delete('test')
|
||||
cs.assert_called('DELETE', '/os-quotas/test')
|
||||
cs.quotas.delete(q)
|
||||
cs.assert_called('DELETE', '/os-quotas/test')
|
||||
|
||||
def test_update_quota(self):
|
||||
q = cs.quotas.list()[0]
|
||||
q.update(volumes=2)
|
||||
cs.assert_called('PUT', '/os-quotas/test')
|
Loading…
x
Reference in New Issue
Block a user