~ubuntu-cloud-archive/ubuntu/precise/nova/trunk

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-06-17 13:29:16 UTC
  • mto: (94.1.1 raring-proposed)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: james.westby@ubuntu.com-20110617132916-u3vv6rxmtvnfn4cj
Tags: upstream-2011.3~d2~20110617.1191
ImportĀ upstreamĀ versionĀ 2011.3~d2~20110617.1191

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from nova import log as logging
21
21
 
22
22
from nova.auth import manager
23
 
from nova.api.openstack import common
24
23
from nova.api.openstack import faults
 
24
from nova.api.openstack import wsgi
 
25
 
25
26
 
26
27
FLAGS = flags.FLAGS
27
28
LOG = logging.getLogger('nova.api.openstack')
34
35
                manager=account.project_manager_id)
35
36
 
36
37
 
37
 
class Controller(common.OpenstackController):
38
 
 
39
 
    _serialization_metadata = {
40
 
        'application/xml': {
41
 
            "attributes": {
42
 
                "account": ["id", "name", "description", "manager"]}}}
 
38
class Controller(object):
43
39
 
44
40
    def __init__(self):
45
41
        self.manager = manager.AuthManager()
66
62
        self.manager.delete_project(id)
67
63
        return {}
68
64
 
69
 
    def create(self, req):
 
65
    def create(self, req, body):
70
66
        """We use update with create-or-update semantics
71
67
           because the id comes from an external source"""
72
68
        raise faults.Fault(webob.exc.HTTPNotImplemented())
73
69
 
74
 
    def update(self, req, id):
 
70
    def update(self, req, id, body):
75
71
        """This is really create or update."""
76
72
        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')
 
73
        description = body['account'].get('description')
 
74
        manager = body['account'].get('manager')
80
75
        try:
81
76
            account = self.manager.get_project(id)
82
77
            self.manager.modify_project(id, manager, description)
83
78
        except exception.NotFound:
84
79
            account = self.manager.create_project(id, manager, description)
85
80
        return dict(account=_translate_keys(account))
 
81
 
 
82
 
 
83
def create_resource():
 
84
    metadata = {
 
85
        "attributes": {
 
86
            "account": ["id", "name", "description", "manager"],
 
87
        },
 
88
    }
 
89
 
 
90
    serializers = {
 
91
        'application/xml': wsgi.XMLDictSerializer(metadata=metadata),
 
92
    }
 
93
 
 
94
    return wsgi.Resource(Controller(), serializers=serializers)