示例#1
0
    def stat(cls, dbg, sr, key):
        log.debug("%s: librbd.Volume.stat: SR: %s Key: %s"
                  % (dbg, sr, key))

        ceph_cluster = ceph_utils.connect(dbg, sr)

        uri = "%s/%s" % (sr, key)
        image_name = "%s%s/%s%s" % (utils.RBDPOOL_PREFIX,
                                    utils.get_sr_uuid_by_uri(dbg, sr),
                                    utils.VDI_PREFIXES[utils.get_vdi_type_by_uri(dbg, uri)],
                                    key)

        try:
            image_meta = meta.RBDMetadataHandler.load(dbg, uri)
            image_meta[meta.PHYSICAL_UTILISATION_TAG] = rbd_utils.getPhysicalUtilisation(dbg,
                                                                                         ceph_cluster,
                                                                                         image_name)
            #meta.RBDMetadataHandler.update(dbg, uri, image_meta)
            log.debug("%s: librbd.Volume.stat: SR: %s Key: %s Metadata: %s"
                      % (dbg, sr, key, image_meta))
            return cls._stat(dbg, sr, key, image_meta)
        except Exception:
            raise Volume_does_not_exist(key)
        finally:
            ceph_utils.disconnect(dbg, ceph_cluster)
示例#2
0
    def _resize(cls, dbg, sr, key, new_size, image_meta):
        log.debug("%s: librbd.QCOW2Volume._resize: SR: %s Key: %s New_size: %s"
                  % (dbg, sr, key, new_size))

        # TODO: Implement overhead calculation for QCOW2 format
        new_size = utils.validate_and_round_vhd_size(new_size)
        new_rbd_size = utils.fullSizeVHD(new_size)

        ceph_cluster = ceph_utils.connect(dbg, sr)

        uri = "%s/%s" % (sr, key)
        image_name = "%s%s/%s%s" % (utils.RBDPOOL_PREFIX,
                                    utils.get_sr_uuid_by_uri(dbg, sr),
                                    utils.VDI_PREFIXES[utils.get_vdi_type_by_uri(dbg, uri)],
                                    key)

        try:
            rbd_utils.resize(dbg, ceph_cluster, image_name, new_rbd_size)
        except Exception:
            raise Volume_does_not_exist(key)
        finally:
            ceph_utils.disconnect(dbg, ceph_cluster)

        #nbd_device = call(dbg, ["/usr/bin/rbd-nbd",
        #                        "map",
        #                        image_name]).rstrip('\n')

        call(dbg, ["/usr/lib64/qemu-dp/bin/qemu-img",
                   "resize",
                   "rbd:%s" % image_name,
                   str(new_size)])
示例#3
0
    def attach(self, dbg, configuration):
        log.debug("%s: SR.attach: configuration: %s" % (dbg, configuration))

        uri = "rbd+%s+%s://%s/%s" % (
            configuration['image-format'], configuration['datapath'],
            configuration['cluster'], configuration['sr_uuid'])

        ceph_cluster = ceph_utils.connect(dbg, uri)

        #sr_uuid=utils.get_sr_uuid_by_uri(dbg,uri)

        log.debug("%s: SR.attach: sr_uuid: %s uri: %s" %
                  (dbg, configuration['sr_uuid'], uri))

        if not ceph_cluster.pool_exists(utils.get_pool_name_by_uri(dbg, uri)):
            raise Sr_not_attached(configuration['sr_uuid'])

        # Create pool metadata image if it doesn't exist
        log.debug("%s: SR.attach: name: %s/%s" %
                  (dbg, utils.get_pool_name_by_uri(
                      dbg, uri), utils.SR_METADATA_IMAGE_NAME))
        if not rbd_utils.if_image_exist(
                dbg, ceph_cluster, '%s/%s' % (utils.get_pool_name_by_uri(
                    dbg, uri), utils.SR_METADATA_IMAGE_NAME)):
            rbd_utils.create(
                dbg, ceph_cluster, '%s/%s' % (utils.get_pool_name_by_uri(
                    dbg, uri), utils.SR_METADATA_IMAGE_NAME), 0)

        ceph_utils.disconnect(dbg, ceph_cluster)

        return uri
示例#4
0
    def _create(cls, dbg, sr, name, description, size, sharable, image_meta):
        log.debug("%s: librbd.RAWVolume.create: SR: %s Name: %s Description: %s Size: %s"
                  % (dbg, sr, name, description, size))

        image_meta[meta.TYPE_TAG] = utils.get_vdi_type_by_uri(dbg, image_meta[meta.URI_TAG][0])

        ceph_cluster = ceph_utils.connect(dbg, sr)

        image_name = "%s%s/%s%s" % (utils.RBDPOOL_PREFIX,
                                    utils.get_sr_uuid_by_uri(dbg, sr),
                                    utils.VDI_PREFIXES[image_meta[meta.TYPE_TAG]],
                                    image_meta[meta.UUID_TAG])

        try:
            rbd_utils.create(dbg, ceph_cluster, image_name, image_meta[meta.VIRTUAL_SIZE_TAG])
            meta.RBDMetadataHandler.update(dbg, image_meta[meta.URI_TAG][0], image_meta)
        except Exception:
            try:
                rbd_utils.remove(dbg, ceph_cluster, image_name)
            except Exception:
                pass
            finally:
                raise Volume_does_not_exist(image_meta[meta.UUID_TAG])
        finally:
            ceph_utils.disconnect(dbg, ceph_cluster)

        return image_meta
示例#5
0
文件: meta.py 项目: kenneth104/RBDSR
    def _load(dbg, uri, use_image_prefix=True):
        log.debug("%s: meta.RBDMetadataHandler._load: uri: %s" % (dbg, uri))

        ceph_cluster = ceph_utils.connect(dbg, uri)

        if use_image_prefix:
            image_name = "%s%s/%s%s" % (
                utils.RBDPOOL_PREFIX, utils.get_sr_uuid_by_uri(
                    dbg, uri), utils.VDI_PREFIXES[utils.get_vdi_type_by_uri(
                        dbg, uri)], utils.get_vdi_uuid_by_uri(dbg, uri))
        else:
            image_name = "%s%s/%s" % (utils.RBDPOOL_PREFIX,
                                      utils.get_sr_uuid_by_uri(dbg, uri),
                                      utils.get_vdi_uuid_by_uri(dbg, uri))

        image_meta = {}

        try:
            image_meta_list = rbd_utils.retrieveImageMetadata(
                dbg, ceph_cluster, image_name)

            for tag, value in image_meta_list:
                image_meta[tag] = TAG_TYPES[tag](value)

            log.debug(
                "%s: meta.RBDMetadataHandler._load: Image: %s Metadata: %s " %
                (dbg, image_name, image_meta))
        except Exception:
            raise Volume_does_not_exist(uri)
        finally:
            ceph_utils.disconnect(dbg, ceph_cluster)

        return image_meta
示例#6
0
    def detach(self, dbg, uri):
        log.debug("%s: SR.detach: uri: %s" % (dbg, uri))

        ceph_cluster = ceph_utils.connect(dbg, uri)

        sr_uuid = utils.get_sr_uuid_by_uri(dbg, uri)

        log.debug("%s: SR.detach: sr_uuid: %s" % (dbg, sr_uuid))

        if not ceph_cluster.pool_exists(utils.get_pool_name_by_uri(dbg, uri)):
            raise Sr_not_attached(sr_uuid)

        ceph_utils.disconnect(dbg, ceph_cluster)
示例#7
0
    def ls(self, dbg, uri):
        log.debug("%s: SR.ls: uri: %s" % (dbg, uri))
        results = []
        key = ''

        ceph_cluster = ceph_utils.connect(dbg, uri)

        try:
            rbds = rbd_utils.list(dbg, ceph_cluster,
                                  utils.get_pool_name_by_uri(dbg, uri))
            for rbd in rbds:
                if rbd.startswith(utils.VDI_PREFIXES[utils.get_vdi_type_by_uri(
                        dbg, uri)]):
                    log.debug("%s: SR.ls: SR: %s rbd: %s" % (dbg, uri, rbd))

                    key = utils.get_vdi_uuid_by_name(dbg, rbd)

                    log.debug("%s: SR.ls: SR: %s Image: %s" % (dbg, uri, key))

                    image_meta = meta.RBDMetadataHandler.load(
                        dbg, "%s/%s" % (uri, key))
                    #log.debug("%s: SR.ls: SR: %s image: %s Metadata: %s" % (dbg, uri, rbd, image_meta))

                    results.append({
                        meta.UUID_TAG:
                        image_meta[meta.UUID_TAG],
                        meta.KEY_TAG:
                        image_meta[meta.KEY_TAG],
                        meta.NAME_TAG:
                        image_meta[meta.NAME_TAG],
                        meta.DESCRIPTION_TAG:
                        image_meta[meta.DESCRIPTION_TAG],
                        meta.READ_WRITE_TAG:
                        image_meta[meta.READ_WRITE_TAG],
                        meta.VIRTUAL_SIZE_TAG:
                        image_meta[meta.VIRTUAL_SIZE_TAG],
                        meta.PHYSICAL_UTILISATION_TAG:
                        image_meta[meta.PHYSICAL_UTILISATION_TAG],
                        meta.URI_TAG:
                        image_meta[meta.URI_TAG],
                        meta.CUSTOM_KEYS_TAG:
                        image_meta[meta.CUSTOM_KEYS_TAG],
                        meta.SHARABLE_TAG:
                        image_meta[meta.SHARABLE_TAG]
                    })
                #log.debug("%s: SR.ls: Result: %s" % (dbg, results))
            return results
        except Exception:
            raise Volume_does_not_exist(key)
        finally:
            ceph_utils.disconnect(dbg, ceph_cluster)
示例#8
0
    def destroy(self, dbg, uri):
        log.debug("%s: SR.destroy: uri: %s" % (dbg, uri))

        ceph_cluster = ceph_utils.connect(dbg, uri)

        ceph_pool_name = utils.get_pool_name_by_uri(dbg, uri)

        if not ceph_cluster.pool_exists(ceph_pool_name):
            raise Exception("Ceph pool %s does not exist ")

        try:
            ceph_cluster.delete_pool(ceph_pool_name)
        except Exception:
            raise Exception("Failed to delete ceph pool %s" % ceph_pool_name)
        finally:
            ceph_utils.disconnect(dbg, ceph_cluster)
示例#9
0
    def _resize(cls, dbg, sr, key, new_size, image_meta):
        log.debug("%s: librbd.RAWVolume._resize: SR: %s Key: %s New_size: %s"
                  % (dbg, sr, key, new_size))

        ceph_cluster = ceph_utils.connect(dbg, sr)

        uri = "%s/%s" % (sr, key)
        image_name = "%s%s/%s%s" % (utils.RBDPOOL_PREFIX,
                                    utils.get_sr_uuid_by_uri(dbg, sr),
                                    utils.VDI_PREFIXES[utils.get_vdi_type_by_uri(dbg, uri)],
                                    key)

        try:
            rbd_utils.resize(dbg, ceph_cluster, image_name, new_size)
        except Exception:
            raise Volume_does_not_exist(key)
        finally:
            ceph_utils.disconnect(dbg, ceph_cluster)
示例#10
0
    def set_name(self, dbg, uri, new_name):
        log.debug("%s: SR.set_name: SR: %s New_name: %s" %
                  (dbg, uri, new_name))

        ceph_cluster = ceph_utils.connect(dbg, uri)

        pool_meta = {
            meta.NAME_TAG: new_name,
        }

        try:
            meta.RBDMetadataHandler.update(
                dbg, '%s/%s' % (uri, utils.SR_METADATA_IMAGE_NAME), pool_meta,
                False)
        except Exception:
            raise Volume_does_not_exist(uri)
        finally:
            ceph_utils.disconnect(dbg, ceph_cluster)
示例#11
0
    def stat(self, dbg, uri):
        log.debug("%s: SR.stat: uri: %s" % (dbg, uri))

        ceph_cluster = ceph_utils.connect(dbg, uri)

        ceph_cluster_stats = ceph_cluster.get_cluster_stats()

        pool_meta = meta.RBDMetadataHandler.load(
            dbg, '%s/%s' % (uri, utils.SR_METADATA_IMAGE_NAME), False)

        log.debug("%s: SR.stat: pool_meta: %s" % (dbg, pool_meta))

        # Get the sizes
        tsize = ceph_cluster_stats['kb'] * 1024
        fsize = ceph_cluster_stats['kb_avail'] * 1024
        log.debug("%s: SR.stat total_space = %Ld free_space = %Ld" %
                  (dbg, tsize, fsize))

        overprovision = 0

        ceph_utils.disconnect(dbg, ceph_cluster)

        return {
            'sr':
            uri,
            'uuid':
            utils.get_sr_uuid_by_uri(dbg, uri),
            'name':
            pool_meta[meta.NAME_TAG]
            if meta.NAME_TAG in pool_meta else '<CEPHBASED SR>',
            'description':
            pool_meta[meta.DESCRIPTION_TAG]
            if meta.DESCRIPTION_TAG in pool_meta else '<CEPHBASED SR>',
            'total_space':
            tsize,
            'free_space':
            fsize,
            'overprovision':
            overprovision,
            'datasources': [],
            'clustered':
            False,
            'health': ['Healthy', '']
        }
示例#12
0
    def destroy(cls, dbg, sr, key):
        log.debug("%s: Volume.destroy: SR: %s Key: %s"
                  % (dbg, sr, key))

        ceph_cluster = ceph_utils.connect(dbg, sr)

        uri = "%s/%s" % (sr, key)
        image_name = "%s%s/%s%s" % (utils.RBDPOOL_PREFIX,
                                    utils.get_sr_uuid_by_uri(dbg, sr),
                                    utils.VDI_PREFIXES[utils.get_vdi_type_by_uri(dbg, uri)],
                                    key)

        try:
            rbd_utils.remove(dbg, ceph_cluster, image_name)
            cls._destroy(dbg, sr, key)
        except Exception:
           raise Volume_does_not_exist(key)
        finally:
            ceph_utils.disconnect(dbg, ceph_cluster)
示例#13
0
文件: meta.py 项目: kenneth104/RBDSR
    def _update(dbg, uri, image_meta, use_image_prefix=True):
        log.debug(
            "%s: meta.RBDMetadataHandler._update_meta: uri: %s image_meta: %s"
            % (dbg, uri, image_meta))

        ceph_cluster = ceph_utils.connect(dbg, uri)

        if use_image_prefix:
            image_name = "%s%s/%s%s" % (
                utils.RBDPOOL_PREFIX, utils.get_sr_uuid_by_uri(
                    dbg, uri), utils.VDI_PREFIXES[utils.get_vdi_type_by_uri(
                        dbg, uri)], utils.get_vdi_uuid_by_uri(dbg, uri))
        else:
            image_name = "%s%s/%s" % (utils.RBDPOOL_PREFIX,
                                      utils.get_sr_uuid_by_uri(dbg, uri),
                                      utils.get_vdi_uuid_by_uri(dbg, uri))

        try:
            rbd_utils.updateImageMetadata(dbg, ceph_cluster, image_name,
                                          image_meta)
        except Exception:
            raise Volume_does_not_exist(uri)
        finally:
            ceph_utils.disconnect(dbg, ceph_cluster)
示例#14
0
    def _create(cls, dbg, sr, name, description, size, sharable, image_meta):
        log.debug("%s: librbd.QCOW2Volume._create: SR: %s Name: %s Description: %s Size: %s"
                  % (dbg, sr, name, description, size))

        image_meta[meta.TYPE_TAG] = utils.get_vdi_type_by_uri(dbg, image_meta[meta.URI_TAG][0])

        ceph_cluster = ceph_utils.connect(dbg, sr)

        image_name = "%s%s/%s%s" % (utils.RBDPOOL_PREFIX,
                                    utils.get_sr_uuid_by_uri(dbg, sr),
                                    utils.VDI_PREFIXES[image_meta[meta.TYPE_TAG]],
                                    image_meta[meta.UUID_TAG])

        # TODO: Implement overhead calculation for QCOW2 format
        size = utils.validate_and_round_vhd_size(size)
        rbd_size = utils.fullSizeVHD(size)

        try:
            rbd_utils.create(dbg, ceph_cluster, image_name, rbd_size)
            meta.RBDMetadataHandler.update(dbg, image_meta[meta.URI_TAG][0], image_meta)
        except Exception:
            try:
                rbd_utils.remove(dbg, ceph_cluster, image_name)
            except Exception:
                pass
            finally:
                raise Volume_does_not_exist(image_meta[meta.UUID_TAG])
        finally:
            ceph_utils.disconnect(dbg, ceph_cluster)

        #Datapath.attach(dbg, image_meta[meta.URI_TAG][0], 0)
        #Datapath.activate(dbg, image_meta[meta.URI_TAG][0], 0, 'raw')

        #nbd_device=call(dbg, ["/opt/xensource/libexec/nbd_client_manager.py",
        #                      "connect",
        #                      "--path",
        #                      utils.VAR_RUN_PREFIX + "/qemu-nbd.{}".format(image_meta[meta.UUID_TAG]),
        #                      "--exportname",
        #                      "qemu_node"])

        nbd_device = call(dbg, ["/usr/bin/rbd-nbd",
                                "map",
                                image_name]).rstrip('\n')

        call(dbg, ["/usr/lib64/qemu-dp/bin/qemu-img",
                   "create",
                   "-f", image_meta[meta.TYPE_TAG],
                   nbd_device,
                   str(size)])

        call(dbg, ["/usr/bin/rbd-nbd",
                   "unmap",
                   nbd_device])

        #call(dbg, ["/opt/xensource/libexec/nbd_client_manager.py",
        #           "disconnect",
        #               "--device",
        #           nbd_device])

        #Datapath.deactivate(dbg, image_meta[meta.URI_TAG][0], 0)
        #Datapath.detach(dbg, image_meta[meta.URI_TAG][0], 0)

        return image_meta
示例#15
0
    def _clone(cls, dbg, sr, key, mode, base_meta):
        log.debug("%s: librbd.QCOW2Volume.clone: SR: %s Key: %s Mode: %s"
                  % (dbg, sr, key, mode))

        # TODO: Implement overhead calculation for QCOW2 format
        size = utils.validate_and_round_vhd_size(base_meta[meta.VIRTUAL_SIZE_TAG])
        rbd_size = utils.fullSizeVHD(size)

        ceph_cluster = ceph_utils.connect(dbg, sr)

        clone_uuid = str(uuid.uuid4())
        clone_name = "%s%s/%s%s" % (utils.RBDPOOL_PREFIX,
                                    utils.get_sr_uuid_by_uri(dbg, sr),
                                    utils.VDI_PREFIXES[utils.get_vdi_type_by_uri(dbg, sr)],
                                    clone_uuid)

        try:
            if base_meta[meta.KEY_TAG] == key:
                base_name = "%s%s/%s%s" % (utils.RBDPOOL_PREFIX,
                                           utils.get_sr_uuid_by_uri(dbg, sr),
                                           utils.VDI_PREFIXES[utils.get_vdi_type_by_uri(dbg, sr)],
                                           key)

                new_base_uuid = str(uuid.uuid4())
                new_base_name = "%s%s/%s%s" % (utils.RBDPOOL_PREFIX,
                                               utils.get_sr_uuid_by_uri(dbg, sr),
                                               utils.VDI_PREFIXES[utils.get_vdi_type_by_uri(dbg, sr)],
                                               new_base_uuid)

                rbd_utils.rename(dbg, ceph_cluster, base_name, new_base_name)
                rbd_utils.create(dbg, ceph_cluster, base_name, rbd_size)
                rbd_utils.create(dbg, ceph_cluster, clone_name, rbd_size)

                base_nbd_device = call(dbg, ["/usr/bin/rbd-nbd",
                                             "map",
                                             base_name]).rstrip('\n')

                clone_nbd_device = call(dbg, ["/usr/bin/rbd-nbd",
                                              "map",
                                              clone_name]).rstrip('\n')

                call(dbg, ["/usr/lib64/qemu-dp/bin/qemu-img",
                           "create",
                           "-f", base_meta[meta.TYPE_TAG],
                           "-b", "rbd:%s" % new_base_name,
                           base_nbd_device])

                call(dbg, ["/usr/lib64/qemu-dp/bin/qemu-img",
                           "create",
                           "-f", base_meta[meta.TYPE_TAG],
                           "-b", "rbd:%s" % new_base_name,
                           clone_nbd_device])

                call(dbg, ["/usr/bin/rbd-nbd",
                           "unmap",
                           clone_nbd_device])

                call(dbg, ["/usr/bin/rbd-nbd",
                           "unmap",
                           base_nbd_device])

                new_base_meta = copy.deepcopy(base_meta)
                new_base_meta[meta.NAME_TAG] = "(base) %s" % new_base_meta[meta.NAME_TAG]
                new_base_meta[meta.KEY_TAG] = new_base_uuid
                new_base_meta[meta.UUID_TAG] = new_base_uuid
                new_base_meta[meta.URI_TAG] = ["%s/%s" % (sr, new_base_uuid)]
                new_base_meta[meta.READ_WRITE_TAG] = False

                if meta.ACTIVE_ON_TAG in new_base_meta:
                    Datapath.snapshot(dbg,new_base_meta[meta.URI_TAG][0], base_meta[meta.URI_TAG][0], 0)

                if meta.ACTIVE_ON_TAG in new_base_meta:
                    new_base_meta[meta.ACTIVE_ON_TAG] = None
                    new_base_meta[meta.QEMU_PID_TAG] = None
                    new_base_meta[meta.QEMU_NBD_SOCK_TAG] = None
                    new_base_meta[meta.QEMU_QMP_SOCK_TAG] = None
                    new_base_meta[meta.QEMU_QMP_LOG_TAG] = None

                meta.RBDMetadataHandler.update(dbg, new_base_meta[meta.URI_TAG][0], new_base_meta)
                meta.RBDMetadataHandler.update(dbg, base_meta[meta.URI_TAG][0], base_meta)

            else:
                base_name = "%s%s/%s%s" % (utils.RBDPOOL_PREFIX,
                                           utils.get_sr_uuid_by_uri(dbg, sr),
                                           utils.VDI_PREFIXES[utils.get_vdi_type_by_uri(dbg, sr)],
                                           base_meta[meta.UUID_TAG])

                rbd_utils.create(dbg, ceph_cluster, clone_name, rbd_size)

                clone_nbd_device = call(dbg, ["/usr/bin/rbd-nbd",
                                              "map",
                                              clone_name]).rstrip('\n')

                call(dbg, ["/usr/lib64/qemu-dp/bin/qemu-img",
                           "create",
                           "-f", base_meta[meta.TYPE_TAG],
                           "-b", "rbd:%s" % base_name,
                           clone_nbd_device])

                call(dbg, ["/usr/bin/rbd-nbd",
                           "unmap",
                           clone_nbd_device])

            clone_meta = copy.deepcopy(base_meta)
            clone_meta[meta.KEY_TAG] = clone_uuid
            clone_meta[meta.UUID_TAG] = clone_uuid
            clone_meta[meta.URI_TAG] = ["%s/%s" % (sr, clone_uuid)]

            if meta.ACTIVE_ON_TAG in clone_meta:
                clone_meta.pop(meta.ACTIVE_ON_TAG, None)
                clone_meta.pop(meta.QEMU_PID_TAG, None)
                clone_meta.pop(meta.QEMU_NBD_SOCK_TAG, None)
                clone_meta.pop(meta.QEMU_QMP_SOCK_TAG, None)
                clone_meta.pop(meta.QEMU_QMP_LOG_TAG, None)

            if mode is 'snapshot':
                clone_meta[meta.READ_WRITE_TAG] = False
                clone_meta[meta.SNAPSHOT_OF_TAG] = new_base_meta[meta.UUID_TAG]
            elif mode is 'clone':
                clone_meta[meta.READ_WRITE_TAG] = True

            meta.RBDMetadataHandler.update(dbg, clone_meta[meta.URI_TAG][0], clone_meta)

            return clone_meta
        except Exception:
            raise Volume_does_not_exist(key)
        finally:
            ceph_utils.disconnect(dbg, ceph_cluster)
示例#16
0
    def probe(self, dbg, configuration):
        log.debug("{}: SR.probe: configuration={}".format(dbg, configuration))

        uri = "rbd+%s://" % configuration[
            meta.
            IMAGE_FORMAT_TAG] if meta.IMAGE_FORMAT_TAG in configuration else 'rbd://'
        uri = "%s%s" % (uri, configuration[meta.CEPH_CLUSTER_TAG])
        _uri_ = uri
        uri = "%s/%s" % (uri, configuration[meta.SR_UUID_TAG]
                         ) if meta.SR_UUID_TAG in configuration else uri

        log.debug("{}: SR.probe: uri to probe: {}".format(dbg, uri))

        result = []

        ceph_cluster = ceph_utils.connect(dbg, uri)

        ceph_cluster_name = utils.get_cluster_name_by_uri(dbg, uri)
        ceph_pools = ceph_cluster.list_pools()
        log.debug("%s: SR.probe: Available Pools" % dbg)
        log.debug(
            "%s: SR.probe: ---------------------------------------------------"
            % dbg)

        for ceph_pool in ceph_pools:
            log.debug("%s: SR.probe: %s" % (dbg, ceph_pool))

            pool_meta = {}
            sr_uuid = utils.get_sr_uuid_by_name(dbg, ceph_pool)

            if ceph_pool.startswith(utils.RBDPOOL_PREFIX):
                if rbd_utils.if_image_exist(
                        dbg, ceph_cluster,
                        '%s/%s' % (ceph_pool, utils.SR_METADATA_IMAGE_NAME)):

                    pool_meta = meta.RBDMetadataHandler.load(
                        dbg, "%s/%s/%s" %
                        (_uri_, utils.get_sr_uuid_by_name(
                            dbg, ceph_pool), utils.SR_METADATA_IMAGE_NAME),
                        False)

                if (meta.IMAGE_FORMAT_TAG in configuration and (
                    (meta.CONFIGURATION_TAG in pool_meta and
                     meta.IMAGE_FORMAT_TAG in pool_meta[meta.CONFIGURATION_TAG]
                     and configuration[meta.IMAGE_FORMAT_TAG] !=
                     pool_meta[meta.CONFIGURATION_TAG][meta.IMAGE_FORMAT_TAG])
                        or (meta.CONFIGURATION_TAG in pool_meta
                            and meta.IMAGE_FORMAT_TAG
                            not in pool_meta[meta.CONFIGURATION_TAG])
                        or meta.CONFIGURATION_TAG not in pool_meta)):

                    ceph_pool = None

                if (meta.SR_UUID_TAG in configuration and
                    ((meta.CONFIGURATION_TAG in pool_meta
                      and meta.SR_UUID_TAG in pool_meta[meta.CONFIGURATION_TAG]
                      and configuration[meta.SR_UUID_TAG] !=
                      pool_meta[meta.CONFIGURATION_TAG][meta.SR_UUID_TAG]) or
                     (meta.CONFIGURATION_TAG in pool_meta and meta.SR_UUID_TAG
                      not in pool_meta[meta.CONFIGURATION_TAG]
                      and configuration[meta.SR_UUID_TAG] != sr_uuid) or
                     (meta.CONFIGURATION_TAG not in pool_meta
                      and configuration[meta.SR_UUID_TAG] != sr_uuid))):

                    ceph_pool = None

                if ceph_pool is not None:

                    _result_ = {}
                    _result_['complete'] = True
                    _result_['configuration'] = {}
                    _result_['configuration'] = copy.deepcopy(configuration)
                    _result_['extra_info'] = {}

                    sr = {}
                    sr['sr'] = "rbd://%s/%s" % (ceph_cluster_name,
                                                utils.get_sr_uuid_by_name(
                                                    dbg, ceph_pool))
                    sr['name'] = pool_meta[
                        meta.
                        NAME_TAG] if meta.NAME_TAG in pool_meta else '<CEPHBASED SR>'
                    sr['description'] = pool_meta[
                        meta.
                        DESCRIPTION_TAG] if meta.DESCRIPTION_TAG in pool_meta else '<CEPHBASED SR>'

                    ceph_cluster_stats = ceph_cluster.get_cluster_stats()

                    sr['free_space'] = ceph_cluster_stats['kb_avail'] * 1024
                    sr['total_space'] = ceph_cluster_stats['kb'] * 1024
                    sr['datasources'] = []
                    sr['clustered'] = False
                    sr['health'] = ['Healthy', '']

                    _result_['sr'] = sr
                    _result_['configuration'][
                        'sr_uuid'] = utils.get_sr_uuid_by_name(dbg, ceph_pool)

                    result.append(_result_)

        ceph_utils.disconnect(dbg, ceph_cluster)

        return result
示例#17
0
    def _clone(cls, dbg, sr, key, mode, base_meta):
        log.debug("%s: librbd.RAWVolume.clone: SR: %s Key: %s Mode: %s"
                  % (dbg, sr, key, mode))

        ceph_cluster = ceph_utils.connect(dbg, sr)

        clone_uuid = str(uuid.uuid4())
        clone_name = "%s%s/%s%s" % (utils.RBDPOOL_PREFIX,
                                    utils.get_sr_uuid_by_uri(dbg, sr),
                                    utils.VDI_PREFIXES[utils.get_vdi_type_by_uri(dbg, sr)],
                                    clone_uuid)

        try:
            if base_meta[meta.KEY_TAG] == key:
                base_name = "%s%s/%s%s" % (utils.RBDPOOL_PREFIX,
                                           utils.get_sr_uuid_by_uri(dbg, sr),
                                           utils.VDI_PREFIXES[utils.get_vdi_type_by_uri(dbg, sr)],
                                           key)

                new_base_uuid = str(uuid.uuid4())
                new_base_name = "%s%s/%s%s" % (utils.RBDPOOL_PREFIX,
                                               utils.get_sr_uuid_by_uri(dbg, sr),
                                               utils.VDI_PREFIXES[utils.get_vdi_type_by_uri(dbg, sr)],
                                               new_base_uuid)

                if meta.ACTIVE_ON_TAG in base_meta:
                    Datapath.suspend(dbg,base_meta[meta.URI_TAG][0], 0)

                rbd_utils.rename(dbg, ceph_cluster, base_name, new_base_name)
                rbd_utils.snapshot(dbg, ceph_cluster, new_base_name, 'base')
                rbd_utils.clone(dbg, ceph_cluster, new_base_name, 'base', base_name)
                rbd_utils.clone(dbg, ceph_cluster, new_base_name, 'base', clone_name)

                if meta.ACTIVE_ON_TAG in base_meta:
                    Datapath.resume(dbg,base_meta[meta.URI_TAG][0], 0)

                new_base_meta = copy.deepcopy(base_meta)
                new_base_meta[meta.NAME_TAG] = "(base) %s" % new_base_meta[meta.NAME_TAG]
                new_base_meta[meta.KEY_TAG] = new_base_uuid
                new_base_meta[meta.UUID_TAG] = new_base_uuid
                new_base_meta[meta.URI_TAG] = ["%s/%s" % (sr, new_base_uuid)]
                new_base_meta[meta.READ_WRITE_TAG] = False

                if meta.ACTIVE_ON_TAG in new_base_meta:
                    new_base_meta[meta.ACTIVE_ON_TAG] = None
                    new_base_meta[meta.QEMU_PID_TAG] = None
                    new_base_meta[meta.QEMU_NBD_SOCK_TAG] = None
                    new_base_meta[meta.QEMU_QMP_SOCK_TAG] = None
                    new_base_meta[meta.QEMU_QMP_LOG_TAG] = None

                meta.RBDMetadataHandler.update(dbg, new_base_meta[meta.URI_TAG][0], new_base_meta)
                meta.RBDMetadataHandler.update(dbg, base_meta[meta.URI_TAG][0], base_meta)

            else:
                base_name = "%s%s/%s%s" % (utils.RBDPOOL_PREFIX,
                                           utils.get_sr_uuid_by_uri(dbg, sr),
                                           utils.VDI_PREFIXES[utils.get_vdi_type_by_uri(dbg, sr)],
                                           base_meta[meta.UUID_TAG])
                rbd_utils.clone(dbg, ceph_cluster, base_name, 'base', clone_name)

            clone_meta = copy.deepcopy(base_meta)
            clone_meta[meta.KEY_TAG] = clone_uuid
            clone_meta[meta.UUID_TAG] = clone_uuid
            clone_meta[meta.URI_TAG] = ["%s/%s" % (sr, clone_uuid)]

            if meta.ACTIVE_ON_TAG in clone_meta:
                clone_meta[meta.ACTIVE_ON_TAG] = None
                clone_meta[meta.QEMU_PID_TAG] = None
                clone_meta[meta.QEMU_NBD_SOCK_TAG] = None
                clone_meta[meta.QEMU_QMP_SOCK_TAG] = None
                clone_meta[meta.QEMU_QMP_LOG_TAG] = None

            if mode is 'snapshot':
                clone_meta[meta.READ_WRITE_TAG] = False
                clone_meta[meta.SNAPSHOT_OF_TAG] = new_base_meta[meta.UUID_TAG]
            elif mode is 'clone':
                clone_meta[meta.READ_WRITE_TAG] = True

            meta.RBDMetadataHandler.update(dbg, clone_meta[meta.URI_TAG][0], clone_meta)
            return clone_meta
        except Exception:
            raise Volume_does_not_exist(key)
        finally:
            ceph_utils.disconnect(dbg, ceph_cluster)
示例#18
0
    def create(self, dbg, sr_uuid, configuration, name, description):
        log.debug(
            "%s: SR.create: sr_uuid %s configuration %s name %s description: %s"
            % (dbg, sr_uuid, configuration, name, description))

        uri = "rbd+%s+%s://%s/%s" % (configuration['image-format'],
                                     configuration['datapath'],
                                     configuration['cluster'], sr_uuid)

        ceph_cluster = ceph_utils.connect(dbg, uri)

        ceph_pool_name = utils.get_pool_name_by_uri(dbg, uri)

        if ceph_cluster.pool_exists(ceph_pool_name):
            raise Exception("Pool %s already exists" % ceph_pool_name)

        try:
            ceph_cluster.create_pool(ceph_pool_name)
        except Exception:
            ceph_utils.disconnect(dbg, ceph_cluster)
            log.debug("%s: SR.create: Failed to create SR - sr_uuid: %s" %
                      (dbg, sr_uuid))
            raise Exception("Failed to create pool %s" % ceph_pool_name)

        try:
            rbd_utils.create(
                dbg, ceph_cluster, '%s/%s' % (utils.get_pool_name_by_uri(
                    dbg, uri), utils.SR_METADATA_IMAGE_NAME), 0)
        except Exception:
            try:
                ceph_cluster.delete_pool(ceph_pool_name)
            except Exception:
                ceph_utils.disconnect(dbg, ceph_cluster)
                raise Exception
            ceph_utils.disconnect(dbg, ceph_cluster)
            log.debug(
                "%s: SR.create: Failed to create SR metadata image - sr_uuid: %s"
                % (dbg, sr_uuid))
            raise Exception("Failed to create pool metadata image %s" %
                            ceph_pool_name)

        configuration['sr_uuid'] = sr_uuid

        if description == '':
            description = ' '

        pool_meta = {
            meta.SR_UUID_TAG: sr_uuid,
            meta.NAME_TAG: name,
            meta.DESCRIPTION_TAG: description,
            meta.CONFIGURATION_TAG: json.dumps(configuration)
        }

        try:
            meta.RBDMetadataHandler.update(
                dbg, '%s/%s' % (uri, utils.SR_METADATA_IMAGE_NAME), pool_meta,
                False)
        except Exception:
            ceph_utils.disconnect(dbg, ceph_cluster)
            raise Exception("Failed to update pool metadata %s" %
                            ceph_pool_name)

        ceph_utils.disconnect(dbg, ceph_cluster)

        return configuration