fix(striker-ui-api): add create_bridge to build network config

main
Tsu-ba-me 1 year ago
parent d2cd24be44
commit 103474a4e2
  1. 28
      striker-ui-api/src/lib/fconfig/buildNetworkConfig.ts

@ -3,13 +3,19 @@ import { cvar } from '../varn';
export const buildNetworkConfig = ( export const buildNetworkConfig = (
networks: InitializeStrikerNetworkForm[], networks: InitializeStrikerNetworkForm[],
configStep = 2, {
netconfStep = 2,
netcountStep = 1,
}: {
netconfStep?: number;
netcountStep?: number;
} = {},
): FormConfigData => { ): FormConfigData => {
const { counters: ncounts, data: cdata } = networks.reduce<{ const { counters: ncounts, data: cdata } = networks.reduce<{
counters: Record<InitializeStrikerNetworkForm['type'], number>; counters: Record<InitializeStrikerNetworkForm['type'], number>;
data: FormConfigData; data: FormConfigData;
}>( }>(
(previous, { interfaces, ipAddress, subnetMask, type }) => { (previous, { createBridge, interfaces, ipAddress, subnetMask, type }) => {
const { counters } = previous; const { counters } = previous;
counters[type] = counters[type] ? counters[type] + 1 : 1; counters[type] = counters[type] ? counters[type] + 1 : 1;
@ -18,24 +24,32 @@ export const buildNetworkConfig = (
previous.data = { previous.data = {
...previous.data, ...previous.data,
[cvar(configStep, `${networkShortName}_ip`)]: { [cvar(netconfStep, `${networkShortName}_ip`)]: {
step: configStep, step: netconfStep,
value: ipAddress, value: ipAddress,
}, },
[cvar(configStep, `${networkShortName}_subnet_mask`)]: { [cvar(netconfStep, `${networkShortName}_subnet_mask`)]: {
step: configStep, step: netconfStep,
value: subnetMask, value: subnetMask,
}, },
...buildNetworkLinkConfig(networkShortName, interfaces), ...buildNetworkLinkConfig(networkShortName, interfaces),
}; };
if (createBridge) {
previous.data[cvar(netconfStep, `${networkShortName}_create_bridge`)] =
{
step: netconfStep,
value: createBridge,
};
}
return previous; return previous;
}, },
{ counters: {}, data: {} }, { counters: {}, data: {} },
); );
Object.entries(ncounts).forEach(([ntype, ncount]) => { Object.entries(ncounts).forEach(([ntype, ncount]) => {
cdata[cvar(1, `${ntype}_count`)] = { value: ncount }; cdata[cvar(netcountStep, `${ntype}_count`)] = { value: ncount };
}); });
return cdata; return cdata;

Loading…
Cancel
Save