class CephFS: mgr: Mgr mon: Mon def __init__(self): self.mgr = Mgr() self.mon = Mon() pass def create(self, name: str) -> None: cmd = { "prefix": "fs volume create", "name": name } try: res = self.mgr.call(cmd) except CephCommandError as e: raise CephFSError(e) from e # this command does not support json at this time, and will output # free-form text instead. We are not going to parse it, but we'll make # sure we've got something out of it. assert "result" in res assert len(res["result"]) > 0 def volume_ls(self) -> CephFSVolumeListModel: cmd = { "prefix": "fs volume ls", "format": "json" } try: res = self.mgr.call(cmd) except CephCommandError as e: raise CephFSError(e) from e return CephFSVolumeListModel( volumes=parse_obj_as(List[CephFSNameModel], res) ) def ls(self) -> List[CephFSListEntryModel]: cmd = { "prefix": "fs ls", "format": "json" } try: res = self.mon.call(cmd) except CephCommandError as e: raise CephFSError(e) from e return parse_obj_as(List[CephFSListEntryModel], res) def get_fs_info(self, name: str) -> CephFSListEntryModel: ls: List[CephFSListEntryModel] = self.ls() for fs in ls: if fs.name == name: return fs raise CephFSError(f"unknown filesystem {name}")
def test_get_pools( ceph_conf_file_fs: Generator[fake_filesystem.FakeFilesystem, None, None], mocker: MockerFixture, get_data_contents: Callable[[str, str], str] ): mon = Mon() mon.call = mocker.MagicMock( return_value=json.loads( get_data_contents(DATA_DIR, 'mon_osdmap_raw.json')) ) res = mon.get_pools() assert len(res) == 0
def test_mon_df( ceph_conf_file_fs: Generator[fake_filesystem.FakeFilesystem, None, None], mocker: MockerFixture, get_data_contents: Callable[[str, str], str] ): mon = Mon() mon.call = mocker.MagicMock( return_value=json.loads(get_data_contents(DATA_DIR, 'mon_df_raw.json')) ) res = mon.df() assert res.stats.total_bytes == 0
def test_get_pools( ceph_conf_file_fs: Generator[fake_filesystem.FakeFilesystem, None, None], mocker: MockerFixture, get_data_contents: Callable[[str, str], str], ): from gravel.controllers.orch.ceph import Ceph, Mon ceph = Ceph() mon = Mon(ceph) mon.call = mocker.MagicMock(return_value=json.loads( get_data_contents(DATA_DIR, "mon_osdmap_raw.json"))) res = mon.get_pools() assert len(res) == 0
class CephFS: mgr: Mgr mon: Mon def __init__(self): self.mgr = Mgr() self.mon = Mon() pass def create(self, name: str) -> None: cmd = {"prefix": "fs volume create", "name": name} try: # this is expected to be a silent command self.mgr.call(cmd) except CephCommandError as e: raise CephFSError(e) from e # schedule orchestrator to update the number of mds instances orch = Orchestrator() orch.apply_mds(name) def volume_ls(self) -> CephFSVolumeListModel: cmd = {"prefix": "fs volume ls", "format": "json"} try: res = self.mgr.call(cmd) except CephCommandError as e: raise CephFSError(e) from e return CephFSVolumeListModel( volumes=parse_obj_as(List[CephFSNameModel], res)) def ls(self) -> List[CephFSListEntryModel]: cmd = {"prefix": "fs ls", "format": "json"} try: res = self.mon.call(cmd) except CephCommandError as e: raise CephFSError(e) from e return parse_obj_as(List[CephFSListEntryModel], res) def get_fs_info(self, name: str) -> CephFSListEntryModel: ls: List[CephFSListEntryModel] = self.ls() for fs in ls: if fs.name == name: return fs raise CephFSError(f"unknown filesystem {name}")
class CephFS: mgr: Mgr mon: Mon def __init__(self): self.mgr = Mgr() self.mon = Mon() pass def create(self, name: str) -> None: cmd = {"prefix": "fs volume create", "name": name} try: # this is expected to be a silent command self.mgr.call(cmd) except CephCommandError as e: raise CephFSError(e) from e # schedule orchestrator to update the number of mds instances orch = Orchestrator() orch.apply_mds(name) def volume_ls(self) -> CephFSVolumeListModel: cmd = {"prefix": "fs volume ls", "format": "json"} try: res = self.mgr.call(cmd) except CephCommandError as e: raise CephFSError(e) from e return CephFSVolumeListModel( volumes=parse_obj_as(List[CephFSNameModel], res)) def ls(self) -> List[CephFSListEntryModel]: cmd = {"prefix": "fs ls", "format": "json"} try: res = self.mon.call(cmd) except CephCommandError as e: raise CephFSError(e) from e return parse_obj_as(List[CephFSListEntryModel], res) def get_fs_info(self, name: str) -> CephFSListEntryModel: ls: List[CephFSListEntryModel] = self.ls() for fs in ls: if fs.name == name: return fs raise CephFSError(f"unknown filesystem {name}") def authorize(self, fsname: str, clientid: str) -> CephFSAuthorizationModel: assert fsname and clientid cmd = { "prefix": "fs authorize", "filesystem": fsname, "entity": f"client.{fsname}-{clientid}", "caps": ["/", "rw"], "format": "json" } try: res = self.mon.call(cmd) except CephCommandError as e: raise CephFSError(str(e)) from e lst = parse_obj_as(List[CephFSAuthorizationModel], res) assert len(lst) == 1 return lst[0] def get_authorization(self, fsname: str, clientid: Optional[str]) -> CephFSAuthorizationModel: if not clientid: clientid = "default" cmd = { "prefix": "auth get", "entity": f"client.{fsname}-{clientid}", "format": "json" } try: res = self.mon.call(cmd) except CephCommandError as e: if e.rc == errno.ENOENT: raise CephFSNoAuthorizationError(e.message) raise CephFSError(str(e)) from e lst = parse_obj_as(List[CephFSAuthorizationModel], res) if len(lst) == 0: raise CephFSNoAuthorizationError() return lst[0]