OpenStack Compute (Nova) Client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

quotas.py 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. from novaclient import base
  16. class QuotaSet(base.Resource):
  17. @property
  18. def id(self):
  19. """QuotaSet does not have a 'id' attribute but base.Resource needs it
  20. to self-refresh and QuotaSet is indexed by tenant_id.
  21. """
  22. return self.tenant_id
  23. def update(self, *args, **kwargs):
  24. return self.manager.update(self.tenant_id, *args, **kwargs)
  25. class QuotaSetManager(base.Manager):
  26. resource_class = QuotaSet
  27. def get(self, tenant_id, user_id=None):
  28. if hasattr(tenant_id, 'tenant_id'):
  29. tenant_id = tenant_id.tenant_id
  30. if user_id:
  31. url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id)
  32. else:
  33. url = '/os-quota-sets/%s' % tenant_id
  34. return self._get(url, "quota_set")
  35. def _update_body(self, tenant_id, **kwargs):
  36. kwargs['tenant_id'] = tenant_id
  37. return {'quota_set': kwargs}
  38. def update(self, tenant_id, **kwargs):
  39. user_id = kwargs.pop('user_id', None)
  40. body = self._update_body(tenant_id, **kwargs)
  41. for key in list(body['quota_set']):
  42. if body['quota_set'][key] is None:
  43. body['quota_set'].pop(key)
  44. if user_id:
  45. url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id)
  46. else:
  47. url = '/os-quota-sets/%s' % tenant_id
  48. return self._update(url, body, 'quota_set')
  49. def defaults(self, tenant_id):
  50. return self._get('/os-quota-sets/%s/defaults' % tenant_id,
  51. 'quota_set')
  52. def delete(self, tenant_id, user_id=None):
  53. if user_id:
  54. url = '/os-quota-sets/%s?user_id=%s' % (tenant_id, user_id)
  55. else:
  56. url = '/os-quota-sets/%s' % tenant_id
  57. self._delete(url)