def delete(self, req, id): """ Deletes the image and all its chunks from the Glance :param req: The WSGI/Webob Request object :param id: The opaque image identifier :raises HttpBadRequest if image registry is invalid :raises HttpNotFound if image or any chunk is not available :raises HttpNotAuthorized if image or any chunk is not deleteable by the requesting user """ if req.context.read_only: msg = "Read-only access" logger.debug(msg) raise HTTPForbidden(msg, request=req, content_type="text/plain") image = self.get_image_meta_or_404(req, id) # The image's location field may be None in the case # of a saving or queued image, therefore don't ask a backend # to delete the image if the backend doesn't yet store it. # See https://bugs.launchpad.net/glance/+bug/747799 if image['location']: schedule_delete_from_backend(image['location'], self.options, req.context, id) registry.delete_image_metadata(self.options, req.context, id)
def delete(self, req, id): """ Deletes the image and all its chunks from the Glance :param req: The WSGI/Webob Request object :param id: The opaque image identifier :raises HttpBadRequest if image registry is invalid :raises HttpNotFound if image or any chunk is not available :raises HttpNotAuthorized if image or any chunk is not deleteable by the requesting user """ if req.context.read_only: msg = _("Read-only access") logger.debug(msg) raise HTTPForbidden(msg, request=req, content_type="text/plain") image = self.get_image_meta_or_404(req, id) # The image's location field may be None in the case # of a saving or queued image, therefore don't ask a backend # to delete the image if the backend doesn't yet store it. # See https://bugs.launchpad.net/glance/+bug/747799 try: if image['location']: schedule_delete_from_backend(image['location'], self.options, req.context, id) registry.delete_image_metadata(self.options, req.context, id) except exception.NotFound, e: msg = ("Failed to find image to delete: %(e)s" % locals()) for line in msg.split('\n'): logger.info(line) self.notifier.info('image.delete', msg) raise HTTPNotFound(msg, request=req, content_type="text/plain")
def test_http_schedule_delete_swallows_error(self): uri = "https://netloc/path/to/file.tar.gz" ctx = context.RequestContext() stub_out_registry_image_update(self.stubs) try: schedule_delete_from_backend(uri, ctx, "image_id") except exception.StoreDeleteNotSupported: self.fail("StoreDeleteNotSupported should be swallowed")
def test_http_schedule_delete_swallows_error(self): uri = "https://netloc/path/to/file.tar.gz" ctx = context.RequestContext() stub_out_registry_image_update(self.stubs, self.conf) try: schedule_delete_from_backend(uri, self.conf, ctx, 'image_id') except exception.StoreDeleteNotSupported: self.fail('StoreDeleteNotSupported should be swallowed')
def delete(self, req, id): """ Deletes the image and all its chunks from the Glance :param req: The WSGI/Webob Request object :param id: The opaque image identifier :raises HttpBadRequest if image registry is invalid :raises HttpNotFound if image or any chunk is not available :raises HttpUnauthorized if image or any chunk is not deleteable by the requesting user """ self._enforce(req, 'delete_image') if req.context.read_only: msg = _("Read-only access") logger.debug(msg) raise HTTPForbidden(msg, request=req, content_type="text/plain") image = self.get_image_meta_or_404(req, id) if image['protected']: msg = _("Image is protected") logger.debug(msg) raise HTTPForbidden(msg, request=req, content_type="text/plain") # The image's location field may be None in the case # of a saving or queued image, therefore don't ask a backend # to delete the image if the backend doesn't yet store it. # See https://bugs.launchpad.net/glance/+bug/747799 try: if image['location']: schedule_delete_from_backend(image['location'], self.conf, req.context, id) registry.delete_image_metadata(req.context, id) except exception.NotFound, e: msg = ("Failed to find image to delete: %(e)s" % locals()) for line in msg.split('\n'): logger.info(line) self.notifier.info('image.delete', msg) raise HTTPNotFound(msg, request=req, content_type="text/plain")