From: Varsha Rao Date: Mon, 22 Jun 2020 18:38:28 +0000 (+0530) Subject: mgr/volumes/nfs: Add cluster show info command X-Git-Tag: v15.2.5~166^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f99c4d10ecafd0e747b421e83435c9f987644ada;p=ceph.git 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) --- diff --git a/doc/cephfs/fs-nfs-exports.rst b/doc/cephfs/fs-nfs-exports.rst index f2db5a0c55ac..6e60c1d3add2 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 7a3a4a4afe36..279d73e30ed1 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 7fb465fbd8e0..17be126ed1e9 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))