Skip to content

Commit

Permalink
Move fabric endpoint retrieval to utils
Browse files Browse the repository at this point in the history
Summary:
Move fabric endpoint retrieval logic to a utility function for common
use.

Reviewed By: shri-khare

Differential Revision: D66775465

fbshipit-source-id: 376962a04b2792764fc00145a2cc23a9627fe57c
  • Loading branch information
jleung51 authored and facebook-github-bot committed Dec 4, 2024
1 parent 4085331 commit c14c5ea
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
17 changes: 1 addition & 16 deletions fboss/cli/fboss2/commands/show/fabric/CmdShowFabric.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,7 @@ class CmdShowFabric : public CmdHandler<CmdShowFabric, CmdShowFabricTraits> {
using RetType = CmdShowFabricTraits::RetType;

RetType queryClient(const HostInfo& hostInfo) {
std::map<std::string, FabricEndpoint> entries;
if (utils::isFbossFeatureEnabled(hostInfo.getName(), "multi_switch")) {
auto hwAgentQueryFn =
[&entries](
apache::thrift::Client<facebook::fboss::FbossHwCtrl>& client) {
std::map<std::string, FabricEndpoint> hwagentEntries;
client.sync_getHwFabricConnectivity(hwagentEntries);
entries.merge(hwagentEntries);
};
utils::runOnAllHwAgents(hostInfo, hwAgentQueryFn);
} else {
auto client =
utils::createClient<apache::thrift::Client<FbossCtrl>>(hostInfo);
client->sync_getFabricConnectivity(entries);
}
return createModel(entries);
return createModel(utils::getFabricEndpoints(hostInfo));
}

inline void udpateNametoIdString(std::string& name, int64_t value) {
Expand Down
19 changes: 19 additions & 0 deletions fboss/cli/fboss2/utils/CmdUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,4 +376,23 @@ cfg::SwitchType getSwitchType(
return switchType;
}

std::map<std::string, FabricEndpoint> getFabricEndpoints(
const HostInfo& hostInfo) {
std::map<std::string, FabricEndpoint> entries;
if (utils::isFbossFeatureEnabled(hostInfo.getName(), "multi_switch")) {
auto hwAgentQueryFn =
[&entries](
apache::thrift::Client<facebook::fboss::FbossHwCtrl>& client) {
std::map<std::string, FabricEndpoint> hwagentEntries;
client.sync_getHwFabricConnectivity(hwagentEntries);
entries.merge(hwagentEntries);
};
utils::runOnAllHwAgents(hostInfo, hwAgentQueryFn);
} else {
utils::createClient<apache::thrift::Client<FbossCtrl>>(hostInfo)
->sync_getFabricConnectivity(entries);
}
return entries;
}

} // namespace facebook::fboss::utils
3 changes: 3 additions & 0 deletions fboss/cli/fboss2/utils/CmdUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,7 @@ Table::StyledCell styledFecTail(int tail);
cfg::SwitchType getSwitchType(
std::map<int64_t, cfg::SwitchInfo> switchIdToSwitchInfo);

std::map<std::string, FabricEndpoint> getFabricEndpoints(
const HostInfo& hostInfo);

} // namespace facebook::fboss::utils

0 comments on commit c14c5ea

Please sign in to comment.