2021-01-06 23:38:39 +00:00
|
|
|
import http from '@/api/http';
|
|
|
|
import { Server, rawDataToServer } from '@/api/admin/servers/getServers';
|
|
|
|
|
2021-10-24 20:14:04 +00:00
|
|
|
export interface CreateServerRequest {
|
|
|
|
externalId: string;
|
2021-01-13 16:43:57 +00:00
|
|
|
name: string;
|
|
|
|
description: string | null;
|
2021-10-24 20:14:04 +00:00
|
|
|
ownerId: number;
|
|
|
|
nodeId: number;
|
2021-01-13 16:43:57 +00:00
|
|
|
|
|
|
|
limits: {
|
|
|
|
memory: number;
|
|
|
|
swap: number;
|
2021-10-24 20:14:04 +00:00
|
|
|
disk: number;
|
|
|
|
io: number;
|
|
|
|
cpu: number;
|
2021-01-13 16:43:57 +00:00
|
|
|
threads: string;
|
2021-10-24 20:14:04 +00:00
|
|
|
oomDisabled: boolean;
|
|
|
|
}
|
2021-01-13 16:43:57 +00:00
|
|
|
|
|
|
|
featureLimits: {
|
|
|
|
allocations: number;
|
|
|
|
backups: number;
|
|
|
|
databases: number;
|
|
|
|
};
|
2021-10-24 20:14:04 +00:00
|
|
|
|
|
|
|
allocation: {
|
|
|
|
default: number;
|
|
|
|
additional: number[];
|
|
|
|
};
|
|
|
|
|
|
|
|
startup: string;
|
|
|
|
environment: Record<string, any>;
|
|
|
|
eggId: number;
|
|
|
|
image: string;
|
|
|
|
skipScripts: boolean;
|
|
|
|
startOnCompletion: boolean;
|
2021-01-13 16:43:57 +00:00
|
|
|
}
|
|
|
|
|
2021-01-15 16:41:15 +00:00
|
|
|
export default (r: CreateServerRequest, include: string[] = []): Promise<Server> => {
|
2021-01-06 23:38:39 +00:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
http.post('/api/application/servers', {
|
2021-10-24 20:14:04 +00:00
|
|
|
externalId: r.externalId,
|
2021-01-13 16:43:57 +00:00
|
|
|
name: r.name,
|
|
|
|
description: r.description,
|
2021-10-24 20:14:04 +00:00
|
|
|
owner_id: r.ownerId,
|
|
|
|
node_id: r.nodeId,
|
2021-01-13 16:43:57 +00:00
|
|
|
|
|
|
|
limits: {
|
|
|
|
cpu: r.limits.cpu,
|
|
|
|
disk: r.limits.disk,
|
|
|
|
io: r.limits.io,
|
|
|
|
memory: r.limits.memory,
|
|
|
|
swap: r.limits.swap,
|
|
|
|
threads: r.limits.threads,
|
2021-10-29 06:04:28 +00:00
|
|
|
oom_killer: r.limits.oomDisabled,
|
2021-01-13 16:43:57 +00:00
|
|
|
},
|
|
|
|
|
2021-10-29 06:04:28 +00:00
|
|
|
feature_limits: {
|
2021-01-13 16:43:57 +00:00
|
|
|
allocations: r.featureLimits.allocations,
|
|
|
|
backups: r.featureLimits.backups,
|
|
|
|
databases: r.featureLimits.databases,
|
|
|
|
},
|
2021-10-24 20:14:04 +00:00
|
|
|
|
|
|
|
allocation: {
|
|
|
|
default: r.allocation.default,
|
|
|
|
additional: r.allocation.additional,
|
|
|
|
},
|
|
|
|
|
|
|
|
startup: r.startup,
|
|
|
|
environment: r.environment,
|
|
|
|
egg_id: r.eggId,
|
|
|
|
image: r.image,
|
|
|
|
skip_scripts: r.skipScripts,
|
|
|
|
start_on_completion: r.startOnCompletion,
|
2021-01-15 16:41:15 +00:00
|
|
|
}, { params: { include: include.join(',') } })
|
2021-01-06 23:38:39 +00:00
|
|
|
.then(({ data }) => resolve(rawDataToServer(data)))
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|