コード例 #1
0
ファイル: image_api.py プロジェクト: wiltood/gce-api
 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)
コード例 #2
0
ファイル: image_api.py プロジェクト: tshrklr/gce-api
 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()
コード例 #3
0
ファイル: image_api.py プロジェクト: tshrklr/gce-api
 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")
コード例 #4
0
 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)
コード例 #5
0
 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
コード例 #6
0
 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
コード例 #7
0
ファイル: image_api.py プロジェクト: wiltood/gce-api
 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
コード例 #8
0
 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
コード例 #9
0
ファイル: image_api.py プロジェクト: wiltood/gce-api
 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
コード例 #10
0
 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
コード例 #11
0
ファイル: image_api.py プロジェクト: wiltood/gce-api
    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
コード例 #12
0
    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
コード例 #13
0
ファイル: image_api.py プロジェクト: tshrklr/gce-api
    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