From 750b0ac7c0ec908dfa47cf2605fe43670564b333 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Sun, 2 Jul 2023 20:53:08 -0400 Subject: [PATCH] fix(striker-ui-api): create bridge for node's bcn/ifn with 2 ifaces --- .../request_handlers/host/prepareNetwork.ts | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/striker-ui-api/src/lib/request_handlers/host/prepareNetwork.ts b/striker-ui-api/src/lib/request_handlers/host/prepareNetwork.ts index 4c22a342..f2afed11 100644 --- a/striker-ui-api/src/lib/request_handlers/host/prepareNetwork.ts +++ b/striker-ui-api/src/lib/request_handlers/host/prepareNetwork.ts @@ -9,7 +9,7 @@ import { SERVER_PATHS, } from '../../consts'; -import { job, variable } from '../../accessModule'; +import { job, query, variable } from '../../accessModule'; import { buildJobData } from '../../buildJobData'; import { buildNetworkConfig } from '../../fconfig'; import { sanitize } from '../../sanitize'; @@ -68,6 +68,35 @@ export const prepareNetwork: RequestHandler< return response.status(400).send(); } + let hostType: string; + + try { + const rows = await query<[[string]]>( + `SELECT host_type FROM hosts WHERE host_uuid = '${hostUUID}';`, + ); + + assert.ok(rows.length, `No record found`); + + [[hostType]] = rows; + } catch (error) { + stderr(`Failed to get host type with ${hostUUID}; CAUSE: ${error}`); + + return response.status(500).send(); + } + + networks.forEach((network) => { + const { interfaces: ifaces, type } = network; + + if ( + hostType === 'node' && + ['bcn', 'ifn'].includes(type) && + ifaces.length === 2 && + !ifaces.some((iface) => !iface) + ) { + network.createBridge = '1'; + } + }); + const configData: FormConfigData = { [cvar(2, 'dns')]: { step: 2, value: dns }, [cvar(2, 'gateway')]: { step: 2, value: gateway },