From: Ramana Raja Date: Sun, 14 Jun 2020 16:33:16 +0000 (+0530) Subject: mgr/volumes/nfs: list exports within a ganesha cluster X-Git-Tag: v17.0.0~1910^2~18 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=6f8d20f2cbcdb5a0351a050abd6d66c0c840c108;p=ceph.git mgr/volumes/nfs: list exports within a ganesha cluster List the pseudo paths of the exports within a ganesha cluster with `nfs export ls ` command. List all the details of the exports within a ganesha cluster with `nfs export ls --detailed` command. Partially-fixes: https://tracker.ceph.com/issues/45741 Signed-off-by: Ramana Raja --- diff --git a/src/pybind/mgr/volumes/fs/nfs.py b/src/pybind/mgr/volumes/fs/nfs.py index 3464eec3866c3..8e97302870318 100644 --- a/src/pybind/mgr/volumes/fs/nfs.py +++ b/src/pybind/mgr/volumes/fs/nfs.py @@ -209,6 +209,15 @@ class CephFSFSal(): return cls(fsal_dict['name'], fsal_dict['user_id'], fsal_dict['fs_name'], fsal_dict['sec_label_xattr'], None) + def to_dict(self): + return { + 'name': self.name, + 'user_id': self.user_id, + 'fs_name': self.fs_name, + 'sec_label_xattr': self.sec_label_xattr + } + + class Client(object): def __init__(self, addresses, access_type=None, squash=None): self.addresses = addresses @@ -312,6 +321,22 @@ class Export(object): ex_dict['access_type'], [Client.from_dict(client) for client in ex_dict['clients']]) + def to_dict(self): + return { + 'export_id': self.export_id, + 'path': self.path, + 'fsal': self.fsal.to_dict(), + 'cluster_id': self.cluster_id, + 'pseudo': self.pseudo, + 'access_type': self.access_type, + 'squash': self.squash, + 'security_label': self.security_label, + 'protocols': sorted([p for p in self.protocols]), + 'transports': sorted([t for t in self.transports]), + 'clients': [client.to_dict() for client in self.clients] + } + + class FSExport(object): def __init__(self, mgr, namespace=None): self.mgr = mgr @@ -525,6 +550,16 @@ class FSExport(object): except KeyError: log.info("No exports to delete") + def list_exports(self, cluster_id, detailed): + if not f"ganesha-{cluster_id}" in available_clusters(self.mgr): + return -errno.ENOENT, "", f"NFS cluster '{cluster_id}' not found" + if detailed: + result = [export.to_dict() for export in self.exports[cluster_id]] + else: + result = [export.pseudo for export in self.exports[cluster_id]] + + return 0, json.dumps(result, indent=2), '' + def make_rados_url(self, obj): if self.rados_namespace: return "rados://{}/{}/{}".format(self.rados_pool, self.rados_namespace, obj) diff --git a/src/pybind/mgr/volumes/module.py b/src/pybind/mgr/volumes/module.py index 6032d597183d1..2c106bda54245 100644 --- a/src/pybind/mgr/volumes/module.py +++ b/src/pybind/mgr/volumes/module.py @@ -270,6 +270,13 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): 'desc': "Delete a cephfs export", 'perm': 'rw' }, + { + 'cmd': 'nfs export ls ' + 'name=clusterid,type=CephString ' + 'name=detailed,type=CephBool,req=false ', + 'desc': "List exports of a NFS cluster", + 'perm': 'r' + }, { 'cmd': 'nfs cluster create ' 'name=type,type=CephString ' @@ -488,6 +495,9 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): def _cmd_nfs_export_delete(self, inbuf, cmd): return self.fs_export.delete_export(cluster_id=cmd['attach'], pseudo_path=cmd['binding']) + def _cmd_nfs_export_ls(self, inbuf, cmd): + return self.fs_export.list_exports(cluster_id=cmd['clusterid'], detailed=cmd.get('detailed', False)) + def _cmd_nfs_cluster_create(self, inbuf, cmd): return self.nfs.create_nfs_cluster(cluster_id=cmd['clusterid'], export_type=cmd['type'], placement=cmd.get('placement', None))