def create(self, req, body): """ Registers a new image with the registry. :param req: wsgi Request object :param body: Dictionary of information about the image :retval Returns the newly-created image information as a mapping, which will include the newly-created image's internal id in the 'id' field """ if req.context.read_only: raise exc.HTTPForbidden() image_data = body['image'] # Ensure the image has a status set image_data.setdefault('status', 'active') # Set up the image owner if not req.context.is_admin or 'owner' not in image_data: image_data['owner'] = req.context.owner image_id = image_data.get('id') if image_id and not utils.is_uuid_like(image_id): msg = _("Invalid image id format") return exc.HTTPBadRequest(explanation=msg) try: image_data = db_api.image_create(req.context, image_data) return dict(image=make_image_dict(image_data)) except exception.Duplicate: msg = (_("Image with identifier %s already exists!") % id) logger.error(msg) return exc.HTTPConflict(msg) except exception.Invalid, e: msg = (_("Failed to add image metadata. " "Got error: %(e)s") % locals()) logger.error(msg) return exc.HTTPBadRequest(msg)
def create_fixtures(self): for fixture in FIXTURES: db_api.image_create(self.adm_context, fixture)