fix(striker-ui-api): add commands for server VM power management

main
Tsu-ba-me 2 years ago
parent 993c2350e5
commit 9067791e38
  1. 2
      striker-ui-api/src/lib/consts/SERVER_PATHS.ts
  2. 22
      striker-ui-api/src/lib/request_handlers/command/buildPowerHandler.ts
  3. 2
      striker-ui-api/src/lib/request_handlers/command/index.ts
  4. 3
      striker-ui-api/src/lib/request_handlers/command/startServer.ts
  5. 3
      striker-ui-api/src/lib/request_handlers/command/stopServer.ts
  6. 4
      striker-ui-api/src/routes/command.ts
  7. 8
      striker-ui-api/src/types/BuildPowerHandlerFunction.d.ts

@ -24,6 +24,7 @@ const EMPTY_SERVER_PATHS: ServerPath = {
},
sbin: {
'anvil-access-module': {},
'anvil-boot-server': {},
'anvil-configure-host': {},
'anvil-get-server-screenshot': {},
'anvil-join-anvil': {},
@ -32,6 +33,7 @@ const EMPTY_SERVER_PATHS: ServerPath = {
'anvil-provision-server': {},
'anvil-safe-start': {},
'anvil-safe-stop': {},
'anvil-shutdown-server': {},
'anvil-sync-shared': {},
'anvil-update-system': {},
'striker-boot-machine': {},

@ -34,15 +34,27 @@ const MAP_TO_POWER_JOB_PARAMS_BUILDER: Record<
job_name: `set_power::on`,
job_title: 'job_0334',
}),
startserver: ({ uuid } = {}) => ({
job_command: `${SERVER_PATHS.usr.sbin['anvil-boot-server'].self} --server-uuid '${uuid}'`,
job_description: 'job_0341',
job_name: 'set_power::server::on',
job_title: 'job_0340',
}),
stop: ({ isStopServers, uuid } = {}) => ({
job_command: `${
SERVER_PATHS.usr.sbin['anvil-safe-stop'].self
} --power-off ${isStopServers ? '--stop-servers' : ''}`,
job_command: `${SERVER_PATHS.usr.sbin['anvil-safe-stop'].self} --power-off${
isStopServers ? ' --stop-servers' : ''
}`,
job_description: 'job_0333',
job_host_uuid: uuid,
job_name: 'set_power::off',
job_title: 'job_0332',
}),
stopserver: ({ uuid } = {}) => ({
job_command: `${SERVER_PATHS.usr.sbin['anvil-shutdown-server'].self} --server-uuid '${uuid}'`,
job_description: 'job_0343',
job_name: 'set_power::server::off',
job_title: 'job_0342',
}),
};
const queuePowerJob = async (
@ -74,7 +86,7 @@ export const buildPowerHandler: (
);
}
} catch (error) {
stderr(`Failed to ${task} host; CAUSE: ${error}`);
stderr(`Failed to ${task}; CAUSE: ${error}`);
return response.status(400).send();
}
@ -82,7 +94,7 @@ export const buildPowerHandler: (
try {
await queuePowerJob(task, { uuid });
} catch (error) {
stderr(`Failed to ${task} host ${uuid ?? LOCAL}; CAUSE: ${error}`);
stderr(`Failed to ${task} ${uuid ?? LOCAL}; CAUSE: ${error}`);
return response.status(500).send();
}

@ -7,7 +7,9 @@ export * from './rebootStriker';
export * from './runManifest';
export * from './setMapNetwork';
export * from './startAn';
export * from './startServer';
export * from './startSubnode';
export * from './stopAn';
export * from './stopServer';
export * from './stopSubnode';
export * from './updateSystem';

@ -0,0 +1,3 @@
import { buildPowerHandler } from './buildPowerHandler';
export const startServer = buildPowerHandler('startserver');

@ -0,0 +1,3 @@
import { buildPowerHandler } from './buildPowerHandler';
export const stopServer = buildPowerHandler('stopserver');

@ -10,8 +10,10 @@ import {
runManifest,
setMapNetwork,
startAn,
startServer,
startSubnode,
stopAn,
stopServer,
stopSubnode,
updateSystem,
} from '../lib/request_handlers/command';
@ -28,8 +30,10 @@ router
.put('/run-manifest/:manifestUuid', runManifest)
.put('/set-map-network/:uuid', setMapNetwork)
.put('/start-an/:uuid', startAn)
.put('/start-server/:uuid', startServer)
.put('/start-subnode/:uuid', startSubnode)
.put('/stop-an/:uuid', stopAn)
.put('/stop-server/:uuid', stopServer)
.put('/stop-subnode/:uuid', stopSubnode)
.put('/update-system', updateSystem);

@ -1,4 +1,10 @@
type PowerTask = 'poweroff' | 'reboot' | 'start' | 'stop';
type PowerTask =
| 'poweroff'
| 'reboot'
| 'start'
| 'startserver'
| 'stop'
| 'stopserver';
type PowerJobParams = Omit<JobParams, 'file' | 'line'>;

Loading…
Cancel
Save