From 522c184f4257c44f2e85205a48ccbecf9d1a9bdb Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 12 Oct 2021 11:13:04 -0500 Subject: [PATCH] mgr/nfs: add 'nfs cluster config get' Fixes: https://tracker.ceph.com/issues/52942 Signed-off-by: Sage Weil --- doc/mgr/nfs.rst | 9 +++++++++ src/pybind/mgr/nfs/cluster.py | 10 ++++++++++ src/pybind/mgr/nfs/export.py | 8 ++++++++ src/pybind/mgr/nfs/module.py | 5 +++++ 4 files changed, 32 insertions(+) diff --git a/doc/mgr/nfs.rst b/doc/mgr/nfs.rst index 2c70c5c2f25..54ca19fdd2e 100644 --- a/doc/mgr/nfs.rst +++ b/doc/mgr/nfs.rst @@ -204,6 +204,15 @@ Example use cases include: # ceph auth get-or-create client. mon 'allow r' osd 'allow rw pool=.nfs namespace=, allow rw tag cephfs data=' mds 'allow rw path=' +View Customized NFS Ganesha Configuration +----------------------------------------- + +.. code:: bash + + $ ceph nfs cluster config get + +This will output the user defined configuration (if any). + Reset NFS Ganesha Configuration ------------------------------- diff --git a/src/pybind/mgr/nfs/cluster.py b/src/pybind/mgr/nfs/cluster.py index 4ccf37d2b05..156b57e4c94 100644 --- a/src/pybind/mgr/nfs/cluster.py +++ b/src/pybind/mgr/nfs/cluster.py @@ -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): diff --git a/src/pybind/mgr/nfs/export.py b/src/pybind/mgr/nfs/export.py index 59c94a4dc0a..bfc779a9a52 100644 --- a/src/pybind/mgr/nfs/export.py +++ b/src/pybind/mgr/nfs/export.py @@ -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) diff --git a/src/pybind/mgr/nfs/module.py b/src/pybind/mgr/nfs/module.py index 6e97d48f834..d134e55eab2 100644 --- a/src/pybind/mgr/nfs/module.py +++ b/src/pybind/mgr/nfs/module.py @@ -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]: -- 2.39.5