1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2011 OpenStack LLC.
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
# not use this file except in compliance with the License. You may obtain
8
# a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
# License for the specific language governing permissions and limitations
21
from nova import exception
22
from nova import quota
23
from nova.api.openstack import extensions
26
class QuotaSetsController(object):
28
def _format_quota_set(self, project_id, quota_set):
29
"""Convert the quota object to a result dict"""
31
return {'quota_set': {
32
'id': str(project_id),
33
'metadata_items': quota_set['metadata_items'],
34
'injected_file_content_bytes':
35
quota_set['injected_file_content_bytes'],
36
'volumes': quota_set['volumes'],
37
'gigabytes': quota_set['gigabytes'],
38
'ram': quota_set['ram'],
39
'floating_ips': quota_set['floating_ips'],
40
'instances': quota_set['instances'],
41
'injected_files': quota_set['injected_files'],
42
'cores': quota_set['cores'],
45
def show(self, req, id):
46
context = req.environ['nova.context']
48
db.sqlalchemy.api.authorize_project_context(context, id)
49
return self._format_quota_set(id,
50
quota.get_project_quotas(context, id))
51
except exception.NotAuthorized:
52
return webob.Response(status_int=403)
54
def update(self, req, id, body):
55
context = req.environ['nova.context']
57
resources = ['metadata_items', 'injected_file_content_bytes',
58
'volumes', 'gigabytes', 'ram', 'floating_ips', 'instances',
59
'injected_files', 'cores']
60
for key in body['quota_set'].keys():
62
value = int(body['quota_set'][key])
64
db.quota_update(context, project_id, key, value)
65
except exception.ProjectQuotaNotFound:
66
db.quota_create(context, project_id, key, value)
67
except exception.AdminRequired:
68
return webob.Response(status_int=403)
69
return {'quota_set': quota.get_project_quotas(context, project_id)}
71
def defaults(self, req, id):
72
return self._format_quota_set(id, quota._get_default_quotas())
75
class Quotas(extensions.ExtensionDescriptor):
81
return "os-quota-sets"
83
def get_description(self):
84
return "Quotas management support"
86
def get_namespace(self):
87
return "http://docs.openstack.org/ext/quotas-sets/api/v1.1"
89
def get_updated(self):
90
return "2011-08-08T00:00:00+00:00"
92
def get_resources(self):
95
res = extensions.ResourceExtension('os-quota-sets',
96
QuotaSetsController(),
97
member_actions={'defaults': 'GET'})