From c14c5eafe772814cc299556e75d191a1df3ca29e Mon Sep 17 00:00:00 2001 From: Jeffrey Leung Date: Wed, 4 Dec 2024 14:49:19 -0800 Subject: [PATCH] Move fabric endpoint retrieval to utils Summary: Move fabric endpoint retrieval logic to a utility function for common use. Reviewed By: shri-khare Differential Revision: D66775465 fbshipit-source-id: 376962a04b2792764fc00145a2cc23a9627fe57c --- .../commands/show/fabric/CmdShowFabric.h | 17 +---------------- fboss/cli/fboss2/utils/CmdUtils.cpp | 19 +++++++++++++++++++ fboss/cli/fboss2/utils/CmdUtils.h | 3 +++ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/fboss/cli/fboss2/commands/show/fabric/CmdShowFabric.h b/fboss/cli/fboss2/commands/show/fabric/CmdShowFabric.h index 94b876e20c777..6a92c707d0b47 100644 --- a/fboss/cli/fboss2/commands/show/fabric/CmdShowFabric.h +++ b/fboss/cli/fboss2/commands/show/fabric/CmdShowFabric.h @@ -39,22 +39,7 @@ class CmdShowFabric : public CmdHandler { using RetType = CmdShowFabricTraits::RetType; RetType queryClient(const HostInfo& hostInfo) { - std::map entries; - if (utils::isFbossFeatureEnabled(hostInfo.getName(), "multi_switch")) { - auto hwAgentQueryFn = - [&entries]( - apache::thrift::Client& client) { - std::map hwagentEntries; - client.sync_getHwFabricConnectivity(hwagentEntries); - entries.merge(hwagentEntries); - }; - utils::runOnAllHwAgents(hostInfo, hwAgentQueryFn); - } else { - auto client = - utils::createClient>(hostInfo); - client->sync_getFabricConnectivity(entries); - } - return createModel(entries); + return createModel(utils::getFabricEndpoints(hostInfo)); } inline void udpateNametoIdString(std::string& name, int64_t value) { diff --git a/fboss/cli/fboss2/utils/CmdUtils.cpp b/fboss/cli/fboss2/utils/CmdUtils.cpp index c74f1e490a231..f68912d3e68d9 100644 --- a/fboss/cli/fboss2/utils/CmdUtils.cpp +++ b/fboss/cli/fboss2/utils/CmdUtils.cpp @@ -376,4 +376,23 @@ cfg::SwitchType getSwitchType( return switchType; } +std::map getFabricEndpoints( + const HostInfo& hostInfo) { + std::map entries; + if (utils::isFbossFeatureEnabled(hostInfo.getName(), "multi_switch")) { + auto hwAgentQueryFn = + [&entries]( + apache::thrift::Client& client) { + std::map hwagentEntries; + client.sync_getHwFabricConnectivity(hwagentEntries); + entries.merge(hwagentEntries); + }; + utils::runOnAllHwAgents(hostInfo, hwAgentQueryFn); + } else { + utils::createClient>(hostInfo) + ->sync_getFabricConnectivity(entries); + } + return entries; +} + } // namespace facebook::fboss::utils diff --git a/fboss/cli/fboss2/utils/CmdUtils.h b/fboss/cli/fboss2/utils/CmdUtils.h index 25366caad3d62..69f6198af4a35 100644 --- a/fboss/cli/fboss2/utils/CmdUtils.h +++ b/fboss/cli/fboss2/utils/CmdUtils.h @@ -472,4 +472,7 @@ Table::StyledCell styledFecTail(int tail); cfg::SwitchType getSwitchType( std::map switchIdToSwitchInfo); +std::map getFabricEndpoints( + const HostInfo& hostInfo); + } // namespace facebook::fboss::utils