proxmox-sdk 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +16 -0
- package/dist/index.js +20 -0
- package/dist/src/http-proxmox.repository.js +336 -0
- package/dist/src/proxmox.provider.js +23 -0
- package/dist/src/tools/encode-ssh-key.js +7 -0
- package/dist/src/types/clone-qemu-machine.js +2 -0
- package/dist/src/types/create-qemu-machine.js +2 -0
- package/dist/src/types/delete-qemu-machine.js +2 -0
- package/dist/src/types/download-iso-image.js +2 -0
- package/dist/src/types/index.js +26 -0
- package/dist/src/types/ip.js +2 -0
- package/dist/src/types/list-qemu-machines.js +2 -0
- package/dist/src/types/start-qemu-machine.js +2 -0
- package/dist/src/types/stop-qemu-machine.js +2 -0
- package/dist/src/types/update-qemu-machine.js +2 -0
- package/dist/src/types/upid.js +2 -0
- package/index.ts +2 -0
- package/package.json +32 -0
- package/src/http-proxmox.repository.ts +362 -0
- package/src/tools/encode-ssh-key.ts +3 -0
- package/src/types/clone-qemu-machine.ts +6 -0
- package/src/types/create-qemu-machine.ts +149 -0
- package/src/types/delete-qemu-machine.ts +26 -0
- package/src/types/download-iso-image.ts +23 -0
- package/src/types/index.ts +10 -0
- package/src/types/ip.ts +1 -0
- package/src/types/list-qemu-machines.ts +39 -0
- package/src/types/start-qemu-machine.ts +5 -0
- package/src/types/stop-qemu-machine.ts +5 -0
- package/src/types/update-qemu-machine.ts +205 -0
- package/src/types/upid.ts +1 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { Logger } from "nestjs-pino";
|
|
3
|
+
|
|
4
|
+
import { encodeSSHKey } from "./tools/encode-ssh-key";
|
|
5
|
+
import { CloneQemuMachinePayload } from "./types/clone-qemu-machine";
|
|
6
|
+
import { CreateQemuMachinePayload, CreateQemuMachineProxmoxPayload } from "./types/create-qemu-machine";
|
|
7
|
+
import { DeleteQemuMachinePayload } from "./types/delete-qemu-machine";
|
|
8
|
+
import { DownloadIsoImagePayload } from "./types/download-iso-image";
|
|
9
|
+
import { ListQemuMachinesAnswer } from "./types/list-qemu-machines";
|
|
10
|
+
import { StartQemuMachinePayload } from "./types/start-qemu-machine";
|
|
11
|
+
import { StopQemuMachinePayload } from "./types/stop-qemu-machine";
|
|
12
|
+
import { UpdateQemuMachinePayload, UpdateQemuMachineProxmoxPayload } from "./types/update-qemu-machine";
|
|
13
|
+
import { IP } from "./types/ip";
|
|
14
|
+
import { UPID } from "./types";
|
|
15
|
+
|
|
16
|
+
export type AuthConfig = {
|
|
17
|
+
host: string;
|
|
18
|
+
password: string;
|
|
19
|
+
username: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// authorize self signed cert if you do not use a valid SSL certificat
|
|
23
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
24
|
+
|
|
25
|
+
// https://pve.proxmox.com/wiki/Proxmox_VE_API#Authentication
|
|
26
|
+
export class HttpProxmoxRepository {
|
|
27
|
+
constructor (
|
|
28
|
+
private readonly parameters: AuthConfig,
|
|
29
|
+
private readonly logger: Logger,
|
|
30
|
+
) {}
|
|
31
|
+
|
|
32
|
+
async getProxmoxVersion (): Promise<string> {
|
|
33
|
+
let data;
|
|
34
|
+
try {
|
|
35
|
+
data = await axios({
|
|
36
|
+
url: this.computeUrl("/api2/json/version"),
|
|
37
|
+
headers: await this.prepareHeaders(),
|
|
38
|
+
});
|
|
39
|
+
} catch (err) {
|
|
40
|
+
console.log(err);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return (data as unknown as any).data.data.version;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async listQemuMachines (node: string): Promise<ListQemuMachinesAnswer> {
|
|
47
|
+
let data;
|
|
48
|
+
try {
|
|
49
|
+
data = await axios({
|
|
50
|
+
url: this.computeUrl(`/api2/json/nodes/${node}/qemu`),
|
|
51
|
+
headers: await this.prepareHeaders(),
|
|
52
|
+
});
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.log(err);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return (data as unknown as any).data.data;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async getQemuMachineVlanTag (node: string, vmid: number): Promise<number> {
|
|
61
|
+
let data;
|
|
62
|
+
try {
|
|
63
|
+
data = await axios({
|
|
64
|
+
url: this.computeUrl(`/api2/json/nodes/${node}/qemu/${vmid}/config`),
|
|
65
|
+
headers: await this.prepareHeaders(),
|
|
66
|
+
});
|
|
67
|
+
} catch (err) {
|
|
68
|
+
this.logger.error(err);
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const tag = data.data.data.net0.split(",").find((e: string) => e.startsWith("tag"));
|
|
73
|
+
if (tag) {
|
|
74
|
+
return parseInt(tag.split("=").at(1), 10);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return 1;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async listQemuMachineIps (node: string, vmid: number): Promise<Array<IP>> {
|
|
81
|
+
let data;
|
|
82
|
+
try {
|
|
83
|
+
data = await axios({
|
|
84
|
+
url: this.computeUrl(`/api2/json/nodes/${node}/qemu/${vmid}/agent/network-get-interfaces`),
|
|
85
|
+
headers: await this.prepareHeaders(),
|
|
86
|
+
});
|
|
87
|
+
} catch (err) {
|
|
88
|
+
this.logger.error(err);
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
type PAYLOAD = {
|
|
93
|
+
result: Array<{
|
|
94
|
+
"hardware-address": string;
|
|
95
|
+
"ip-addresses": Array<{ "ip-address": IP, "ip-address-type": "ipv4"|"ipv6", prefix: number }>,
|
|
96
|
+
name: string;
|
|
97
|
+
statistics: {
|
|
98
|
+
"rx-bytes": number,
|
|
99
|
+
"rx-dropped": number,
|
|
100
|
+
"rx-errs": number,
|
|
101
|
+
"rx-packets": number,
|
|
102
|
+
"tx-bytes": number,
|
|
103
|
+
"tx-dropped": number,
|
|
104
|
+
"tx-errs": number,
|
|
105
|
+
"tx-packets": number,
|
|
106
|
+
}
|
|
107
|
+
}>
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const payload = (data as unknown as any)?.data?.data as PAYLOAD;
|
|
111
|
+
console.log(payload);
|
|
112
|
+
const answer = payload.result
|
|
113
|
+
.map(
|
|
114
|
+
eth => eth["ip-addresses"]
|
|
115
|
+
.filter(ip => ip["ip-address-type"] === "ipv4")
|
|
116
|
+
.map(ip => ip["ip-address"]),
|
|
117
|
+
)
|
|
118
|
+
.flat()
|
|
119
|
+
.filter(ip => !["127.0.0.1"].includes(ip));
|
|
120
|
+
|
|
121
|
+
return answer;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
async createQemuMachine (payload: CreateQemuMachinePayload): Promise<string> {
|
|
125
|
+
let data;
|
|
126
|
+
|
|
127
|
+
// According to this answer https://forum.proxmox.com/threads/can-not-create-vm-with-qcow2-format.114881/post-496759
|
|
128
|
+
// when your Proxmox uses a local-lvm, the logical block storage does not support qcow2, only raw.
|
|
129
|
+
const FORMAT = payload.localStorageName === "local" ? "qcow2" : "raw";
|
|
130
|
+
|
|
131
|
+
const proxmoxPayload: CreateQemuMachineProxmoxPayload = {
|
|
132
|
+
autostart: payload.autostart,
|
|
133
|
+
bios: payload.bios,
|
|
134
|
+
cores: payload.coreCount,
|
|
135
|
+
efidisk0: `${payload.localStorageName}:1,efitype=4m,pre-enrolled-keys=1,format=${FORMAT}`,
|
|
136
|
+
memory: payload.memory,
|
|
137
|
+
name: payload.name,
|
|
138
|
+
net0: "virtio,bridge=vmbr0,firewall=1,vlanid=10",
|
|
139
|
+
node: payload.node,
|
|
140
|
+
numa: 0,
|
|
141
|
+
ostype: payload.ostype,
|
|
142
|
+
scsi0: `${payload.localStorageName}:32,format=${FORMAT},iothread=on`,
|
|
143
|
+
scsihw: "virtio-scsi-single",
|
|
144
|
+
sockets: 1,
|
|
145
|
+
vmid: payload.vmid,
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
if (payload.isoName) {
|
|
149
|
+
proxmoxPayload.scsi2 = `${payload.localStorageName}:iso/${payload.isoName},media=cdrom`;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
data = await axios({
|
|
154
|
+
data: proxmoxPayload,
|
|
155
|
+
headers: await this.prepareHeaders(),
|
|
156
|
+
method: "POST",
|
|
157
|
+
url: this.computeUrl(`/api2/json/nodes/${payload.node}/qemu`),
|
|
158
|
+
});
|
|
159
|
+
} catch (err) {
|
|
160
|
+
this.logger.error({ status: (err as unknown as any).response.status, vmid: payload.vmid, errors: (err as unknown as any).response.data.errors }, (err as unknown as any).response.statusText);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return (data as unknown as any)?.data?.data as string;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async updateQemuMachine (payload: UpdateQemuMachinePayload): Promise<string> {
|
|
167
|
+
let data;
|
|
168
|
+
|
|
169
|
+
// @ts-ignore
|
|
170
|
+
const proxmoxPayload: UpdateQemuMachineProxmoxPayload = {
|
|
171
|
+
cores: payload.coreCount,
|
|
172
|
+
memory: payload.memory,
|
|
173
|
+
name: payload.name,
|
|
174
|
+
tags: payload.tags,
|
|
175
|
+
ipconfig0: "ip=dhcp",
|
|
176
|
+
// ide2: `local:${payload.vmid}/vm-${payload.vmid}-cloudinit.qcow2,media=cdrom`,
|
|
177
|
+
// overridenUsername: "toto",
|
|
178
|
+
// overridenPassword: "toto",
|
|
179
|
+
ciuser: payload.overridenUser,
|
|
180
|
+
cipassword: payload.overridenPassword,
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
if (payload.sshkey) {
|
|
184
|
+
proxmoxPayload.sshkeys = encodeSSHKey(payload.sshkey);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (payload.networks?.[0]) {
|
|
188
|
+
proxmoxPayload.net0 = `model=${payload.networks[0].model},bridge=${payload.networks[0].bridge},firewall=${payload.networks[0].firewall}`;
|
|
189
|
+
if (payload.networks[0].tag) {
|
|
190
|
+
proxmoxPayload.net0 += `,tag=${payload.networks[0].tag}`;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
try {
|
|
195
|
+
data = await axios({
|
|
196
|
+
data: proxmoxPayload,
|
|
197
|
+
headers: await this.prepareHeaders(),
|
|
198
|
+
method: "PUT",
|
|
199
|
+
url: this.computeUrl(`/api2/json/nodes/${payload.node}/qemu/${payload.vmid}/config`),
|
|
200
|
+
});
|
|
201
|
+
} catch (err) {
|
|
202
|
+
this.logger.error({ status: (err as unknown as any).response.status, vmid: payload.vmid, errors: (err as unknown as any).response.data.errors }, (err as unknown as any).response.statusText);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return (data as unknown as any)?.data?.data as string;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
async deleteQemuMachine (port: DeleteQemuMachinePayload): Promise<UPID> {
|
|
209
|
+
let data;
|
|
210
|
+
try {
|
|
211
|
+
data = await axios({
|
|
212
|
+
headers: await this.prepareHeaders(),
|
|
213
|
+
method: "DELETE",
|
|
214
|
+
url: this.computeUrl(`/api2/json/nodes/${port.node}/qemu/${port.vmid}`),
|
|
215
|
+
});
|
|
216
|
+
} catch (err) {
|
|
217
|
+
this.logger.error({ status: (err as unknown as any).response.status, vmid: port.vmid, errors: (err as unknown as any).response.data.errors }, (err as unknown as any).response.statusText);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const payload = (data as unknown as any)?.data?.data as UPID;
|
|
221
|
+
|
|
222
|
+
return payload;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async downloadISOImage (payload: DownloadIsoImagePayload): Promise<string> {
|
|
226
|
+
const params = new URLSearchParams({
|
|
227
|
+
url: payload.url,
|
|
228
|
+
content: payload.content,
|
|
229
|
+
filename: payload.filename,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
let data;
|
|
233
|
+
try {
|
|
234
|
+
data = await axios({
|
|
235
|
+
headers: await this.prepareHeaders(),
|
|
236
|
+
method: "POST",
|
|
237
|
+
url: this.computeUrl(`/api2/json/nodes/${payload.node}/storage/${payload.storage}/download-url?${params.toString()}`),
|
|
238
|
+
});
|
|
239
|
+
} catch (err) {
|
|
240
|
+
this.logger.error({ status: (err as unknown as any).response.status, ...payload, errors: (err as unknown as any).response.data.errors }, (err as unknown as any).response.statusText);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return (data as unknown as any)?.data?.data as string;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async startQemuMachine (payload: StartQemuMachinePayload) {
|
|
247
|
+
let data;
|
|
248
|
+
try {
|
|
249
|
+
data = await axios({
|
|
250
|
+
method: "POST",
|
|
251
|
+
url: this.computeUrl(`/api2/json/nodes/${payload.node}/qemu/${payload.vmid}/status/start`),
|
|
252
|
+
headers: await this.prepareHeaders(),
|
|
253
|
+
});
|
|
254
|
+
} catch (err) {
|
|
255
|
+
this.logger.error({ status: (err as unknown as any).response.status, ...payload, errors: (err as unknown as any).response.data.errors }, (err as unknown as any).response.statusText);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return (data as unknown as any)?.data?.data as string;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async stopQemuMachine (payload: StopQemuMachinePayload) {
|
|
262
|
+
let data;
|
|
263
|
+
try {
|
|
264
|
+
data = await axios({
|
|
265
|
+
method: "POST",
|
|
266
|
+
url: this.computeUrl(`/api2/json/nodes/${payload.node}/qemu/${payload.vmid}/status/stop`),
|
|
267
|
+
headers: await this.prepareHeaders(),
|
|
268
|
+
});
|
|
269
|
+
} catch (err) {
|
|
270
|
+
this.logger.error({ status: (err as unknown as any).response.status, ...payload, errors: (err as unknown as any).response.data.errors }, (err as unknown as any).response.statusText);
|
|
271
|
+
}
|
|
272
|
+
return (data as unknown as any)?.data?.data as string;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
async cloneQemuMarchine (payload: CloneQemuMachinePayload) {
|
|
276
|
+
let data;
|
|
277
|
+
try {
|
|
278
|
+
data = await axios({
|
|
279
|
+
method: "POST",
|
|
280
|
+
url: this.computeUrl(`/api2/json/nodes/${payload.node}/qemu/${payload.vmid}/clone`),
|
|
281
|
+
headers: {
|
|
282
|
+
...await this.prepareHeaders(),
|
|
283
|
+
},
|
|
284
|
+
data: {
|
|
285
|
+
full: 1,
|
|
286
|
+
name: "azdzfaef2233",
|
|
287
|
+
newid: payload.newid,
|
|
288
|
+
target: payload.node,
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
} catch (err) {
|
|
292
|
+
this.logger.error({ status: (err as unknown as any).response.status, ...payload, errors: (err as unknown as any).response.data.errors }, (err as unknown as any).response.statusText);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return (data as unknown as any)?.data?.data as string;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async resizeDisk (
|
|
299
|
+
payload: { node: string; vmid: number, size: number, disk: string, unit: "G" }
|
|
300
|
+
) {
|
|
301
|
+
let data;
|
|
302
|
+
try {
|
|
303
|
+
data = await axios({
|
|
304
|
+
method: "PUT",
|
|
305
|
+
url: this.computeUrl(`/api2/json/nodes/${payload.node}/qemu/${payload.vmid}/resize`),
|
|
306
|
+
headers: await this.prepareHeaders(),
|
|
307
|
+
data: {
|
|
308
|
+
disk: payload.disk,
|
|
309
|
+
size: `+${payload.size}G`
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
} catch (err) {
|
|
313
|
+
this.logger.error({ status: (err as unknown as any).response.status, ...payload, errors: (err as unknown as any).response.data.errors }, (err as unknown as any).response.statusText);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return (data as unknown as any)?.data?.data as string;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
private computeUrl (path: string) {
|
|
320
|
+
return `${this.parameters.host}${path}`;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private async prepareHeaders () {
|
|
324
|
+
const ticket = await this.getTicket();
|
|
325
|
+
return {
|
|
326
|
+
CSRFPreventionToken: ticket.CSRFPreventionToken,
|
|
327
|
+
Cookie: `PVEAuthCookie=${ticket.ticket}`,
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
private async getTicket (): Promise<{
|
|
332
|
+
CSRFPreventionToken: string;
|
|
333
|
+
cap: {
|
|
334
|
+
dc: any;
|
|
335
|
+
nodes: any;
|
|
336
|
+
},
|
|
337
|
+
ticket: string;
|
|
338
|
+
username: string;
|
|
339
|
+
}> {
|
|
340
|
+
const params = new URLSearchParams({
|
|
341
|
+
username: this.parameters.username,
|
|
342
|
+
password: this.parameters.password,
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
let data;
|
|
346
|
+
try {
|
|
347
|
+
const url = this.computeUrl(`/api2/json/access/ticket?${params.toString()}`);
|
|
348
|
+
({ data } = await axios({
|
|
349
|
+
url,
|
|
350
|
+
method: "POST",
|
|
351
|
+
headers: {
|
|
352
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
353
|
+
},
|
|
354
|
+
}));
|
|
355
|
+
} catch (err) {
|
|
356
|
+
console.log((err as unknown as any).response.status);
|
|
357
|
+
console.log((err as unknown as any).response.statusText);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return (data as unknown as any).data;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/qemu
|
|
2
|
+
type CreateQemuMachineBasePayload = {
|
|
3
|
+
/**
|
|
4
|
+
* Automatic restart after crash (currently ignored).
|
|
5
|
+
*/
|
|
6
|
+
autostart?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Select BIOS implementation.
|
|
9
|
+
*
|
|
10
|
+
* default = seabios.
|
|
11
|
+
*/
|
|
12
|
+
bios?: "seabios" | "ovmf";
|
|
13
|
+
/**
|
|
14
|
+
* Memory quantity.
|
|
15
|
+
*
|
|
16
|
+
* default = 512(MB)
|
|
17
|
+
*/
|
|
18
|
+
memory?: number;
|
|
19
|
+
/**
|
|
20
|
+
* The name of the VM.
|
|
21
|
+
*/
|
|
22
|
+
name: string;
|
|
23
|
+
/**
|
|
24
|
+
* The cluster node name.
|
|
25
|
+
*/
|
|
26
|
+
node: string;
|
|
27
|
+
/**
|
|
28
|
+
* Specify guest operating system. This is used to enable special
|
|
29
|
+
* optimization/features for specific operating systems:
|
|
30
|
+
*
|
|
31
|
+
* - l24: Linux 2.4 Kernel
|
|
32
|
+
* - l26: Linux 2.6 - 6.X Kernel
|
|
33
|
+
* - other: unspecified OS
|
|
34
|
+
* - solaris: Solaris/OpenSolaris/OpenIndiania kernel
|
|
35
|
+
* - w2k3: Microsoft Windows 2003
|
|
36
|
+
* - w2k8: Microsoft Windows 2008
|
|
37
|
+
* - w2k: Microsoft Windows 2000
|
|
38
|
+
* - win10: Microsoft Windows 10/2016/2019
|
|
39
|
+
* - win11: Microsoft Windows 11/2022
|
|
40
|
+
* - win7: Microsoft Windows 7
|
|
41
|
+
* - win8: Microsoft Windows 8/2012/2012r2
|
|
42
|
+
* - wvista: Microsoft Windows Vista
|
|
43
|
+
* - wxp: Microsoft Windows XP
|
|
44
|
+
*/
|
|
45
|
+
ostype?: OS;
|
|
46
|
+
/**
|
|
47
|
+
* The (unique) ID of the VM.
|
|
48
|
+
* It should be between 100 and 999999999.
|
|
49
|
+
*/
|
|
50
|
+
vmid: number;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type CreateQemuMachinePayload = CreateQemuMachineBasePayload & {
|
|
54
|
+
/**
|
|
55
|
+
* The number of cores per socket.
|
|
56
|
+
*
|
|
57
|
+
* default = 1
|
|
58
|
+
*/
|
|
59
|
+
coreCount?: number;
|
|
60
|
+
/**
|
|
61
|
+
* ISO name
|
|
62
|
+
*
|
|
63
|
+
* The name of the filename you gave to the ISO.
|
|
64
|
+
* (e.g: debian.iso)
|
|
65
|
+
*/
|
|
66
|
+
isoName?: string;
|
|
67
|
+
/**
|
|
68
|
+
* Specify the name of the storage, according to the Proxmox installation
|
|
69
|
+
* it can be different
|
|
70
|
+
*
|
|
71
|
+
* It's the storage where you have a section "VM Disks"
|
|
72
|
+
*/
|
|
73
|
+
localStorageName: "local" | "local-lvm";
|
|
74
|
+
/**
|
|
75
|
+
* Networks configurations
|
|
76
|
+
*/
|
|
77
|
+
networks?: Array<QemuNetwork>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export type CreateQemuMachineProxmoxPayload = CreateQemuMachineBasePayload & {
|
|
81
|
+
/**
|
|
82
|
+
* The number of cores per socket.
|
|
83
|
+
*
|
|
84
|
+
* default = 1
|
|
85
|
+
*/
|
|
86
|
+
cores?: number;
|
|
87
|
+
efidisk0: string;
|
|
88
|
+
/**
|
|
89
|
+
* cloud-init: Specify IP addresses and gateways for the corresponding interface.
|
|
90
|
+
*
|
|
91
|
+
* IP addresses use CIDR notation, gateways are optional but need an IP of the same type specified.
|
|
92
|
+
* The special string 'dhcp' can be used for IP addresses to use DHCP, in which case no explicit
|
|
93
|
+
* gateway should be provided.
|
|
94
|
+
*
|
|
95
|
+
* For IPv6 the special string 'auto' can be used to use stateless autoconfiguration. This requires
|
|
96
|
+
* cloud-init 19.4 or newer.
|
|
97
|
+
*
|
|
98
|
+
* If cloud-init is enabled and neither an IPv4 nor an IPv6 address is specified, it defaults to using
|
|
99
|
+
* dhcp on IPv4.
|
|
100
|
+
*
|
|
101
|
+
* [gw=<GatewayIPv4>] [,gw6=<GatewayIPv6>] [,ip=<IPv4Format/CIDR>] [,ip6=<IPv6Format/CIDR>]
|
|
102
|
+
*/
|
|
103
|
+
ipconfig0?: string;
|
|
104
|
+
/**
|
|
105
|
+
* cloud-init: Specify IP addresses and gateways for the corresponding interface.
|
|
106
|
+
*
|
|
107
|
+
* IP addresses use CIDR notation, gateways are optional but need an IP of the same type specified.
|
|
108
|
+
* The special string 'dhcp' can be used for IP addresses to use DHCP, in which case no explicit
|
|
109
|
+
* gateway should be provided.
|
|
110
|
+
*
|
|
111
|
+
* For IPv6 the special string 'auto' can be used to use stateless autoconfiguration. This requires
|
|
112
|
+
* cloud-init 19.4 or newer.
|
|
113
|
+
*
|
|
114
|
+
* If cloud-init is enabled and neither an IPv4 nor an IPv6 address is specified, it defaults to using
|
|
115
|
+
* dhcp on IPv4.
|
|
116
|
+
*
|
|
117
|
+
* [gw=<GatewayIPv4>] [,gw6=<GatewayIPv6>] [,ip=<IPv4Format/CIDR>] [,ip6=<IPv6Format/CIDR>]
|
|
118
|
+
*/
|
|
119
|
+
ipconfig1?: string;
|
|
120
|
+
net0: string;
|
|
121
|
+
numa: number;
|
|
122
|
+
/**
|
|
123
|
+
* scsi[n]
|
|
124
|
+
* Use volume as SCSI hard disk or CD-ROM (n is 0 to 30).
|
|
125
|
+
* Use the special syntax STORAGE_ID:SIZE_IN_GiB to allocate a new volume.
|
|
126
|
+
* Use STORAGE_ID:0 and the 'import-from' parameter to import
|
|
127
|
+
* from an existing volume.
|
|
128
|
+
*/
|
|
129
|
+
scsi0?: string;
|
|
130
|
+
/**
|
|
131
|
+
* scsi[n]
|
|
132
|
+
* Use volume as SCSI hard disk or CD-ROM (n is 0 to 30).
|
|
133
|
+
* Use the special syntax STORAGE_ID:SIZE_IN_GiB to allocate a new volume.
|
|
134
|
+
* Use STORAGE_ID:0 and the 'import-from' parameter to import
|
|
135
|
+
* from an existing volume.
|
|
136
|
+
*/
|
|
137
|
+
scsi2?: string;
|
|
138
|
+
scsihw?: "virtio-scsi-single";
|
|
139
|
+
|
|
140
|
+
sockets: number;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export type OS = "other" | "wxp" | "w2k" | "w2k3" | "w2k8" | "wvista" | "win7" | "win8" | "win10" | "win11" | "l24" | "l26" | "solaris";
|
|
144
|
+
|
|
145
|
+
export type QemuNetwork = {
|
|
146
|
+
bridge: "vmbr0";
|
|
147
|
+
firewall: boolean;
|
|
148
|
+
model: "virtio";
|
|
149
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/qemu/{vmid}
|
|
2
|
+
export type DeleteQemuMachinePayload = {
|
|
3
|
+
/**
|
|
4
|
+
* If set, destroy additionally all disks not referenced in the config but with a matching VMID from all enabled storages.
|
|
5
|
+
*
|
|
6
|
+
* default = false
|
|
7
|
+
*/
|
|
8
|
+
"destroy-unreferenced-disks"?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The cluster node name.
|
|
11
|
+
*/
|
|
12
|
+
node: string;
|
|
13
|
+
/**
|
|
14
|
+
* Remove VMID from configurations, like backup & replication jobs and HA.
|
|
15
|
+
*/
|
|
16
|
+
purge?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* ignore locks - only root is allowed to use this option.
|
|
19
|
+
*/
|
|
20
|
+
skiplock?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* The (unique) ID of the VM.
|
|
23
|
+
* It should be between 100 and 999999999.
|
|
24
|
+
*/
|
|
25
|
+
vmid: number;
|
|
26
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/storage/{storage}/download-url
|
|
2
|
+
export type DownloadIsoImagePayload = {
|
|
3
|
+
/**
|
|
4
|
+
* Content type.
|
|
5
|
+
*/
|
|
6
|
+
content: "iso" | "vztmpl";
|
|
7
|
+
/**
|
|
8
|
+
* The name of the file to create. Caution: This will be normalized!
|
|
9
|
+
*/
|
|
10
|
+
filename: string;
|
|
11
|
+
/**
|
|
12
|
+
* The cluster node name.
|
|
13
|
+
*/
|
|
14
|
+
node: string;
|
|
15
|
+
/**
|
|
16
|
+
* The storage identifier.
|
|
17
|
+
*/
|
|
18
|
+
storage: string;
|
|
19
|
+
/**
|
|
20
|
+
* The URL to download the file from.
|
|
21
|
+
*/
|
|
22
|
+
url: string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './clone-qemu-machine';
|
|
2
|
+
export * from './create-qemu-machine';
|
|
3
|
+
export * from './delete-qemu-machine';
|
|
4
|
+
export * from './download-iso-image';
|
|
5
|
+
export * from './index';
|
|
6
|
+
export * from './ip';
|
|
7
|
+
export * from './list-qemu-machines';
|
|
8
|
+
export * from './start-qemu-machine';
|
|
9
|
+
export * from './stop-qemu-machine';
|
|
10
|
+
export * from './upid';
|
package/src/types/ip.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type IP = string & { readonly "": unique symbol };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/qemu/{vmid}
|
|
2
|
+
export type ListQemuMachinesPayload = {
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export type QemuMachine = {
|
|
6
|
+
/**
|
|
7
|
+
* Maximum usable CPUs.
|
|
8
|
+
*/
|
|
9
|
+
cpus: number;
|
|
10
|
+
/**
|
|
11
|
+
* Root disk size in bytes.
|
|
12
|
+
*/
|
|
13
|
+
maxdisk: number;
|
|
14
|
+
/**
|
|
15
|
+
* Maximum memory in bytes.
|
|
16
|
+
*/
|
|
17
|
+
maxmem: number;
|
|
18
|
+
name: string;
|
|
19
|
+
/**
|
|
20
|
+
* Current state of the VM.
|
|
21
|
+
*
|
|
22
|
+
* QEMU process status.
|
|
23
|
+
*/
|
|
24
|
+
status: "running" | "stopped";
|
|
25
|
+
/**
|
|
26
|
+
* The current configured tags, if any
|
|
27
|
+
* Splitted by ;
|
|
28
|
+
*/
|
|
29
|
+
tags: string;
|
|
30
|
+
/**
|
|
31
|
+
* Uptime duration in second.
|
|
32
|
+
*/
|
|
33
|
+
uptime: string;
|
|
34
|
+
/**
|
|
35
|
+
* The (unique) ID of the VM.
|
|
36
|
+
*/
|
|
37
|
+
vmid: number;
|
|
38
|
+
}
|
|
39
|
+
export type ListQemuMachinesAnswer = Array<QemuMachine>;
|