~openstack-gd/nova/multi-nic-exp-fix

« back to all changes in this revision

Viewing changes to nova/api/openstack/accounts.py

  • Committer: Mark Washenberger
  • Date: 2011-03-15 18:19:47 UTC
  • mfrom: (806 nova)
  • mto: This revision was merged to the branch mainline in revision 814.
  • Revision ID: mark.washenberger@rackspace.com-20110315181947-no5rfi12g7fa75sm
mergeĀ lp:nova

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2011 OpenStack LLC.
 
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
 
 
16
import common
 
17
 
 
18
from nova import exception
 
19
from nova import flags
 
20
from nova import log as logging
 
21
from nova import wsgi
 
22
 
 
23
from nova.auth import manager
 
24
from nova.api.openstack import faults
 
25
 
 
26
FLAGS = flags.FLAGS
 
27
LOG = logging.getLogger('nova.api.openstack')
 
28
 
 
29
 
 
30
def _translate_keys(account):
 
31
    return dict(id=account.id,
 
32
                name=account.name,
 
33
                description=account.description,
 
34
                manager=account.project_manager_id)
 
35
 
 
36
 
 
37
class Controller(wsgi.Controller):
 
38
 
 
39
    _serialization_metadata = {
 
40
        'application/xml': {
 
41
            "attributes": {
 
42
                "account": ["id", "name", "description", "manager"]}}}
 
43
 
 
44
    def __init__(self):
 
45
        self.manager = manager.AuthManager()
 
46
 
 
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."))
 
52
 
 
53
    def index(self, req):
 
54
        raise faults.Fault(exc.HTTPNotImplemented())
 
55
 
 
56
    def detail(self, req):
 
57
        raise faults.Fault(exc.HTTPNotImplemented())
 
58
 
 
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))
 
63
 
 
64
    def delete(self, req, id):
 
65
        self._check_admin(req.environ['nova.context'])
 
66
        self.manager.delete_project(id)
 
67
        return {}
 
68
 
 
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())
 
73
 
 
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')
 
80
        try:
 
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))