1
# Copyright 2011 OpenStack LLC.
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
8
# http://www.apache.org/licenses/LICENSE-2.0
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
18
from nova import exception
19
from nova import flags
20
from nova import log as logging
22
from nova.auth import manager
23
from nova.api.openstack import faults
24
from nova.api.openstack import wsgi
28
LOG = logging.getLogger('nova.api.openstack')
31
def _translate_keys(account):
32
return dict(id=account.id,
34
description=account.description,
35
manager=account.project_manager_id)
38
class Controller(object):
41
self.manager = manager.AuthManager()
43
def _check_admin(self, context):
44
"""We cannot depend on the db layer to check for admin access
45
for the auth manager, so we do it here"""
46
if not context.is_admin:
47
raise exception.AdminRequired()
50
raise webob.exc.HTTPNotImplemented()
52
def detail(self, req):
53
raise webob.exc.HTTPNotImplemented()
55
def show(self, req, id):
56
"""Return data about the given account id"""
57
account = self.manager.get_project(id)
58
return dict(account=_translate_keys(account))
60
def delete(self, req, id):
61
self._check_admin(req.environ['nova.context'])
62
self.manager.delete_project(id)
65
def create(self, req, body):
66
"""We use update with create-or-update semantics
67
because the id comes from an external source"""
68
raise webob.exc.HTTPNotImplemented()
70
def update(self, req, id, body):
71
"""This is really create or update."""
72
self._check_admin(req.environ['nova.context'])
73
description = body['account'].get('description')
74
manager = body['account'].get('manager')
76
account = self.manager.get_project(id)
77
self.manager.modify_project(id, manager, description)
78
except exception.NotFound:
79
account = self.manager.create_project(id, manager, description)
80
return dict(account=_translate_keys(account))
83
def create_resource():
86
"account": ["id", "name", "description", "manager"],
91
'application/xml': wsgi.XMLDictSerializer(metadata=metadata),
93
serializer = wsgi.ResponseSerializer(body_serializers)
94
return wsgi.Resource(Controller(), serializer=serializer)