parent
9ad619f269
commit
f863f7a046
3 changed files with 169 additions and 8 deletions
@ -0,0 +1,36 @@ |
||||
const processNetworkData = (data: AnvilNetwork): ProcessedNetwork => { |
||||
const processedBonds: string[] = []; |
||||
const thingy: ProcessedNetwork = { bonds: [] }; |
||||
|
||||
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); |
||||
thingy.bonds.push({ |
||||
bond_name: bond.bond_name, |
||||
bond_uuid: bond.bond_uuid, |
||||
nodes: [ |
||||
{ |
||||
host_name: node.host_name, |
||||
host_uuid: node.host_uuid, |
||||
link: bond.links[0].is_active ? bond.links[0] : bond.links[1], |
||||
}, |
||||
], |
||||
}); |
||||
} else { |
||||
thingy.bonds[index].nodes.push({ |
||||
host_name: node.host_name, |
||||
host_uuid: node.host_uuid, |
||||
link: bond.links[0].is_active ? bond.links[0] : bond.links[1], |
||||
}); |
||||
} |
||||
}); |
||||
}); |
||||
return thingy; |
||||
}; |
||||
|
||||
export default processNetworkData; |
@ -0,0 +1,43 @@ |
||||
declare type AnvilNetworkBondLink = { |
||||
link_name: string; |
||||
link_uuid: string; |
||||
link_speed: number; |
||||
link_state: 'optimal' | 'degraded'; |
||||
is_active: boolean; |
||||
}; |
||||
|
||||
declare type AnvilNetworkNodeBond = { |
||||
bond_name: string; |
||||
bond_uuid: string; |
||||
links: Array<AnvilNetworkBondLink>; |
||||
}; |
||||
|
||||
declare type AnvilNetworkNode = { |
||||
host_name: string; |
||||
host_uuid: string; |
||||
bonds: Array<AnvilNetworkNodeBond>; |
||||
}; |
||||
|
||||
declare type AnvilNetwork = { |
||||
nodes: Array<AnvilNetworkNode>; |
||||
}; |
||||
|
||||
declare type ProcessedBond = { |
||||
bond_name: string; |
||||
bond_uuid: string; |
||||
nodes: Array<{ |
||||
host_name: string; |
||||
host_uuid: string; |
||||
link: { |
||||
link_name: string; |
||||
link_uuid: string; |
||||
link_speed: number; |
||||
link_state: 'optimal' | 'degraded'; |
||||
is_active: boolean; |
||||
}; |
||||
}>; |
||||
}; |
||||
|
||||
declare type ProcessedNetwork = { |
||||
bonds: Array<ProcessedBond>; |
||||
}; |
Loading…
Reference in new issue