コード例 #1
0
ファイル: module.py プロジェクト: houbin0504/ceph-1
    def queue_flatten(self, image_spec):
        image_spec = self.extract_image_spec(image_spec)
        self.log.info("queue_flatten: {}".format(image_spec))

        refs = {TASK_REF_ACTION: TASK_REF_ACTION_FLATTEN,
                TASK_REF_POOL_NAME: image_spec[0],
                TASK_REF_POOL_NAMESPACE: image_spec[1],
                TASK_REF_IMAGE_NAME: image_spec[2]}
        task = self.find_task(refs)
        if task:
            return 0, task.to_json(), ''

        with self.open_ioctx(image_spec) as ioctx:
            with rbd.Image(ioctx, image_spec[2]) as image:
                try:
                    image.parent_id()
                except rbd.ImageNotFound:
                    raise rbd.ImageNotFound("Image {} does not have a parent".format(
                        self.format_image_spec(image_spec)), errno=errno.ENOENT)

            return 0, self.add_task(ioctx,
                                    "Flattening image {}".format(
                                        self.format_image_spec(image_spec)),
                                    {TASK_REF_ACTION: TASK_REF_ACTION_FLATTEN,
                                     TASK_REF_POOL_NAME: image_spec[0],
                                     TASK_REF_POOL_NAMESPACE: image_spec[1],
                                     TASK_REF_IMAGE_NAME: image_spec[2]}), ""
コード例 #2
0
    def queue_remove(self, image_spec):
        image_spec = self.extract_image_spec(image_spec)

        authorize_request(self.module, image_spec[0], image_spec[1])
        self.log.info("queue_remove: {}".format(image_spec))

        refs = {TASK_REF_ACTION: TASK_REF_ACTION_REMOVE,
                TASK_REF_POOL_NAME: image_spec[0],
                TASK_REF_POOL_NAMESPACE: image_spec[1],
                TASK_REF_IMAGE_NAME: image_spec[2]}

        with self.open_ioctx(image_spec) as ioctx:
            try:
                with rbd.Image(ioctx, image_spec[2]) as image:
                    refs[TASK_REF_IMAGE_ID] = image.id()
                    snaps = list(image.list_snaps())

            except rbd.ImageNotFound:
                pass

            task = self.find_task(refs)
            if task:
                return 0, task.to_json(), ''

            if TASK_REF_IMAGE_ID not in refs:
                raise rbd.ImageNotFound("Image {} does not exist".format(
                    self.format_image_spec(image_spec)), errno=errno.ENOENT)
            if snaps:
                raise rbd.ImageBusy("Image {} has snapshots".format(
                    self.format_image_spec(image_spec)), errno=errno.EBUSY)

            return 0, self.add_task(ioctx,
                                    "Removing image {}".format(
                                        self.format_image_spec(image_spec)),
                                    refs), ''
コード例 #3
0
ファイル: task.py プロジェクト: zqlzhang511/ceph
    def queue_flatten(self, image_spec):
        image_spec = self.extract_image_spec(image_spec)

        authorize_request(self.module, image_spec[0], image_spec[1])
        self.log.info("queue_flatten: {}".format(image_spec))

        refs = {
            TASK_REF_ACTION: TASK_REF_ACTION_FLATTEN,
            TASK_REF_POOL_NAME: image_spec[0],
            TASK_REF_POOL_NAMESPACE: image_spec[1],
            TASK_REF_IMAGE_NAME: image_spec[2]
        }

        with self.open_ioctx(image_spec) as ioctx:
            try:
                with rbd.Image(ioctx, image_spec[2]) as image:
                    refs[TASK_REF_IMAGE_ID] = image.id()

                    try:
                        parent_image_id = image.parent_id()
                    except rbd.ImageNotFound:
                        parent_image_id = None

            except rbd.ImageNotFound:
                pass

            task = self.find_task(refs)
            if task:
                return 0, task.to_json(), ''

            if TASK_REF_IMAGE_ID not in refs:
                raise rbd.ImageNotFound("Image {} does not exist".format(
                    self.format_image_spec(image_spec)),
                                        errno=errno.ENOENT)
            if not parent_image_id:
                raise rbd.ImageNotFound(
                    "Image {} does not have a parent".format(
                        self.format_image_spec(image_spec)),
                    errno=errno.ENOENT)

            return 0, self.add_task(
                ioctx, "Flattening image {}".format(
                    self.format_image_spec(image_spec)), refs), ""
コード例 #4
0
ファイル: rbd.py プロジェクト: drunkard/ceph
    def _rbd_image_stat_removing(cls, ioctx, pool_name, namespace, image_id):
        rbd_inst = rbd.RBD()
        img = rbd_inst.trash_get(ioctx, image_id)
        img_spec = get_image_spec(pool_name, namespace, image_id)

        if img['source'] == 'REMOVING':
            img['unique_id'] = img_spec
            img['pool_name'] = pool_name
            img['namespace'] = namespace
            img['deletion_time'] = "{}Z".format(img['deletion_time'].isoformat())
            img['deferment_end_time'] = "{}Z".format(img['deferment_end_time'].isoformat())
            return img
        raise rbd.ImageNotFound('No image {} in status `REMOVING` found.'.format(img_spec),
                                errno=errno.ENOENT)