mirror of
https://github.com/ceph/ceph
synced 2025-02-19 17:08:05 +00:00
mgr/volumes/nfs: Add cluster show info command
Fixes: https://tracker.ceph.com/issues/45743 Signed-off-by: Varsha Rao <varao@redhat.com>
This commit is contained in:
parent
4425f3e678
commit
1faed4b1aa
@ -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
|
||||
====================
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user