Esempio n. 1
0
    def load(self, dbg, uri):
        log.debug("%s: xcpng.libsbd.meta.MetaDBOpeations.load: uri: %s" %
                  (dbg, uri))

        cluster = ceph_cluster(dbg, get_cluster_name_by_uri(dbg, uri))

        try:
            cluster.connect()
            length = unpack(
                '!I',
                rbd_read(dbg, cluster, get_sr_name_by_uri(dbg, uri),
                         '__meta__', 0, 4))[0]
            data = unpack(
                '!%ss' % length,
                rbd_read(dbg, cluster, get_sr_name_by_uri(dbg, uri),
                         '__meta__', 4, length))[0]
            return data
        except Exception as e:
            log.error(
                "%s: xcpng.librbd.meta.MetaDBOpeations.load: Failed to load MetaDB: uri: %s"
                % (dbg, uri))
            log.error(traceback.format_exc())
            raise Exception(e)
        finally:
            cluster.shutdown()
Esempio n. 2
0
    def destroy(self, dbg, uri):
        log.debug("%s: xcpng.librbd.meta.MetaDBOpeations.destroy: uri: %s" % (dbg, uri))

        cluster = ceph_cluster(dbg, get_cluster_name_by_uri(dbg, uri))

        try:
            cluster.connect()
            rbd_remove(dbg, cluster, get_sr_name_by_uri(dbg, uri), '__meta__')
            rbd_remove(dbg, cluster, get_sr_name_by_uri(dbg, uri), '__lock__')

        except Exception as e:
            log.debug("%s: xcpng.librbd.meta.MetaDBOpeations.destroy: Failed to destroy MetaDB: uri: %s"
                      % (dbg, uri))
            raise Exception(e)
        finally:
            cluster.shutdown()
Esempio n. 3
0
    def lock(self, dbg, uri, timeout=10):
        log.debug("%s: xcpng.libsbd.meta.MetaDBOpeations.lock: uri: %s" % (dbg, uri))

        if self.lh is not None:
            raise Exception("MetaDB has been already locked by another client")

        start_time = time()
        self.lh = [None, None, None]
        self.lh[0] = ceph_cluster(dbg, get_cluster_name_by_uri(dbg, uri))

        try:
            while True:
                try:
                    self.lh[0].connect()
                    self.lh[1], self.lh[2] = rbd_lock(dbg,
                                                      self.lh[0],
                                                      get_sr_name_by_uri(dbg, uri),
                                                      '__lock__')
                    break
                except Exception as e:
                    if time() - start_time >= timeout:
                        log.debug("%s: xcpng.libsbd.meta.MetaDBOpeations.lock: Failed to lock MetaDB: uri: %s" % (dbg, uri))
                        raise Exception(e)
                    pass
        except Exception as e:
            log.debug("%s: xcpng.librbd.meta.MetaDBOpeations.lock: Failed to lock MetaDB: uri: %s"
                      % (dbg, uri))
            self.lh[0].shutdown()
            raise Exception(e)
Esempio n. 4
0
    def create(self, dbg, uri, db, size=8388608):
        log.debug("%s: xcpng.librbd.meta.MetaDBOpeations.create: uri: %s" % (dbg, uri))

        cluster = ceph_cluster(dbg, get_cluster_name_by_uri(dbg, uri))

        try:
            cluster.connect()
            rbd_create(dbg, cluster, get_sr_name_by_uri(dbg, uri), '__meta__', size)  # default size = 8388608 = 8Mb
            rbd_create(dbg, cluster, get_sr_name_by_uri(dbg, uri), '__lock__', 0)
            length = len(db)
            rbd_write(dbg, cluster, get_sr_name_by_uri(dbg, uri), '__meta__', pack("!I%ss" % length, length, db), 0, length+4)
        except Exception as e:
            log.error("%s: xcpng.librbd.meta.MetaDBOpeations.create: Failed to create MetaDB: uri: %s"
                      % (dbg, uri))
            raise Exception(e)
        finally:
            cluster.shutdown()
Esempio n. 5
0
 def get_vdi_list(self, dbg, uri):
     log.debug("%s: xcpng.libzfs.sr.SROperations.get_vdi_list: uri: %s" %
               (dbg, uri))
     zvols = []
     for zvol in zvol_list(dbg, get_sr_name_by_uri(dbg, uri)):
         if zvol.startswith(VDI_PREFIXES[get_vdi_type_by_uri(dbg, uri)]):
             zvols.extend(zvol)
     return zvols
Esempio n. 6
0
    def lock(self, dbg, uri, timeout=10):
        log.debug("%s: xcpng.librbd.meta.MetaDBOpeations.lock: uri: %s timeout: %s" % (dbg, uri, timeout))

        sr_uuid = get_sr_uuid_by_uri(dbg, uri)
        vdi_uuid = get_vdi_uuid_by_uri(dbg, uri)
        pool_name = get_sr_name_by_uri(dbg, uri)

        if vdi_uuid is not None:
            lock_uuid = vdi_uuid
            image_name = get_vdi_name_by_uri(dbg, uri)
        else:
            lock_uuid = sr_uuid
            image_name = '__lock__'

        start_time = time()

        lh = [None, None, None]
        lh[0] = ceph_cluster(dbg, get_cluster_name_by_uri(dbg, uri))

        if is_locked(dbg, lh[0], pool_name, '__lock__'):
            # SR is locked
            raise ImageBusy

        try:
            while True:
                try:
                    if lock_uuid in self.__lhs:
                        raise ImageExists

                    lh[0].connect()
                    lh[1], lh[2] = rbd_lock(dbg,
                                            lh[0],
                                            pool_name,
                                            image_name)
                    self.__lhs[lock_uuid] = lh
                    break
                except Exception as e:
                    if time() - start_time >= timeout:
                        log.error("%s: xcpng.librbd.meta.MetaDBOpeations.lock: Failed to lock: uri: %s" % (dbg, uri))
                        raise Exception(e)
                    sleep(1)
                    pass
        except Exception as e:
            log.error("%s: xcpng.librbd.meta.MetaDBOpeations.lock: Failed to lock: uri: %s"
                      % (dbg, uri))
            log.error(traceback.format_exc())
            lh[0].shutdown()
            raise Exception(e)
Esempio n. 7
0
    def destroy(self, dbg, uri):
        log.debug("%s: xcpng.librbd.sr.SROperations.destroy: uri: %s" %
                  (dbg, uri))

        cluster = ceph_cluster(dbg, get_cluster_name_by_uri(dbg, uri))

        try:
            cluster.connect()
            cluster.delete_pool(get_sr_name_by_uri(dbg, uri))
        except Exception as e:
            log.debug(
                "%s: xcpng.librbd.sr.SROperations.destory: Failed to destroy SR: uri: %s"
                % dbg, uri)
            raise Exception(e)
        finally:
            cluster.shutdown()
Esempio n. 8
0
    def dump(self, dbg, uri, json):
        log.debug("%s: xcpng.libsbd.meta.MetaDBOpeations.dump: uri: %s" %
                  (dbg, uri))

        cluster = ceph_cluster(dbg, get_cluster_name_by_uri(dbg, uri))

        try:
            length = len(json)
            cluster.connect()
            rbd_write(dbg, cluster, get_sr_name_by_uri(dbg, uri), '__meta__',
                      pack("!I%ss" % length, length, json), 0, length + 4)
        except Exception as e:
            log.error(
                "%s: xcpng.librbd.meta.MetaDBOpeations.dump: Failed to dump MetaDB: uri: %s"
                % (dbg, uri))
            log.error(traceback.format_exc())
            raise Exception(e)
        finally:
            cluster.shutdown()
Esempio n. 9
0
    def get_vdi_list(self, dbg, uri):
        log.debug("%s: xcpng.librbd.sr.SROperations.get_vdi_list: uri: %s" %
                  (dbg, uri))

        rbds = []
        cluster = ceph_cluster(dbg, get_cluster_name_by_uri(dbg, uri))

        try:
            cluster.connect()
            for rbd in rbd_list(dbg, cluster, get_sr_name_by_uri(dbg, uri)):
                if rbd.startswith(VDI_PREFIXES[get_vdi_type_by_uri(dbg, uri)]):
                    rbds.append(rbd)
            return rbds
        except Exception as e:
            log.debug(
                "%s: xcpng.librbd.sr.SROperations.get_vdi_list: uri: Failed to get VDIs list: uri: %s"
                % dbg, uri)
            raise Exception(e)
        finally:
            cluster.shutdown()
Esempio n. 10
0
    def destroy(self, dbg, uri):
        log.debug("%s: xcpng.librbd.volume.VolumeOperations.destroy: uri: %s" %
                  (dbg, uri))

        volume_meta = self.MetadataHandler.get_vdi_meta(dbg, uri)
        cluster = ceph_cluster(dbg, get_cluster_name_by_uri(dbg, uri))

        try:
            cluster.connect()
            rbd_remove(
                dbg, cluster, get_sr_name_by_uri(dbg, uri),
                "%s%s" % (VDI_PREFIXES[get_vdi_type_by_uri(
                    dbg, uri)], volume_meta[IMAGE_UUID_TAG]))
        except Exception as e:
            log.debug(
                "%s: xcpng.librbd.volume.VolumeOperations.create: Failed to create volume: uri: %s"
                % dbg, uri)
            raise Exception(e)
        finally:
            cluster.shutdown()
Esempio n. 11
0
    def get_phisical_utilization(self, dbg, uri):
        log.debug(
            "%s: xcpng.librbd.volume.VolumeOperations.get_phisical_utilization: uri: %s"
            % (dbg, uri))

        volume_meta = self.MetadataHandler.get_vdi_meta(dbg, uri)
        cluster = ceph_cluster(dbg, get_cluster_name_by_uri(dbg, uri))

        try:
            cluster.connect()
            return rbd_utilization(
                dbg, cluster, get_sr_name_by_uri(dbg, uri),
                "%s%s" % (VDI_PREFIXES[get_vdi_type_by_uri(
                    dbg, uri)], volume_meta[IMAGE_UUID_TAG]))
        except Exception as e:
            log.debug(
                "%s: xcpng.librbd.volume.VolumeOperations.resize: Failed to create volume: uri: %s new_size: %s"
                % dbg, uri.new_size)
            raise Exception(e)
        finally:
            cluster.shutdown()
Esempio n. 12
0
    def sr_import(self, dbg, uri, configuration):
        log.debug(
            "%s: xcpng.librbd.sr.SROperations.sr_import: uri: %s configuration %s"
            % (dbg, uri, configuration))

        cluster = ceph_cluster(dbg, get_cluster_name_by_uri(dbg, uri))
        pool_name = get_sr_name_by_uri(dbg, uri)

        try:
            cluster.connect()
            if not cluster.pool_exists(pool_name):
                raise Exception("CEPH pool %s doesn\'t exist" % pool_name)
        except Exception as e:
            log.debug(
                "%s: xcpng.librbd.sr.SROperations.get_vdi_list: uri: Failed to destroy SR: uri: %s"
                % dbg, uri)
            raise Exception(e)
        finally:
            cluster.shutdown()

        mkdir_p("%s/%s" % (SR_PATH_PREFIX, get_sr_uuid_by_uri(dbg, uri)))
Esempio n. 13
0
    def create(self, dbg, uri, configuration):
        log.debug(
            "%s: xcpng.librbd.sr.SROperations.create: uri: %s configuration %s"
            % (dbg, uri, configuration))

        if CEPH_CLUSTER_TAG not in configuration:
            raise Exception(
                'Failed to connect to CEPH cluster. Parameter \'cluster\' is not specified'
            )

        cluster = ceph_cluster(dbg, configuration[CEPH_CLUSTER_TAG])

        try:
            cluster.connect()
            cluster.create_pool(get_sr_name_by_uri(dbg, uri))
        except Exception as e:
            log.debug(
                "%s: xcpng.librbd.sr.SROperations.create: uri: Failed to create SR: uri: %s"
                % dbg, uri)
            raise Exception(e)
        finally:
            cluster.shutdown()
Esempio n. 14
0
 def sr_import(self, dbg, uri, configuration):
     log.debug(
         "%s: xcpng.libzfs.sr.SROperations.sr_import: uri: %s configuration %s"
         % (dbg, uri, configuration))
     pool_import(dbg, get_sr_name_by_uri(dbg, uri),
                 configuration['mountpoint'])
Esempio n. 15
0
 def gen_vol_uri(self, dbg, uri):
     volume_meta = self.MetadataHandler.get_vdi_meta(dbg, uri)
     return "rbd:%s/%s%s:conf=/etc/ceph/%s.conf" % (
         get_sr_name_by_uri(dbg, uri), VDI_PREFIXES[get_vdi_type_by_uri(
             dbg, uri)], volume_meta[IMAGE_UUID_TAG],
         get_cluster_name_by_uri(dbg, uri))
Esempio n. 16
0
 def create(self, dbg, uri, configuration):
     log.debug(
         "%s: xcpng.libzfs.sr.SROperations.create: uri: %s configuration %s"
         % (dbg, uri, configuration))
     pool_create(dbg, get_sr_name_by_uri(dbg, uri), configuration['vdevs'],
                 configuration['mountpoint'])
Esempio n. 17
0
 def destroy(self, dbg, uri):
     log.debug("%s: xcpng.libzfs.sr.SROperations.destroy: uri: %s" %
               (dbg, uri))
     pool_destroy(dbg, get_sr_name_by_uri(dbg, uri))
Esempio n. 18
0
 def get_size(self, dbg, uri):
     log.debug("%s: xcpng.libzfs.sr.SROperations.get_size: uri: %s" %
               (dbg, uri))
     return int(pool_get(dbg, get_sr_name_by_uri(dbg, uri), 'size'))
Esempio n. 19
0
 def sr_export(self, dbg, uri):
     log.debug("%s: xcpng.libzfs.sr.SROperations.sr_export: uri: %s" %
               (dbg, uri))
     pool_export(dbg, get_sr_name_by_uri(dbg, uri))