當前位置: 首頁>>代碼示例>>Python>>正文


Python rados.Rados方法代碼示例

本文整理匯總了Python中rados.Rados方法的典型用法代碼示例。如果您正苦於以下問題:Python rados.Rados方法的具體用法?Python rados.Rados怎麽用?Python rados.Rados使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rados的用法示例。


在下文中一共展示了rados.Rados方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_connection

# 需要導入模塊: import rados [as 別名]
# 或者: from rados import Rados [as 別名]
def get_connection(self, conffile, rados_id):
        client = rados.Rados(conffile=conffile, rados_id=rados_id)

        try:
            client.connect(timeout=self.connect_timeout)
        except (rados.Error, rados.ObjectNotFound) as e:
            if self.backend_group and len(self.conf.enabled_backends) > 1:
                reason = _("Error in store configuration: %s") % e
                LOG.debug(reason)
                raise exceptions.BadStoreConfiguration(
                    store_name=self.backend_group, reason=reason)
            else:
                msg = _LE("Error connecting to ceph cluster.")
                LOG.exception(msg)
                raise exceptions.BackendException()
        try:
            yield client
        finally:
            client.shutdown() 
開發者ID:openstack,項目名稱:glance_store,代碼行數:21,代碼來源:rbd.py

示例2: __init__

# 需要導入模塊: import rados [as 別名]
# 或者: from rados import Rados [as 別名]
def __init__(self, pool, images, backup_dest, conf_file, check_mode=False, compress_mode=False, window_size=7, window_unit='days'):
        '''
        images: list of images to backup
        backup_dest: path where to write the backups
        '''
        super(CephFullBackup, self).__init__()
        if len(set(images)) != len(images):
            raise Exception("Duplicated elements detected in list of images")
        self._pool = pool
        self._images = images
        self._backup_dest = backup_dest
        self._check_mode = check_mode
        self._compress_mode = compress_mode
        # TODO: support also cardinal backup window instead of temporal one, snapshots unit
        self._window_size = window_size
        self._window_unit = window_unit
        # Ceph objects
        cluster = rados.Rados(conffile=conf_file)
        cluster.connect()
        self._ceph_ioctx = cluster.open_ioctx(pool)
        self._ceph_rbd = rbd.RBD()

        # support wildcard for images
        if len(self._images) == 1 and self._images[0] == '*':
            self._images = self._get_images() 
開發者ID:teralytics,項目名稱:ceph-backup,代碼行數:27,代碼來源:ceph_backup.py

示例3: __init__

# 需要導入模塊: import rados [as 別名]
# 或者: from rados import Rados [as 別名]
def __init__(self, _id, **kwargs):
        """
        Initialize settings, connect to Ceph cluster
        """
        self.osd_id = _id
        self.settings = {
            'conf': "/etc/ceph/ceph.conf",
            'filename': '/var/run/ceph/osd.{}-weight'.format(_id),
            'rfilename': '/var/run/ceph/osd.{}-reweight'.format(_id),
            'timeout': 60,
            'keyring': '/etc/ceph/ceph.client.admin.keyring',
            'client': 'client.admin',
            'delay': 6
        }
        self.settings.update(kwargs)
        log.debug("settings for OSDWeight: {}".format(pprint.pformat(self.settings)))
        self.cluster = rados.Rados(conffile=self.settings['conf'],
                                   conf=dict(keyring=self.settings['keyring']),
                                   name=self.settings['client'])
        try:
            self.cluster.connect()
        except Exception as error:
            raise RuntimeError("connection error: {}".format(error)) 
開發者ID:SUSE,項目名稱:DeepSea,代碼行數:25,代碼來源:osd.py

示例4: rbd_from_configuration

# 需要導入模塊: import rados [as 別名]
# 或者: from rados import Rados [as 別名]
def rbd_from_configuration(
    cluster_name, user_id, ceph_conf_path, storage_pool
):
    try:
        cluster = rados.Rados(conffile=ceph_conf_path)
    except TypeError as e:
        # XXX eliot
        raise e

    try:
        cluster.connect()
    except Exception as e:
        # XXX eliot
        raise e

    if not cluster.pool_exists(storage_pool):
        raise Exception("Pool does not exist")  # XXX eliot
    ioctx = cluster.open_ioctx(storage_pool)

    return CephRBDBlockDeviceAPI(cluster, ioctx, storage_pool, check_output) 
開發者ID:ClusterHQ,項目名稱:ceph-flocker-driver,代碼行數:22,代碼來源:ceph_rbd.py

示例5: df

# 需要導入模塊: import rados [as 別名]
# 或者: from rados import Rados [as 別名]
def df(**kwargs):
    """
    Return osd df
    """
    settings = {
        'conf': "/etc/ceph/ceph.conf",
        'keyring': '/etc/ceph/ceph.client.admin.keyring',
        'client': 'client.admin',
    }
    settings.update(kwargs)

    cluster = rados.Rados(conffile=settings['conf'],
                          conf=dict(keyring=settings['keyring']),
                          name=settings['client'])

    cluster.connect()
    cmd = json.dumps({"prefix": "osd df", "format": "json"})
    _, output, _ = cluster.mon_command(cmd, b'', timeout=6)
    osd_df = json.loads(output)
    log.debug(json.dumps(osd_df, indent=4))
    return osd_df 
開發者ID:SUSE,項目名稱:DeepSea,代碼行數:23,代碼來源:osd.py

示例6: _settings

# 需要導入模塊: import rados [as 別名]
# 或者: from rados import Rados [as 別名]
def _settings(**kwargs):
    """
    Initialize settings to use the client.storage name and keyring
    if the keyring is available (Only exists on storage nodes.)

    Otherwise, rely on the default which is client.admin. See
    rados.Rados.
    """
    settings = {}
    storage_keyring = '/etc/ceph/ceph.client.storage.keyring'
    if os.path.exists(storage_keyring):
        settings = {
            'keyring': storage_keyring,
            'client': 'client.storage'
        }
        settings.update(kwargs)
    return settings 
開發者ID:SUSE,項目名稱:DeepSea,代碼行數:19,代碼來源:osd.py

示例7: _mon_command

# 需要導入模塊: import rados [as 別名]
# 或者: from rados import Rados [as 別名]
def _mon_command(self, cmd_request):
        """ Issue a command to the monitor """

        buf_s = '{}'
        conf_file = "/etc/ceph/{}.conf".format(self.cluster_name)

        start = time.time()
        with rados.Rados(conffile=conf_file) as cluster:
            cmd = {'prefix': cmd_request, 'format': 'json'}
            rc, buf_s, out = cluster.mon_command(json.dumps(cmd), b'')
        end = time.time()

        self.logger.debug("_mon_command call '{}' :"
                          " {:.3f}s".format(cmd_request,
                                        (end - start)))

        return json.loads(buf_s) 
開發者ID:ceph,項目名稱:cephmetrics,代碼行數:19,代碼來源:mon.py

示例8: get_rbd_pools

# 需要導入模塊: import rados [as 別名]
# 或者: from rados import Rados [as 別名]
def get_rbd_pools(self):
        """
        Look at the rados pools to filter out pools that would normally not
        be associated with rbd images
        :return: (list) of pools that may contain rbd images
        """
        skip_pools = ('default.rgw', '.rgw.')

        start = time.time()
        conf_file = "/etc/ceph/{}.conf".format(self.cluster_name)
        with rados.Rados(conffile=conf_file) as cluster:
            rados_pools = sorted(cluster.list_pools())
        end = time.time()

        self.logger.debug('lspools took {:.3f}s'.format(end - start))

        filtered_pools = [pool for pool in rados_pools
                          if not pool.startswith(skip_pools)]

        return filtered_pools 
開發者ID:ceph,項目名稱:cephmetrics,代碼行數:22,代碼來源:mon.py

示例9: _perform_rados_call

# 需要導入模塊: import rados [as 別名]
# 或者: from rados import Rados [as 別名]
def _perform_rados_call(self):
        """The actual Rados interaction."""
        with Rados(conffile=self._ceph_config,
                   rados_id="landscape-client") as cluster:

            cluster_stats = cluster.get_cluster_stats()
            if self._ceph_ring_id is None:
                fsid = unicode(cluster.get_fsid(), "utf-8")
                self._ceph_ring_id = fsid

        return cluster_stats 
開發者ID:CanonicalLtd,項目名稱:landscape-client,代碼行數:13,代碼來源:cephusage.py

示例10: _connect

# 需要導入模塊: import rados [as 別名]
# 或者: from rados import Rados [as 別名]
def _connect(self):
        """
        Connect to Ceph cluster
        """
        self.cluster = rados.Rados(conffile=self.settings['conf'])
        self.cluster.connect() 
開發者ID:SUSE,項目名稱:DeepSea,代碼行數:8,代碼來源:mon.py

示例11: _tree

# 需要導入模塊: import rados [as 別名]
# 或者: from rados import Rados [as 別名]
def _tree(**kwargs):
    """
    Return osd tree
    """
    cluster = rados.Rados(**kwargs)
    cluster.connect()
    cmd = json.dumps({"prefix": "osd tree", "format": "json"})
    _, output, _ = cluster.mon_command(cmd, b'', timeout=6)
    osd_tree = json.loads(output)
    log.debug(json.dumps(osd_tree, indent=4))
    return osd_tree 
開發者ID:SUSE,項目名稱:DeepSea,代碼行數:13,代碼來源:osd.py

示例12: __init__

# 需要導入模塊: import rados [as 別名]
# 或者: from rados import Rados [as 別名]
def __init__(self, pool, namespace):
        self.pool = pool
        self.namespace = namespace
        self.rados = rados.Rados(conffile="/etc/ceph/ceph.conf", name="client.admin")
        self.rados.connect() 
開發者ID:SUSE,項目名稱:DeepSea,代碼行數:7,代碼來源:ganesha.py

示例13: find_pool

# 需要導入模塊: import rados [as 別名]
# 或者: from rados import Rados [as 別名]
def find_pool(applications, preferred_pool=None):
    try:
        import rados
    except ImportError:
        raise Exception("This method should not be called before Ceph is "
                        "installed")

    if not isinstance(applications, list):
        applications = [applications]

    cluster = rados.Rados(conffile="/etc/ceph/ceph.conf")
    cluster.connect()

    pools = [pool for pool in cluster.list_pools()]
    for pool in pools:
        if pool == preferred_pool:
            cluster.shutdown()
            return pool

    eligible_pools = []
    for pool in pools:
        pool_id = cluster.pool_lookup(pool)
        ioctx = cluster.open_ioctx(pool)
        for app in ioctx.application_list():
            if app in applications:
                eligible_pools.append((pool_id, pool))
        ioctx.close()

    cluster.shutdown()

    if not eligible_pools:
        return None

    eligible_pools = sorted(eligible_pools, key=lambda e: e[0])
    if [pool for _, pool in eligible_pools if pool == preferred_pool]:
        return preferred_pool
    return eligible_pools[0][1] 
開發者ID:SUSE,項目名稱:DeepSea,代碼行數:39,代碼來源:deepsea.py

示例14: __init__

# 需要導入模塊: import rados [as 別名]
# 或者: from rados import Rados [as 別名]
def __init__(self, pool, client_name, namespace=None):
        self.pool = pool
        self.namespace = namespace
        self.rados = rados.Rados(conffile="/etc/ceph/ceph.conf",
                                 name=client_name)
        self.rados.connect() 
開發者ID:SUSE,項目名稱:DeepSea,代碼行數:8,代碼來源:iscsi.py

示例15: __init__

# 需要導入模塊: import rados [as 別名]
# 或者: from rados import Rados [as 別名]
def __init__(self, conf, pool_size=5):
        self.conf = conf
        self.pool = queue.Queue(pool_size)
        if conf.ceph_client_id:
            self.cluster = rados.Rados(conffile=conf.ceph_conf_file, rados_id=conf.ceph_client_id)
        else:
            self.cluster = rados.Rados(conffile=conf.ceph_conf_file)
        self.lock = threading.Lock() 
開發者ID:haiwen,項目名稱:seafobj,代碼行數:10,代碼來源:ceph.py


注:本文中的rados.Rados方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。