]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes/nfs: list exports within a ganesha cluster
authorRamana Raja <rraja@redhat.com>
Sun, 14 Jun 2020 16:33:16 +0000 (22:03 +0530)
committerVarsha Rao <varao@redhat.com>
Tue, 30 Jun 2020 17:47:38 +0000 (23:17 +0530)
List the pseudo paths of the exports within a ganesha cluster
with `nfs export ls <cluster ID>` command.

List all the details of the exports within a ganesha cluster
with `nfs export ls <cluster ID> --detailed` command.

Partially-fixes: https://tracker.ceph.com/issues/45741
Signed-off-by: Ramana Raja <rraja@redhat.com>
src/pybind/mgr/volumes/fs/nfs.py
src/pybind/mgr/volumes/module.py

index 3464eec3866c39f1f8c6543f1212647edb7b3760..8e97302870318391db54e1308b1692e4f1205303 100644 (file)
@@ -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)
index 6032d597183d1b5595a55e9eae293f8f0ad804de..2c106bda542454045ddeea1b16ee4c1c94036b04 100644 (file)
@@ -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))