~jaypipes/glance/api-add-image

« back to all changes in this revision

Viewing changes to glance/registry/controllers.py

  • Committer: Tarmac
  • Author(s): jaypipes at gmail
  • Date: 2010-12-17 16:37:06 UTC
  • mfrom: (24.1.9 refactoring)
  • Revision ID: tarmac-20101217163706-6lvp8gu58tifeksv
Major refactoring...

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
from glance.common import wsgi
26
26
from glance.common import exception
27
 
from glance.parallax import db
 
27
from glance.registry import db
28
28
 
29
29
 
30
30
class ImageController(wsgi.Controller):
74
74
        return dict(image=make_image_dict(image))
75
75
 
76
76
    def delete(self, req, id):
77
 
        """Deletes an existing image with the registry.
 
77
        """
 
78
        Deletes an existing image with the registry.
78
79
 
79
80
        :param req: Request body.  Ignored.
80
81
        :param id:  The opaque internal identifier for the image
89
90
            return exc.HTTPNotFound()
90
91
 
91
92
    def create(self, req):
92
 
        """Registers a new image with the registry.
 
93
        """
 
94
        Registers a new image with the registry.
93
95
 
94
96
        :param req: Request body.  A JSON-ified dict of information about
95
97
                    the image.
106
108
 
107
109
        context = None
108
110
        try:
109
 
            new_image = db.image_create(context, image_data)
110
 
            return dict(image=new_image)
 
111
            image_data = db.image_create(context, image_data)
 
112
            return dict(image=make_image_dict(image_data))
111
113
        except exception.Duplicate:
112
114
            return exc.HTTPConflict()
113
115
        except exception.Invalid:
129
131
        context = None
130
132
        try:
131
133
            updated_image = db.image_update(context, id, image_data)
132
 
            return dict(image=updated_image)
 
134
            return dict(image=make_image_dict(updated_image))
133
135
        except exception.NotFound:
134
136
            return exc.HTTPNotFound()
135
137
 
136
138
 
137
139
class API(wsgi.Router):
138
 
    """WSGI entry point for all Parallax requests."""
 
140
    """WSGI entry point for all Registry requests."""
139
141
 
140
142
    def __init__(self):
141
 
        # TODO(sirp): should we add back the middleware for parallax?
 
143
        # TODO(sirp): should we add back the middleware for registry?
142
144
        mapper = routes.Mapper()
143
145
        mapper.resource("image", "images", controller=ImageController(),
144
146
                       collection={'detail': 'GET'})
156
158
        return dict([(a, d[a]) for a in attrs
157
159
                    if a in d.keys()])
158
160
 
159
 
    files = [_fetch_attrs(f, db.IMAGE_FILE_ATTRS) for f in image['files']]
160
 
 
161
161
    # TODO(sirp): should this be a dict, or a list of dicts?
162
162
    # A plain dict is more convenient, but list of dicts would provide
163
163
    # access to created_at, etc
166
166
 
167
167
    image_dict = _fetch_attrs(image, db.IMAGE_ATTRS)
168
168
 
169
 
    image_dict['files'] = files
170
169
    image_dict['properties'] = properties
171
170
    return image_dict