def update(self, req, id, body): """ Updates an existing image with the registry. :param req: wsgi Request object :param body: Dictionary of information about the image :param id: The opaque internal identifier for the image :retval Returns the updated image information as a mapping, """ if req.context.read_only: raise exc.HTTPForbidden() image_data = body['image'] # Prohibit modification of 'owner' if not req.context.is_admin and 'owner' in image_data: del image_data['owner'] purge_props = req.headers.get("X-Glance-Registry-Purge-Props", "false") try: logger.debug(_("Updating image %(id)s with metadata: " "%(image_data)r") % locals()) if purge_props == "true": updated_image = db_api.image_update(req.context, id, image_data, True) else: updated_image = db_api.image_update(req.context, id, image_data) return dict(image=make_image_dict(updated_image)) except exception.Invalid, e: msg = (_("Failed to update image metadata. " "Got error: %(e)s") % locals()) logger.error(msg) return exc.HTTPBadRequest(msg)
def update(self, req, id): """Updates an existing image with the registry. :param req: Request body. A JSON-ified dict of information about the image. This will replace the information in the registry about this image :param id: The opaque internal identifier for the image :retval Returns the updated image information as a mapping, """ image_data = json.loads(req.body)['image'] purge_props = req.headers.get("X-Glance-Registry-Purge-Props", "false") context = None try: logger.debug("Updating image %(id)s with metadata: %(image_data)r" % locals()) if purge_props == "true": updated_image = db_api.image_update(context, id, image_data, True) else: updated_image = db_api.image_update(context, id, image_data) return dict(image=make_image_dict(updated_image)) except exception.Invalid, e: msg = ("Failed to update image metadata. " "Got error: %(e)s" % locals()) logger.error(msg) return exc.HTTPBadRequest(msg)
def _delete(self, image_id, location): try: logger.debug(_("Deleting %(location)s") % locals()) store.delete_from_backend(location) except (store.UnsupportedBackend, exception.NotFound): msg = _("Failed to delete image from store (%(uri)s).") % locals() logger.error(msg) ctx = context.RequestContext(is_admin=True, show_deleted=True) db_api.image_update(ctx, image_id, {'status': 'deleted'})
def _delete(self, id, location): try: logger.debug("Deleting %s" % location) store.delete_from_backend(location) except (store.UnsupportedBackend, exception.NotFound): msg = "Failed to delete image from store (%s). " logger.error(msg % uri) ctx = context.RequestContext(is_admin=True, show_deleted=True) db_api.image_update(ctx, id, {"status": "deleted"})