fix(striker-ui-api): correct job data creation in create server

main
Tsu-ba-me 1 year ago
parent 4252435c04
commit 80108dd43e
  1. 37
      striker-ui-api/src/lib/request_handlers/server/createServer.ts

@ -5,6 +5,7 @@ import { REP_UUID, SERVER_PATHS } from '../../consts';
import { OS_LIST_MAP } from '../../consts/OS_LIST'; import { OS_LIST_MAP } from '../../consts/OS_LIST';
import { job, query } from '../../accessModule'; import { job, query } from '../../accessModule';
import { buildJobDataFromObject } from '../../buildJobData';
import { sanitize } from '../../sanitize'; import { sanitize } from '../../sanitize';
import { stderr, stdout, stdoutVar } from '../../shell'; import { stderr, stdout, stdoutVar } from '../../shell';
@ -33,7 +34,7 @@ export const createServer: RequestHandler = async (request, response) => {
const os = sanitize(rOptimizeForOs, 'string'); const os = sanitize(rOptimizeForOs, 'string');
const cpuCores = sanitize(rCpuCores, 'number'); const cpuCores = sanitize(rCpuCores, 'number');
const memory = sanitize(rMemory, 'number'); const memory = sanitize(rMemory, 'number');
const storageGroupUUID = sanitize(rStorageGroupUuid, 'string'); const storageGroupUuid = sanitize(rStorageGroupUuid, 'string');
const storageSize = sanitize(rStorageSize, 'number'); const storageSize = sanitize(rStorageSize, 'number');
const installIsoUuid = sanitize(rInstallIsoUuid, 'string'); const installIsoUuid = sanitize(rInstallIsoUuid, 'string');
const driverIsoUuid = sanitize(rDriverIsoUuid, 'string', { const driverIsoUuid = sanitize(rDriverIsoUuid, 'string', {
@ -72,8 +73,8 @@ export const createServer: RequestHandler = async (request, response) => {
); );
assert( assert(
REP_UUID.test(storageGroupUUID), REP_UUID.test(storageGroupUuid),
`Data storage group UUID must be a valid UUID; got [${storageGroupUUID}]`, `Data storage group UUID must be a valid UUID; got [${storageGroupUuid}]`,
); );
assert( assert(
@ -103,18 +104,7 @@ export const createServer: RequestHandler = async (request, response) => {
return response.status(400).send(); return response.status(400).send();
} }
const provisionServerJobData = `server_name=${serverName} const [[provisionServerJobHostUuid]]: [[string]] = await query(
os=${os}
cpu_cores=${cpuCores}
ram=${memory}
storage_group_uuid=${storageGroupUUID}
storage_size=${storageSize}
install_iso=${installIsoUuid}
driver_iso=${driverIsoUuid}`;
stdout(`provisionServerJobData=[${provisionServerJobData}]`);
const [[provisionServerJobHostUUID]]: [[string]] = await query(
`SELECT `SELECT
CASE CASE
WHEN pri_hos.primary_host_uuid IS NULL WHEN pri_hos.primary_host_uuid IS NULL
@ -147,17 +137,28 @@ driver_iso=${driverIsoUuid}`;
ON pri_hos.phl = nod_1.phr;`, ON pri_hos.phl = nod_1.phr;`,
); );
stdout(`provisionServerJobHostUUID=[${provisionServerJobHostUUID}]`); stdout(`provisionServerJobHostUuid=[${provisionServerJobHostUuid}]`);
try { try {
await job({ await job({
file: __filename, file: __filename,
job_command: SERVER_PATHS.usr.sbin['anvil-provision-server'].self, job_command: SERVER_PATHS.usr.sbin['anvil-provision-server'].self,
job_data: provisionServerJobData, job_data: buildJobDataFromObject({
obj: {
cpu_cores: cpuCores,
driver_iso: driverIsoUuid,
install_iso: installIsoUuid,
os,
ram: memory,
server_name: serverName,
storage_group_uuid: storageGroupUuid,
storage_size: storageSize,
},
}),
job_name: 'server:provision', job_name: 'server:provision',
job_title: 'job_0147', job_title: 'job_0147',
job_description: 'job_0148', job_description: 'job_0148',
job_host_uuid: provisionServerJobHostUUID, job_host_uuid: provisionServerJobHostUuid,
}); });
} catch (subError) { } catch (subError) {
stderr(`Failed to provision server; CAUSE: ${subError}`); stderr(`Failed to provision server; CAUSE: ${subError}`);

Loading…
Cancel
Save