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
23
from nova.auth import manager
24
from nova.api.openstack import faults
27
LOG = logging.getLogger('nova.api.openstack')
30
def _translate_keys(account):
31
return dict(id=account.id,
33
description=account.description,
34
manager=account.project_manager_id)
37
class Controller(wsgi.Controller):
39
_serialization_metadata = {
42
"account": ["id", "name", "description", "manager"]}}}
45
self.manager = manager.AuthManager()
47
def _check_admin(self, context):
48
"""We cannot depend on the db layer to check for admin access
49
for the auth manager, so we do it here"""
50
if not context.is_admin:
51
raise exception.NotAuthorized(_("Not admin user."))
54
raise faults.Fault(exc.HTTPNotImplemented())
56
def detail(self, req):
57
raise faults.Fault(exc.HTTPNotImplemented())
59
def show(self, req, id):
60
"""Return data about the given account id"""
61
account = self.manager.get_project(id)
62
return dict(account=_translate_keys(account))
64
def delete(self, req, id):
65
self._check_admin(req.environ['nova.context'])
66
self.manager.delete_project(id)
69
def create(self, req):
70
"""We use update with create-or-update semantics
71
because the id comes from an external source"""
72
raise faults.Fault(exc.HTTPNotImplemented())
74
def update(self, req, id):
75
"""This is really create or update."""
76
self._check_admin(req.environ['nova.context'])
77
env = self._deserialize(req.body, req.get_content_type())
78
description = env['account'].get('description')
79
manager = env['account'].get('manager')
81
account = self.manager.get_project(id)
82
self.manager.modify_project(id, manager, description)
83
except exception.NotFound:
84
account = self.manager.create_project(id, manager, description)
85
return dict(account=_translate_keys(account))