Пример #1
0
def track_pg_creation(fsid,
                      pool_id,
                      pg_count_before,
                      pg_count_after,
                      pgs_current_active=None):
    """
    :type fsid: str
    :type pool_id: int
    :type pg_count_before: int
    :type pg_count_after: int
    :type pgs_current_active: int | None
    """
    from ceph.models import CephPg, CephPool, fsid_context

    with fsid_context(fsid):
        pool = CephPool.objects.get(id=pool_id)
        pgs = list(CephPg.objects.filter(pool_name__exact=pool.name))

        def pg_in_state(state):
            return len([pg for pg in pgs if state in pg.state])

        active = pg_in_state('active')
        creating = pg_in_state('creating')

        logger.info('before={} after={} all={} active={} creating={}'.format(
            pg_count_before, pg_count_after, len(pgs), active, creating))

        if active >= pg_count_after:
            return
        else:
            return track_pg_creation(fsid, pool_id, pg_count_before,
                                     pg_count_after, active)
Пример #2
0
def set_pgs(fsid, pool_id, pgs):
    from ceph.models import CephPool, fsid_context

    with fsid_context(fsid) as ctx:
        pool = CephPool.objects.get(id=pool_id)
        api = librados.MonApi(fsid)

        api.osd_pool_set(pool.name, 'pg_num', pgs)
        api.osd_pool_set(pool.name, 'pgp_num', pgs)
        return track_pg_creation(fsid, pool_id, pool.pg_num, pgs)
Пример #3
0
def copy_rbd(fsid,
             s_pool,
             s_image,
             d_pool,
             d_image,
             features=None,
             order=None,
             stripe_unit=None,
             stripe_count=None,
             data_pool_name=None):
    from ceph.models import fsid_context
    with fsid_context(fsid) as ctx:
        rbd_api = librados.RbdApi(fsid)
        rbd_api.copy(s_pool, s_image, d_pool, d_image, features, order,
                     stripe_unit, stripe_count, data_pool_name)
Пример #4
0
def rollback_to_snapshot(fsid, pool_name, image_name, snap_name):
    from ceph.models import fsid_context
    with fsid_context(fsid) as ctx:
        rbd_api = librados.RbdApi(fsid)
        rbd_api.rollback_to_snapshot(pool_name, image_name, snap_name)
Пример #5
0
def delete_rbd(fsid, pool_name, image_name):
    from ceph.models import fsid_context
    with fsid_context(fsid) as ctx:
        rbd_api = librados.RbdApi(fsid)
        rbd_api.remove(pool_name, image_name)