feat(striker-ui-api): add provision server endpoint

main
Tsu-ba-me 3 years ago
parent 8310a6edbb
commit 8e64a9a185
  1. 60
      striker-ui-api/src/lib/request_handlers/server/createServer.ts
  2. 4
      striker-ui-api/src/lib/request_handlers/server/getServer.ts
  3. 2
      striker-ui-api/src/lib/request_handlers/server/index.ts
  4. 4
      striker-ui-api/src/routes/server.ts

@ -0,0 +1,60 @@
import { RequestHandler } from 'express';
// import SERVER_PATHS from '../../consts/SERVER_PATHS';
import { sub } from '../../accessModule';
export const createServer: RequestHandler = ({ body }, response) => {
console.log('Creating server.');
if (body) {
const {
serverName,
cpuCores,
memory,
virtualDisks: [{ storageSize, storageGroupUUID }],
installISOFileUUID,
driverISOFileUUIDs,
anvilUUID,
optimizeForOS,
} = body;
const provisionServerJobData = `
server_name=${serverName}
os=${optimizeForOS}
cpu_cores=${cpuCores}
ram=${memory}
storage_group_uuid=${storageGroupUUID}
storage_size=${storageSize}
install_iso=${installISOFileUUID}
driver_iso=${driverISOFileUUIDs}`;
console.log(`provisionServerJobData: ${provisionServerJobData}`);
const { stdout: provisionServerJobHostUUID } = sub(
'get_primary_host_uuid',
{
subModuleName: 'Cluster',
subParams: { anvil_uuid: anvilUUID },
},
);
console.log(`provisionServerJobHostUUID: [${provisionServerJobHostUUID}]`);
// sub('insert_or_update_jobs', {
// subParams: {
// file: __filename,
// line: 0,
// job_command: SERVER_PATHS.usr.sbin['anvil-provision-server'].self,
// job_data: provisionServerJobData,
// job_name: 'server:provision',
// job_title: 'job_0147',
// job_description: 'job_0148',
// job_progress: 0,
// job_host_uuid: provisionServerJobHostUUID,
// },
// });
}
response.status(202).send();
};

@ -1,7 +1,7 @@
import buildGetRequestHandler from '../buildGetRequestHandler'; import buildGetRequestHandler from '../buildGetRequestHandler';
import join from '../../join'; import join from '../../join';
const getServer = buildGetRequestHandler((request) => { export const getServer = buildGetRequestHandler((request) => {
const { anvilsUUID } = request.body; const { anvilsUUID } = request.body;
const condAnvilsUUID = join(anvilsUUID, { const condAnvilsUUID = join(anvilsUUID, {
@ -23,5 +23,3 @@ const getServer = buildGetRequestHandler((request) => {
WHERE server_state != 'DELETED' WHERE server_state != 'DELETED'
${condAnvilsUUID};`; ${condAnvilsUUID};`;
}); });
export default getServer;

@ -0,0 +1,2 @@
export { createServer } from './createServer';
export { getServer } from './getServer';

@ -1,9 +1,9 @@
import express from 'express'; import express from 'express';
import getServer from '../lib/request_handlers/server/getServer'; import { createServer, getServer } from '../lib/request_handlers/server';
const router = express.Router(); const router = express.Router();
router.get('/', getServer); router.get('/', getServer).post('/', createServer);
export default router; export default router;

Loading…
Cancel
Save