You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.4 KiB
48 lines
1.4 KiB
4 years ago
|
const processNetworkData = (data: AnvilNetwork): ProcessedNetwork => {
|
||
|
const processedBonds: string[] = [];
|
||
4 years ago
|
const displayBonds: ProcessedNetwork = { bonds: [] };
|
||
4 years ago
|
|
||
|
data?.nodes.forEach((node) => {
|
||
|
node.bonds.forEach((bond) => {
|
||
|
const index = processedBonds.findIndex(
|
||
|
(processed: string) => processed === bond.bond_name,
|
||
|
);
|
||
|
|
||
|
if (index === -1) {
|
||
|
processedBonds.push(bond.bond_name);
|
||
4 years ago
|
displayBonds.bonds.push({
|
||
4 years ago
|
bond_name: bond.bond_name,
|
||
|
bond_uuid: bond.bond_uuid,
|
||
4 years ago
|
bond_speed: 0,
|
||
|
bond_state: 'degraded',
|
||
4 years ago
|
nodes: [
|
||
|
{
|
||
|
host_name: node.host_name,
|
||
|
host_uuid: node.host_uuid,
|
||
|
link: bond.links[0].is_active ? bond.links[0] : bond.links[1],
|
||
|
},
|
||
|
],
|
||
|
});
|
||
|
} else {
|
||
4 years ago
|
displayBonds.bonds[index].nodes.push({
|
||
4 years ago
|
host_name: node.host_name,
|
||
|
host_uuid: node.host_uuid,
|
||
|
link: bond.links[0].is_active ? bond.links[0] : bond.links[1],
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
});
|
||
4 years ago
|
|
||
4 years ago
|
/* eslint-disable no-param-reassign */
|
||
|
displayBonds.bonds.forEach((bond) => {
|
||
|
const nodeIndex =
|
||
|
bond.nodes[0].link.link_speed > bond.nodes[1].link.link_speed ? 1 : 0;
|
||
|
|
||
|
bond.bond_speed = bond.nodes[nodeIndex].link.link_speed;
|
||
|
bond.bond_state = bond.nodes[nodeIndex].link.link_state;
|
||
|
});
|
||
4 years ago
|
return displayBonds;
|
||
4 years ago
|
};
|
||
|
|
||
|
export default processNetworkData;
|