]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/nfs: add 'nfs cluster config get'
authorSage Weil <sage@newdream.net>
Tue, 12 Oct 2021 16:13:04 +0000 (11:13 -0500)
committerSage Weil <sage@newdream.net>
Fri, 15 Oct 2021 00:57:38 +0000 (20:57 -0400)
Fixes: https://tracker.ceph.com/issues/52942
Signed-off-by: Sage Weil <sage@newdream.net>
doc/mgr/nfs.rst
src/pybind/mgr/nfs/cluster.py
src/pybind/mgr/nfs/export.py
src/pybind/mgr/nfs/module.py

index 2c70c5c2f2501b81a5efc3f5814b9e6c471133a4..54ca19fdd2e26a3a26cc95c606cf0a503bdf0069 100644 (file)
@@ -204,6 +204,15 @@ Example use cases include:
 
          # ceph auth get-or-create client.<user_id> mon 'allow r' osd 'allow rw pool=.nfs namespace=<nfs_cluster_name>, allow rw tag cephfs data=<fs_name>' mds 'allow rw path=<export_path>'
 
+View Customized NFS Ganesha Configuration
+-----------------------------------------
+
+.. code:: bash
+
+    $ ceph nfs cluster config get <cluster_id>
+
+This will output the user defined configuration (if any).
+
 Reset NFS Ganesha Configuration
 -------------------------------
 
index 4ccf37d2b0572192b6e0d13289d7dc7b8ea96f99..156b57e4c947805efe6909ddc52056522e980d38 100644 (file)
@@ -213,6 +213,16 @@ class NFSCluster:
         except Exception as e:
             return exception_handler(e, "Failed to show info for cluster")
 
+    def get_nfs_cluster_config(self, cluster_id: str) -> Tuple[int, str, str]:
+        try:
+            if cluster_id in available_clusters(self.mgr):
+                rados_obj = NFSRados(self.mgr, cluster_id)
+                conf = rados_obj.read_obj(self._get_user_conf_obj_name(cluster_id))
+                return 0, conf or "", ""
+            raise ClusterNotFound()
+        except Exception as e:
+            return exception_handler(e, f"Fetching NFS-Ganesha Config failed for {cluster_id}")
+
     def set_nfs_cluster_config(self, cluster_id: str, nfs_config: str) -> Tuple[int, str, str]:
         try:
             if cluster_id in available_clusters(self.mgr):
index 59c94a4dc0ab9cbcc1c99783098df480d99de13f..bfc779a9a5247a9d5a9e6eee24cd5958e0656e2e 100644 (file)
@@ -74,6 +74,14 @@ class NFSRados:
             ExportMgr._check_rados_notify(ioctx, config_obj)
             log.debug("Added %s url to %s", obj, config_obj)
 
+    def read_obj(self, obj: str) -> Optional[str]:
+        with self.mgr.rados.open_ioctx(self.pool) as ioctx:
+            ioctx.set_namespace(self.namespace)
+            try:
+                return ioctx.read(obj, 1048576).decode()
+            except ObjectNotFound:
+                return None
+
     def update_obj(self, conf_block: str, obj: str, config_obj: str) -> None:
         with self.mgr.rados.open_ioctx(self.pool) as ioctx:
             ioctx.set_namespace(self.namespace)
index 6e97d48f83436894baa3b7cb8eee6514908f0c54..d134e55eab22edec741d70d58abe114691dbefc8 100644 (file)
@@ -120,6 +120,11 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
         """Displays NFS Cluster info"""
         return self.nfs.show_nfs_cluster_info(cluster_id=cluster_id)
 
+    @CLICommand('nfs cluster config get', perm='r')
+    def _cmd_nfs_cluster_config_get(self, cluster_id: str) -> Tuple[int, str, str]:
+        """Fetch NFS-Ganesha config"""
+        return self.nfs.get_nfs_cluster_config(cluster_id=cluster_id)
+
     @CLICommand('nfs cluster config set', perm='rw')
     @CLICheckNonemptyFileInput(desc='NFS-Ganesha Configuration')
     def _cmd_nfs_cluster_config_set(self, cluster_id: str, inbuf: str) -> Tuple[int, str, str]: