Example #1
0
    def _create_cephfs(self, svc: ServiceModel) -> None:
        cephfs = CephFS()
        try:
            cephfs.create(svc.name)
        except CephFSError as e:
            raise ServiceError("unable to create cephfs service") from e

        try:
            fs: CephFSListEntryModel = cephfs.get_fs_info(svc.name)
        except CephFSError as e:
            raise ServiceError("unable to list cephfs filesystems") from e
        assert fs.name == svc.name

        mon = Mon()
        pools: List[CephOSDPoolEntryModel] = mon.get_pools()

        def get_pool(name: str) -> CephOSDPoolEntryModel:
            for pool in pools:
                if pool.pool_name == name:
                    return pool
            raise ServiceError(f"unknown pool {name}")

        metadata_pool = get_pool(fs.metadata_pool)
        if metadata_pool.size != svc.replicas:
            mon.set_pool_size(metadata_pool.pool_name, svc.replicas)
        svc.pools.append(metadata_pool.pool)

        for name in fs.data_pools:
            data_pool = get_pool(name)
            if data_pool.size != svc.replicas:
                mon.set_pool_size(data_pool.pool_name, svc.replicas)
            svc.pools.append(data_pool.pool)
Example #2
0
async def get_authorization(name: str,
                            clientid: Optional[str] = None
                            ) -> CephFSAuthorizationModel:
    """
    Obtain authorization credentials for a given service `name`. In case of
    success, will return an entity and a cephx key. If `clientid` is supplied,
    will obtain the authorization for a client with said `clientid`, if it
    exists.
    """
    cephfs: CephFS = CephFS()
    try:
        result = cephfs.get_authorization(name, clientid)
        return result
    except CephFSNoAuthorizationError:
        raise HTTPException(status.HTTP_404_NOT_FOUND,
                            detail="No authorization found for service")
    except CephFSError as e:
        raise HTTPException(status.HTTP_500_INTERNAL_SERVER_ERROR,
                            detail=str(e))
Example #3
0
    def _create_cephfs(self, svc: ServiceModel) -> None:
        cephfs = CephFS()
        try:
            cephfs.create(svc.name)
        except CephFSError as e:
            raise ServiceError("unable to create cephfs service") from e

        try:
            fs: CephFSListEntryModel = cephfs.get_fs_info(svc.name)
        except CephFSError as e:
            raise ServiceError("unable to list cephfs filesystems") from e
        assert fs.name == svc.name

        mon = Mon()
        pools: List[CephOSDPoolEntryModel] = mon.get_pools()

        def get_pool(name: str) -> CephOSDPoolEntryModel:
            for pool in pools:
                if pool.pool_name == name:
                    return pool
            raise ServiceError(f"unknown pool {name}")

        metadata_pool = get_pool(fs.metadata_pool)
        if metadata_pool.size != svc.replicas:
            mon.set_pool_size(metadata_pool.pool_name, svc.replicas)
        svc.pools.append(metadata_pool.pool)

        for name in fs.data_pools:
            data_pool = get_pool(name)
            if data_pool.size != svc.replicas:
                mon.set_pool_size(data_pool.pool_name, svc.replicas)
            svc.pools.append(data_pool.pool)

        # create cephfs default user
        logger.debug("authorize default user")
        try:
            cephfs.authorize(svc.name, "default")
            logger.info(f"created cephfs client for service '{svc.name}'")
        except CephFSError as e:
            logger.error(f"Unable to authorize cephfs client: {str(e)}")
            logger.exception(e)
Example #4
0
# project aquarium's backend
# Copyright (C) 2021 SUSE, LLC.

from gravel.controllers.orch.ceph import Ceph, Mgr, Mon
from gravel.controllers.orch.cephfs import CephFS, CephFSError

if __name__ == "__main__":
    ceph: Ceph = Ceph()
    ceph_mgr: Mgr = Mgr(ceph)
    ceph_mon: Mon = Mon(ceph)
    cephfs: CephFS = CephFS(ceph_mgr, ceph_mon)

    try:
        cephfs.create("foobarbaz")
    except CephFSError as e:
        print(f"error: {str(e)}")
    res = cephfs.volume_ls()
    print(res.json())
    print(cephfs.ls())
# project aquarium's backend
# Copyright (C) 2021 SUSE, LLC.

from gravel.controllers.orch.cephfs import CephFS, CephFSError

if __name__ == "__main__":
    cephfs = CephFS()
    try:
        cephfs.create("foobarbaz")
    except CephFSError as e:
        print(f"error: {str(e)}")
    res = cephfs.volume_ls()
    print(res.json())
    print(cephfs.ls())