From 5c2b0d9bdd7359dece8afe1c30776db1aed97053 Mon Sep 17 00:00:00 2001 From: Brian M Date: Fri, 15 Nov 2024 07:55:33 -0800 Subject: [PATCH] Address review: use PythonMetric for rdma_link_choices (cherry picked from commit 420baa8417d159ad2e81b2fa2ee263ec5ee17009) --- ixdiagnose/plugins/network.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ixdiagnose/plugins/network.py b/ixdiagnose/plugins/network.py index 631c34d..2f3f9fd 100644 --- a/ixdiagnose/plugins/network.py +++ b/ixdiagnose/plugins/network.py @@ -1,8 +1,20 @@ +from typing import Any + from ixdiagnose.utils.command import Command -from ixdiagnose.utils.middleware import MiddlewareCommand +from ixdiagnose.utils.formatter import dumps +from ixdiagnose.utils.middleware import MiddlewareClient, MiddlewareCommand from .base import Plugin -from .metrics import CommandMetric, FileMetric, MiddlewareClientMetric +from .metrics import CommandMetric, FileMetric, MiddlewareClientMetric, PythonMetric + + +def link_choices(client: MiddlewareClient, context: Any) -> str: + summary = {} + configured_interfaces = client.call('interface.get_configured_interfaces') + for link in client.call('rdma.get_link_choices', True): + summary[link['netdev']] = link | {'configured_interface': link['netdev'] in configured_interfaces} + + return dumps(summary) class Network(Plugin): @@ -33,11 +45,10 @@ class Network(Plugin): 'rdma_config', [ MiddlewareCommand('rdma.capable_protocols', result_key='capable_protocols'), MiddlewareCommand('rdma.get_card_choices', result_key='card_choices'), - MiddlewareCommand('rdma.get_link_choices', [True], result_key='all_link_choices'), - MiddlewareCommand('rdma.get_link_choices', result_key='link_choices'), MiddlewareCommand('rdma.interface.query', result_key='interfaces'), ] ), + PythonMetric('rdma_link_choices', link_choices), ] raw_metrics = [ CommandMetric(