summaryrefslogtreecommitdiff
path: root/novaclient/v2/quotas.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/v2/quotas.py')
-rw-r--r--novaclient/v2/quotas.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/novaclient/v2/quotas.py b/novaclient/v2/quotas.py
new file mode 100644
index 0000000..cd16042
--- /dev/null
+++ b/novaclient/v2/quotas.py
@@ -0,0 +1,72 @@
1# Copyright 2011 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from novaclient import base
17
18
19class QuotaSet(base.Resource):
20
21 @property
22 def id(self):
23 """QuotaSet does not have a 'id' attribute but base.Resource needs it
24 to self-refresh and QuotaSet is indexed by tenant_id.
25 """
26 return self.tenant_id
27
28 def update(self, *args, **kwargs):
29 return self.manager.update(self.tenant_id, *args, **kwargs)
30
31
32class QuotaSetManager(base.Manager):
33 resource_class = QuotaSet
34
35 def get(self, tenant_id, user_id=None):
36 if hasattr(tenant_id, 'tenant_id'):
37 tenant_id = tenant_id.tenant_id
38 if user_id:
39 url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id)
40 else:
41 url = '/os-quota-sets/%s' % tenant_id
42 return self._get(url, "quota_set")
43
44 def _update_body(self, tenant_id, **kwargs):
45 kwargs['tenant_id'] = tenant_id
46 return {'quota_set': kwargs}
47
48 def update(self, tenant_id, **kwargs):
49
50 user_id = kwargs.pop('user_id', None)
51 body = self._update_body(tenant_id, **kwargs)
52
53 for key in list(body['quota_set']):
54 if body['quota_set'][key] is None:
55 body['quota_set'].pop(key)
56
57 if user_id:
58 url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id)
59 else:
60 url = '/os-quota-sets/%s' % tenant_id
61 return self._update(url, body, 'quota_set')
62
63 def defaults(self, tenant_id):
64 return self._get('/os-quota-sets/%s/defaults' % tenant_id,
65 'quota_set')
66
67 def delete(self, tenant_id, user_id=None):
68 if user_id:
69 url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id)
70 else:
71 url = '/os-quota-sets/%s' % tenant_id
72 self._delete(url)