From 28ca0652785eeca9722c8ae4c04f4c5514f2b4e2 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 4 May 2021 13:10:14 -0400 Subject: [PATCH] mgr/nfs: change 'nfs cluster info' - include the virtual_ip and port at top level - move backend server list into a sub-item - include (haproxy) monitoring port Signed-off-by: Sage Weil (cherry picked from commit 00aac5df9ea603d26c340279f97f45f366b6f26f) --- src/pybind/mgr/nfs/cluster.py | 39 +++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/pybind/mgr/nfs/cluster.py b/src/pybind/mgr/nfs/cluster.py index 8f8c4f6593a78..1f9e4db3e5127 100644 --- a/src/pybind/mgr/nfs/cluster.py +++ b/src/pybind/mgr/nfs/cluster.py @@ -2,8 +2,10 @@ import logging import socket import json import re +from typing import cast, Dict, List, Any, Union from ceph.deployment.service_spec import NFSServiceSpec, PlacementSpec, IngressSpec +from cephadm.utils import resolve_ip import orchestrator @@ -127,31 +129,38 @@ class NFSCluster: except Exception as e: return exception_handler(e, "Failed to list NFS Cluster") - def _show_nfs_cluster_info(self, cluster_id): + def _show_nfs_cluster_info(self, cluster_id: str) -> Dict[str, Any]: self._set_cluster_id(cluster_id) completion = self.mgr.list_daemons(daemon_type='nfs') orchestrator.raise_if_exception(completion) - host_ip = [] + backends: List[Dict[str, Union[str, int]]] = [] # 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({ + backends.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 + "ip": cluster.ip or resolve_ip(cluster.hostname), + "port": cluster.ports[0] }) - except socket.gaierror: + except OrchestratorError: continue - return host_ip + + r: Dict[str, Any] = { + 'virtual_ip': None, + 'backend': backends, + } + sc = self.mgr.describe_service(service_type='ingress') + orchestrator.raise_if_exception(sc) + for i in sc.result: + spec = cast(IngressSpec, i.spec) + if spec.backend_service == f'nfs.{cluster_id}': + r['virtual_ip'] = i.virtual_ip.split('/')[0] + if i.ports: + r['port'] = i.ports[0] + if len(i.ports) > 1: + r['monitor_port'] = i.ports[1] + return r def show_nfs_cluster_info(self, cluster_id=None): try: -- 2.39.5