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.7KB

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. return self.tenant_id
  22. def update(self, *args, **kwargs):
  23. return self.manager.update(self.tenant_id, *args, **kwargs)
  24. class QuotaSetManager(base.Manager):
  25. resource_class = QuotaSet
  26. def get(self, tenant_id):
  27. if hasattr(tenant_id, 'tenant_id'):
  28. tenant_id = tenant_id.tenant_id
  29. return self._get("/os-quota-sets/%s" % (tenant_id), "quota_set")
  30. def update(self, tenant_id, force=None, metadata_items=None,
  31. injected_file_content_bytes=None, injected_file_path_bytes=None,
  32. volumes=None, gigabytes=None,
  33. ram=None, floating_ips=None, fixed_ips=None, instances=None,
  34. injected_files=None, cores=None, key_pairs=None,
  35. security_groups=None, security_group_rules=None):
  36. body = {'quota_set': {
  37. 'tenant_id': tenant_id,
  38. 'metadata_items': metadata_items,
  39. 'key_pairs': key_pairs,
  40. 'injected_file_content_bytes': injected_file_content_bytes,
  41. 'injected_file_path_bytes': injected_file_path_bytes,
  42. 'volumes': volumes,
  43. 'gigabytes': gigabytes,
  44. 'ram': ram,
  45. 'floating_ips': floating_ips,
  46. 'fixed_ips': fixed_ips,
  47. 'instances': instances,
  48. 'injected_files': injected_files,
  49. 'cores': cores,
  50. 'security_groups': security_groups,
  51. 'security_group_rules': security_group_rules,
  52. 'force': force}}
  53. for key in body['quota_set'].keys():
  54. if body['quota_set'][key] is None:
  55. body['quota_set'].pop(key)
  56. return self._update('/os-quota-sets/%s' % tenant_id, body, 'quota_set')
  57. def defaults(self, tenant_id):
  58. return self._get('/os-quota-sets/%s/defaults' % tenant_id,
  59. 'quota_set')