fix(striker-ui): add storage network for nodes in NetworkInitForm

main
Tsu-ba-me 2 years ago
parent 03a251f44d
commit 73d04b7078
  1. 120
      striker-ui/components/NetworkInitForm.tsx

@ -100,41 +100,6 @@ type TestInputToToggleSubmitDisabled = (
>, >,
) => void; ) => void;
const MOCK_NICS: NetworkInterfaceOverviewMetadata[] = [
{
networkInterfaceUUID: 'fe299134-c8fe-47bd-ab7a-3aa95eada1f6',
networkInterfaceMACAddress: '52:54:00:d2:31:36',
networkInterfaceName: 'ens10',
networkInterfaceState: 'up',
networkInterfaceSpeed: 10000,
networkInterfaceOrder: 1,
},
{
networkInterfaceUUID: 'a652bfd5-61ac-4495-9881-185be8a2ac74',
networkInterfaceMACAddress: '52:54:00:d4:4d:b5',
networkInterfaceName: 'ens11',
networkInterfaceState: 'up',
networkInterfaceSpeed: 10000,
networkInterfaceOrder: 2,
},
{
networkInterfaceUUID: 'b8089b40-0969-49c3-ad65-2470ddb420ef',
networkInterfaceMACAddress: '52:54:00:ba:f5:a3',
networkInterfaceName: 'ens3',
networkInterfaceState: 'up',
networkInterfaceSpeed: 10000,
networkInterfaceOrder: 3,
},
{
networkInterfaceUUID: '42a17465-31b1-4e47-9a91-f803f22ffcc1',
networkInterfaceMACAddress: '52:54:00:ae:31:70',
networkInterfaceName: 'ens9',
networkInterfaceState: 'up',
networkInterfaceSpeed: 10000,
networkInterfaceOrder: 4,
},
];
const CLASS_PREFIX = 'NetworkInitForm'; const CLASS_PREFIX = 'NetworkInitForm';
const CLASSES = { const CLASSES = {
ifaceNotApplied: `${CLASS_PREFIX}-network-interface-not-applied`, ifaceNotApplied: `${CLASS_PREFIX}-network-interface-not-applied`,
@ -144,9 +109,10 @@ const INITIAL_IFACES = [undefined, undefined];
const NETWORK_TYPES: Record<string, string> = { const NETWORK_TYPES: Record<string, string> = {
bcn: 'Back-Channel Network', bcn: 'Back-Channel Network',
ifn: 'Internet-Facing Network', ifn: 'Internet-Facing Network',
sn: 'Storage Network',
}; };
const REQUIRED_NETWORKS: NetworkInput[] = [ const STRIKER_REQUIRED_NETWORKS: NetworkInput[] = [
{ {
inputUUID: '30dd2ac5-8024-4a7e-83a1-6a3df7218972', inputUUID: '30dd2ac5-8024-4a7e-83a1-6a3df7218972',
interfaces: [...INITIAL_IFACES], interfaces: [...INITIAL_IFACES],
@ -168,6 +134,19 @@ const REQUIRED_NETWORKS: NetworkInput[] = [
typeCount: 1, typeCount: 1,
}, },
]; ];
const NODE_REQUIRED_NETWORKS: NetworkInput[] = [
...STRIKER_REQUIRED_NETWORKS,
{
inputUUID: '525e4847-f929-44a7-83b2-28eb289ffb57',
interfaces: [...INITIAL_IFACES],
ipAddress: '10.202.1.1',
isRequired: true,
name: `${NETWORK_TYPES.sn} 1`,
subnetMask: '255.255.0.0',
type: 'sn',
typeCount: 1,
},
];
const MAX_INTERFACES_PER_NETWORK = 2; const MAX_INTERFACES_PER_NETWORK = 2;
const IT_IDS = { const IT_IDS = {
@ -584,15 +563,20 @@ const NetworkInitForm = forwardRef<
hostDetail?: APIHostDetail; hostDetail?: APIHostDetail;
toggleSubmitDisabled?: (testResult: boolean) => void; toggleSubmitDisabled?: (testResult: boolean) => void;
} }
>(({ hostDetail: { hostUUID = 'local' } = {}, toggleSubmitDisabled }, ref) => { >(
(
{ hostDetail: { hostType, hostUUID = 'local' } = {}, toggleSubmitDisabled },
ref,
) => {
const [dragMousePosition, setDragMousePosition] = useState<{ const [dragMousePosition, setDragMousePosition] = useState<{
x: number; x: number;
y: number; y: number;
}>({ x: 0, y: 0 }); }>({ x: 0, y: 0 });
const [networkInterfaceInputMap, setNetworkInterfaceInputMap] = const [networkInterfaceInputMap, setNetworkInterfaceInputMap] =
useState<NetworkInterfaceInputMap>({}); useState<NetworkInterfaceInputMap>({});
const [networkInputs, setNetworkInputs] = const [networkInputs, setNetworkInputs] = useState<NetworkInput[]>(
useState<NetworkInput[]>(REQUIRED_NETWORKS); hostType === 'node' ? NODE_REQUIRED_NETWORKS : STRIKER_REQUIRED_NETWORKS,
);
const [networkInterfaceHeld, setNetworkInterfaceHeld] = useState< const [networkInterfaceHeld, setNetworkInterfaceHeld] = useState<
NetworkInterfaceOverviewMetadata | undefined NetworkInterfaceOverviewMetadata | undefined
>(); >();
@ -602,12 +586,13 @@ const NetworkInitForm = forwardRef<
const dnsCSVInputRef = useRef<InputForwardedRefContent<'string'>>({}); const dnsCSVInputRef = useRef<InputForwardedRefContent<'string'>>({});
const messageGroupRef = useRef<MessageGroupForwardedRefContent>({}); const messageGroupRef = useRef<MessageGroupForwardedRefContent>({});
const { data: networkInterfaces = MOCK_NICS, isLoading } = periodicFetch< const { data: networkInterfaces = [], isLoading } = periodicFetch<
NetworkInterfaceOverviewMetadata[] NetworkInterfaceOverviewMetadata[]
>(`${API_BASE_URL}/network-interface/${hostUUID}`, { >(`${API_BASE_URL}/network-interface/${hostUUID}`, {
refreshInterval: 2000, refreshInterval: 2000,
onSuccess: (data) => { onSuccess: (data) => {
const map = data.reduce<NetworkInterfaceInputMap>((result, metadata) => { const map = data.reduce<NetworkInterfaceInputMap>(
(result, metadata) => {
const { networkInterfaceUUID } = metadata; const { networkInterfaceUUID } = metadata;
result[networkInterfaceUUID] = networkInterfaceInputMap[ result[networkInterfaceUUID] = networkInterfaceInputMap[
@ -615,7 +600,9 @@ const NetworkInitForm = forwardRef<
] ?? { metadata }; ] ?? { metadata };
return result; return result;
}, {}); },
{},
);
setNetworkInterfaceInputMap(map); setNetworkInterfaceInputMap(map);
}, },
@ -797,7 +784,8 @@ const NetworkInitForm = forwardRef<
const inputTestPrefix = createInputTestPrefix(inputUUID); const inputTestPrefix = createInputTestPrefix(inputUUID);
const inputTestIDIfaces = IT_IDS.networkInterfaces(inputTestPrefix); const inputTestIDIfaces = IT_IDS.networkInterfaces(inputTestPrefix);
const inputTestIDIPAddress = IT_IDS.networkIPAddress(inputTestPrefix); const inputTestIDIPAddress = IT_IDS.networkIPAddress(inputTestPrefix);
const inputTestIDSubnetMask = IT_IDS.networkSubnetMask(inputTestPrefix); const inputTestIDSubnetMask =
IT_IDS.networkSubnetMask(inputTestPrefix);
const setNetworkIfacesInputMessage = (message?: Message) => const setNetworkIfacesInputMessage = (message?: Message) =>
setMessage(inputTestIDIfaces, message); setMessage(inputTestIDIfaces, message);
@ -891,7 +879,9 @@ const NetworkInitForm = forwardRef<
}, },
{ {
test: ({ value }) => test: ({ value }) =>
testNetworkSubnetConflictWithDefaults({ ip: value as string }), testNetworkSubnetConflictWithDefaults({
ip: value as string,
}),
}, },
{ test: testNotBlank }, { test: testNotBlank },
], ],
@ -975,7 +965,10 @@ const NetworkInitForm = forwardRef<
}, [networkInputs, toggleSubmitDisabled]); }, [networkInputs, toggleSubmitDisabled]);
const removeNetwork = useCallback( const removeNetwork = useCallback(
(networkIndex: number) => { (networkIndex: number) => {
const [{ inputUUID, interfaces }] = networkInputs.splice(networkIndex, 1); const [{ inputUUID, interfaces }] = networkInputs.splice(
networkIndex,
1,
);
interfaces.forEach((iface) => { interfaces.forEach((iface) => {
if (iface === undefined) { if (iface === undefined) {
@ -987,13 +980,19 @@ const NetworkInitForm = forwardRef<
networkInterfaceInputMap[networkInterfaceUUID].isApplied = false; networkInterfaceInputMap[networkInterfaceUUID].isApplied = false;
}); });
testInputToToggleSubmitDisabled({ excludeTestIdsRe: RegExp(inputUUID) }); testInputToToggleSubmitDisabled({
excludeTestIdsRe: RegExp(inputUUID),
});
setNetworkInputs([...networkInputs]); setNetworkInputs([...networkInputs]);
setNetworkInterfaceInputMap((previous) => ({ setNetworkInterfaceInputMap((previous) => ({
...previous, ...previous,
})); }));
}, },
[networkInputs, networkInterfaceInputMap, testInputToToggleSubmitDisabled], [
networkInputs,
networkInterfaceInputMap,
testInputToToggleSubmitDisabled,
],
); );
const getNetworkTypeCount: GetNetworkTypeCountFunction = useCallback( const getNetworkTypeCount: GetNetworkTypeCountFunction = useCallback(
( (
@ -1109,27 +1108,6 @@ const NetworkInitForm = forwardRef<
[clearNetworkInterfaceHeld, networkInterfaceHeld], [clearNetworkInterfaceHeld, networkInterfaceHeld],
); );
useEffect(() => {
const map = networkInterfaces.reduce<NetworkInterfaceInputMap>(
(result, metadata) => {
const { networkInterfaceUUID } = metadata;
result[networkInterfaceUUID] = networkInterfaceInputMap[
networkInterfaceUUID
] ?? { metadata };
return result;
},
{},
);
setNetworkInterfaceInputMap(map);
// This block inits the input map for the MOCK_NICS.
// TODO: remove after testing.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useImperativeHandle( useImperativeHandle(
ref, ref,
() => ({ () => ({
@ -1151,7 +1129,8 @@ const NetworkInitForm = forwardRef<
interfaces, interfaces,
ipAddress: ipAddressInputRef?.current.getValue?.call(null) ?? '', ipAddress: ipAddressInputRef?.current.getValue?.call(null) ?? '',
name, name,
subnetMask: subnetMaskInputRef?.current.getValue?.call(null) ?? '', subnetMask:
subnetMaskInputRef?.current.getValue?.call(null) ?? '',
type, type,
typeCount, typeCount,
}), }),
@ -1382,7 +1361,8 @@ const NetworkInitForm = forwardRef<
</MUIBox> </MUIBox>
</MUIBox> </MUIBox>
); );
}); },
);
NetworkInitForm.defaultProps = { NetworkInitForm.defaultProps = {
hostDetail: undefined, hostDetail: undefined,

Loading…
Cancel
Save