From: Shweta Bhosale Date: Wed, 18 Mar 2026 14:13:45 +0000 (+0530) Subject: cephadm: Added command to list RDMA devices X-Git-Tag: v21.0.1~422^2~4 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fb932fb426925e3bc61015860f3ec7ab84e2b18a;p=ceph.git cephadm: Added command to list RDMA devices Added 'cephadm list-rdma' command to list RDMA devices and their netdev interfaces Fixes: https://tracker.ceph.com/issues/75189 Signed-off-by: Shweta Bhosale --- diff --git a/doc/man/8/cephadm.rst b/doc/man/8/cephadm.rst index 0a42850bd59..ca43ca06dda 100644 --- a/doc/man/8/cephadm.rst +++ b/doc/man/8/cephadm.rst @@ -13,7 +13,7 @@ Synopsis | [--log-dir LOG_DIR] [--logrotate-dir LOGROTATE_DIR] | [--unit-dir UNIT_DIR] [--verbose] [--timeout TIMEOUT] | [--retry RETRY] [--no-container-init] -| {version,pull,inspect-image,ls,list-networks,adopt,rm-daemon,rm-cluster,run,shell,enter,ceph-volume,unit,logs,bootstrap,deploy,check-host,prepare-host,add-repo,rm-repo,install,list-images,update-osd-service} +| {version,pull,inspect-image,ls,list-networks,list-rdma,adopt,rm-daemon,rm-cluster,run,shell,enter,ceph-volume,unit,logs,bootstrap,deploy,check-host,prepare-host,add-repo,rm-repo,install,list-images,update-osd-service} | ... @@ -25,6 +25,8 @@ Synopsis | **cephadm** **list-networks** +| **cephadm** **list-rdma** + | **cephadm** **adopt** [-h] --name NAME --style STYLE [--cluster CLUSTER] | [--legacy-dir LEGACY_DIR] [--config-json CONFIG_JSON] | [--skip-firewalld] [--skip-pull] @@ -347,6 +349,10 @@ list-networks list IP networks +list-rdma +--------- + +list RDMA devices and their netdev interfaces ls -- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 7038d4214c8..2539ea46999 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -155,7 +155,7 @@ from cephadmlib.decorators import ( executes_early, require_image ) -from cephadmlib.host_facts import HostFacts, list_networks +from cephadmlib.host_facts import HostFacts, list_networks, list_rdma from cephadmlib.ssh import authorize_ssh_key, check_ssh_connectivity from cephadmlib.daemon_form import ( DaemonForm, @@ -3563,6 +3563,11 @@ def command_list_networks(ctx): print(json.dumps(r, indent=4, default=serialize_sets)) + +def command_list_rdma(ctx: CephadmContext) -> None: + r = list_rdma(ctx) + print(json.dumps(r, indent=4)) + ################################## @@ -5011,6 +5016,10 @@ def _get_parser(): 'list-networks', help='list IP networks') parser_list_networks.set_defaults(func=command_list_networks) + parser_list_rdma = subparsers.add_parser( + 'list-rdma', help='list RDMA devices and their netdev interfaces') + parser_list_rdma.set_defaults(func=command_list_rdma) + parser_adopt = subparsers.add_parser( 'adopt', help='adopt daemon deployed with a different tool') parser_adopt.set_defaults(func=command_adopt) diff --git a/src/cephadm/cephadmlib/host_facts.py b/src/cephadm/cephadmlib/host_facts.py index af5d2e23a67..9d7098f8be6 100644 --- a/src/cephadm/cephadmlib/host_facts.py +++ b/src/cephadm/cephadmlib/host_facts.py @@ -860,6 +860,49 @@ def list_networks(ctx): return res +def list_rdma(ctx: CephadmContext) -> List[Dict[str, str]]: + """List RDMA devices by parsing 'rdma link show' output. + Returns a list of dicts with keys: link, state, physical_state, netdev. + Returns empty list if rdma tool is not installed or command fails. + """ + execstr: Optional[str] = find_executable('rdma') + if not execstr: + logger.error("'rdma' command not found, no RDMA devices listed") + return [] + try: + out, _, _ = call_throws( + ctx, + [execstr, 'link', 'show'], + verbosity=CallVerbosity.QUIET_UNLESS_ERROR, + ) + except Exception as e: + logger.error('rdma link show failed: %s', e) + return [] + # Format: link state physical_state netdev + pattern = re.compile( + r'link\s+(\S+)\s+state\s+(\S+)\s+physical_state\s+(\S+)\s+netdev\s+' + r'(\S+)' + ) + result: List[Dict[str, str]] = [] + for line in out.splitlines(): + line = line.strip() + if not line: + continue + m = pattern.search(line) + if m: + result.append( + { + 'link': m.group(1), + 'state': m.group(2), + 'physical_state': m.group(3), + 'netdev': m.group(4), + } + ) + else: + logger.debug("Skipped RDMA device '%s', as pattern did not match", line) + return result + + def _list_ipv4_networks( ctx: CephadmContext, ) -> Dict[str, Dict[str, Set[str]]]: