]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/volumes/nfs: Add cluster show info command
authorVarsha Rao <varao@redhat.com>
Mon, 22 Jun 2020 18:38:28 +0000 (00:08 +0530)
committerVarsha Rao <varao@redhat.com>
Wed, 8 Jul 2020 05:37:14 +0000 (07:37 +0200)
Fixes: https://tracker.ceph.com/issues/45743
Signed-off-by: Varsha Rao <varao@redhat.com>
(cherry picked from commit 1faed4b1aab736d63590b069aa0c1739a380f058)

doc/cephfs/fs-nfs-exports.rst
src/pybind/mgr/volumes/fs/nfs.py
src/pybind/mgr/volumes/module.py

index f2db5a0c55acd6e90e00f5f3d158247136b52598..6e60c1d3add264604a5ec2c66055677a788d17fc 100644 (file)
@@ -54,6 +54,15 @@ List NFS Ganesha Cluster
 
 This lists deployed clusters.
 
+Show NFS Ganesha Cluster Information
+====================================
+
+.. code:: bash
+
+    $ ceph nfs cluster info [<clusterid>]
+
+This displays ip and port of deployed cluster.
+
 Create CephFS Export
 ====================
 
index 7a3a4a4afe36886f973a00d8078eca46ec543c57..279d73e30ed111eee263c4c94fe3ce34252ccb93 100644 (file)
@@ -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: [(<AddressFamily.AF_INET: 2>,
+                <SocketKind.SOCK_STREAM: 1>, 6, 'xyz', ('172.217.166.98',2049)),
+                (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_STREAM: 1>, 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)
index 7fb465fbd8e0bfdb8a7a8e19d03dff232debe4be..17be126ed1e9273c36eeb01280e5247281ce1b19 100644 (file)
@@ -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>
         # 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))