2022-12-16 02:06:14 +00:00
|
|
|
import http from '@/api/http';
|
|
|
|
import { Server, rawDataToServer } from '@/api/admin/servers/getServers';
|
|
|
|
|
|
|
|
export interface CreateServerRequest {
|
|
|
|
externalId: string;
|
|
|
|
name: string;
|
|
|
|
description: string | null;
|
|
|
|
ownerId: number;
|
|
|
|
nodeId: number;
|
|
|
|
|
|
|
|
limits: {
|
|
|
|
memory: number;
|
|
|
|
swap: number;
|
|
|
|
disk: number;
|
|
|
|
io: number;
|
|
|
|
cpu: number;
|
|
|
|
threads: string;
|
|
|
|
oomDisabled: boolean;
|
2023-01-12 19:31:47 +00:00
|
|
|
};
|
2022-12-16 02:06:14 +00:00
|
|
|
|
|
|
|
featureLimits: {
|
|
|
|
allocations: number;
|
|
|
|
backups: number;
|
|
|
|
databases: number;
|
|
|
|
};
|
|
|
|
|
|
|
|
allocation: {
|
|
|
|
default: number;
|
|
|
|
additional: number[];
|
|
|
|
};
|
|
|
|
|
|
|
|
startup: string;
|
|
|
|
environment: Record<string, any>;
|
|
|
|
eggId: number;
|
|
|
|
image: string;
|
|
|
|
skipScripts: boolean;
|
|
|
|
startOnCompletion: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default (r: CreateServerRequest, include: string[] = []): Promise<Server> => {
|
|
|
|
return new Promise((resolve, reject) => {
|
2023-01-12 19:31:47 +00:00
|
|
|
http.post(
|
|
|
|
'/api/application/servers',
|
|
|
|
{
|
|
|
|
externalId: r.externalId,
|
|
|
|
name: r.name,
|
|
|
|
description: r.description,
|
|
|
|
owner_id: r.ownerId,
|
|
|
|
node_id: r.nodeId,
|
2022-12-16 02:06:14 +00:00
|
|
|
|
2023-01-12 19:31:47 +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,
|
|
|
|
oom_killer: r.limits.oomDisabled,
|
|
|
|
},
|
2022-12-16 02:06:14 +00:00
|
|
|
|
2023-01-12 19:31:47 +00:00
|
|
|
feature_limits: {
|
|
|
|
allocations: r.featureLimits.allocations,
|
|
|
|
backups: r.featureLimits.backups,
|
|
|
|
databases: r.featureLimits.databases,
|
|
|
|
},
|
2022-12-16 02:06:14 +00:00
|
|
|
|
2023-01-12 19:31:47 +00:00
|
|
|
allocation: {
|
|
|
|
default: r.allocation.default,
|
|
|
|
additional: r.allocation.additional,
|
|
|
|
},
|
2022-12-16 02:06:14 +00:00
|
|
|
|
2023-01-12 19:31:47 +00:00
|
|
|
startup: r.startup,
|
|
|
|
environment: r.environment,
|
|
|
|
egg_id: r.eggId,
|
|
|
|
image: r.image,
|
|
|
|
skip_scripts: r.skipScripts,
|
|
|
|
start_on_completion: r.startOnCompletion,
|
|
|
|
},
|
|
|
|
{ params: { include: include.join(',') } },
|
|
|
|
)
|
2022-12-16 02:06:14 +00:00
|
|
|
.then(({ data }) => resolve(rawDataToServer(data)))
|
|
|
|
.catch(reject);
|
|
|
|
});
|
|
|
|
};
|