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

Loading…
Cancel
Save