From f99c4d10ecafd0e747b421e83435c9f987644ada Mon Sep 17 00:00:00 2001 From: Varsha Rao Date: Tue, 23 Jun 2020 00:08:28 +0530 Subject: [PATCH] mgr/volumes/nfs: Add cluster show info command Fixes: https://tracker.ceph.com/issues/45743 Signed-off-by: Varsha Rao (cherry picked from commit 1faed4b1aab736d63590b069aa0c1739a380f058) --- doc/cephfs/fs-nfs-exports.rst | 9 +++++++ src/pybind/mgr/volumes/fs/nfs.py | 46 ++++++++++++++++++++++++++++++++ src/pybind/mgr/volumes/module.py | 9 +++++++ 3 files changed, 64 insertions(+) diff --git a/doc/cephfs/fs-nfs-exports.rst b/doc/cephfs/fs-nfs-exports.rst index f2db5a0c55acd..6e60c1d3add26 100644 --- a/doc/cephfs/fs-nfs-exports.rst +++ b/doc/cephfs/fs-nfs-exports.rst @@ -54,6 +54,15 @@ List NFS Ganesha Cluster This lists deployed clusters. +Show NFS Ganesha Cluster Information +==================================== + +.. code:: bash + + $ ceph nfs cluster info [] + +This displays ip and port of deployed cluster. + Create CephFS Export ==================== diff --git a/src/pybind/mgr/volumes/fs/nfs.py b/src/pybind/mgr/volumes/fs/nfs.py index 7a3a4a4afe368..279d73e30ed11 100644 --- a/src/pybind/mgr/volumes/fs/nfs.py +++ b/src/pybind/mgr/volumes/fs/nfs.py @@ -2,6 +2,7 @@ import errno import json import logging from typing import List +import socket from ceph.deployment.service_spec import NFSServiceSpec, PlacementSpec from rados import TimedOut @@ -708,3 +709,48 @@ class NFSCluster: except Exception as e: log.exception("Failed to list NFS Cluster") return getattr(e, 'errno', -1), "", str(e) + + def _show_nfs_cluster_info(self, cluster_id): + self._set_cluster_id(cluster_id) + completion = self.mgr.list_daemons(daemon_type='nfs') + self.mgr._orchestrator_wait([completion]) + orchestrator.raise_if_exception(completion) + host_ip = [] + # Here completion.result is a list DaemonDescription objects + for cluster in completion.result: + if self.cluster_id == cluster.service_id(): + """ + getaddrinfo sample output: [(, + , 6, 'xyz', ('172.217.166.98',2049)), + (, , 6, '', + ('2404:6800:4009:80d::200e', 2049, 0, 0))] + """ + try: + host_ip.append({ + "hostname": cluster.hostname, + "ip": list(set([ip[4][0] for ip in socket.getaddrinfo( + cluster.hostname, 2049, flags=socket.AI_CANONNAME, + type=socket.SOCK_STREAM)])), + "port": 2049 # Default ganesha port + }) + except socket.gaierror: + continue + return host_ip + + def show_nfs_cluster_info(self, cluster_id=None): + try: + cluster_ls = [] + info_res = {} + if cluster_id: + cluster_ls = [cluster_id] + else: + cluster_ls = available_clusters(self.mgr) + + for cluster_id in cluster_ls: + res = self._show_nfs_cluster_info(cluster_id) + if res: + info_res[cluster_id] = res + return (0, json.dumps(info_res, indent=4), '') + except Exception as e: + log.exception(f"Failed to show info for cluster") + return getattr(e, 'errno', -1), "", str(e) diff --git a/src/pybind/mgr/volumes/module.py b/src/pybind/mgr/volumes/module.py index 7fb465fbd8e0b..17be126ed1e92 100644 --- a/src/pybind/mgr/volumes/module.py +++ b/src/pybind/mgr/volumes/module.py @@ -310,6 +310,12 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): 'desc': "List NFS Clusters", 'perm': 'r' }, + { + 'cmd': 'nfs cluster info ' + 'name=clusterid,type=CephString,req=false ', + 'desc': "Displays NFS Cluster info", + 'perm': 'r' + }, # volume ls [recursive] # subvolume ls # volume authorize/deauthorize @@ -525,3 +531,6 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): def _cmd_nfs_cluster_ls(self, inbuf, cmd): return self.nfs.list_nfs_cluster() + + def _cmd_nfs_cluster_info(self, inbuf, cmd): + return self.nfs.show_nfs_cluster_info(cluster_id=cmd.get('clusterid', None)) -- 2.39.5