def delete_item(self, context, name, scope=None): """Delete an image, if allowed.""" image = self.get_item(context, name, scope) image_service = clients.glance(context).images operation_util.start_operation(context, self._get_delete_item_progress, image["id"]) image_service.delete(image["id"]) self._delete_db_item(context, image)
def _get_delete_item_progress(self, context, image_id): image_service = clients.glance(context).images try: image = image_service.get(image_id) if image.status in self._deleted_statuses: return operation_api.gef_final_progress() except glanceclient_exc.HTTPNotFound: return operation_api.gef_final_progress()
def _get_add_item_progress(self, context, image_id): image_service = clients.glance(context).images try: image = image_service.get(image_id) except glanceclient_exc.HTTPNotFound: return operation_api.gef_final_progress() if image.status not in ["queued", "saving"]: return operation_api.gef_final_progress(image.status == "killed")
def _get_delete_item_progress(self, context, image_id): image_service = clients.glance(context).images try: image = image_service.get(image_id) if image.status in self._deleted_statuses: return operation_util.get_final_progress() except glanceclient_exc.HTTPNotFound: return operation_util.get_final_progress() return None
def _get_add_item_progress(self, context, image_id): image_service = clients.glance(context).images try: image = image_service.get(image_id) except glanceclient_exc.HTTPNotFound: return operation_util.get_final_progress() if image.status not in ["queued", "saving"]: return operation_util.get_final_progress(image.status == "killed") return None
def get_items(self, context, scope=None): image_service = clients.glance(context).images # NOTE(apavlov): Currently glance doesn't report "killed" images in # list which causes incompatibility with GCE which reports # corresponding "FAILED" images if upload has failed. images = image_service.list(filters={"disk_format": "raw"}) items = list() gce_images = self._get_db_items_dict(context) for image in images: result = self._prepare_image(utils.to_dict(image)) self._prepare_item(result, gce_images.get(result["id"])) items.append(result) self._purge_db(context, items, gce_images) return items
def get_item(self, context, name, scope=None): image_service = clients.glance(context).images images = image_service.list(filters={"name": name, "disk_format": "raw"}) result = None for image in images: if image.status in self._deleted_statuses: continue if result: msg = _("Image resource '%s' found more than once") % name raise exception.NotFound(msg) result = self._prepare_image(utils.to_dict(image)) db_image = self._get_db_item_by_id(context, result["id"]) self._prepare_item(result, db_image) if not result: msg = _("Image resource '%s' could not be found") % name raise exception.NotFound(msg) return result
def get_item(self, context, name, scope=None): image_service = clients.glance(context).images images = image_service.list( filters={"name": name, "disk_format": "raw"}) result = None for image in images: if image.status in self._deleted_statuses: continue if result: msg = _("Image resource '%s' found more than once") % name raise exception.NotFound(msg) result = self._prepare_image(utils.to_dict(image)) db_image = self._get_db_item_by_id(context, result["id"]) self._prepare_item(result, db_image) if not result: msg = _("Image resource '%s' could not be found") % name raise exception.NotFound(msg) return result
def add_item(self, context, name, body, scope=None): name = body["name"] image_ref = body["rawDisk"]["source"] meta = { "name": name, "disk_format": "raw", "container_format": "bare", "min_disk": 0, "min_ram": 0, "copy_from": image_ref, } image_service = clients.glance(context).images operation_util.start_operation(context, self._get_add_item_progress) image = image_service.create(**meta) operation_util.set_item_id(context, image.id, self.KIND) new_image = self._prepare_image(utils.to_dict(image)) new_image["description"] = body.get("description", "") new_image["image_ref"] = image_ref new_image = self._add_db_item(context, new_image) return new_image
def add_item(self, context, name, body, scope=None): name = body['name'] image_ref = body['rawDisk']['source'] meta = { 'name': name, 'disk_format': 'raw', 'container_format': 'bare', 'min_disk': 0, 'min_ram': 0, 'copy_from': image_ref, } image_service = clients.glance(context).images operation_util.start_operation(context, self._get_add_item_progress) image = image_service.create(**meta) operation_util.set_item_id(context, image.id, self.KIND) new_image = self._prepare_image(utils.to_dict(image)) new_image["description"] = body.get("description", "") new_image["image_ref"] = image_ref new_image = self._add_db_item(context, new_image) return new_image
def add_item(self, context, name, body, scope=None): name = body['name'] image_ref = body['rawDisk']['source'] meta = { 'name': name, 'disk_format': 'raw', 'container_format': 'bare', 'min_disk': 0, 'min_ram': 0, 'copy_from': image_ref, } image_service = clients.glance(context).images operation_util.start_operation(context, self._get_add_item_progress) image = image_service.create(**meta) operation_util.set_item_id(context, image.id) new_image = self._prepare_image(utils.to_dict(image)) new_image["description"] = body.get("description", "") new_image["image_ref"] = image_ref new_image = self._add_db_item(context, new_image) return new_image