@virtbase/proxmox-api 2.0.0

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.
@@ -0,0 +1,96 @@
1
+ import type { Proxmox } from "./model.js";
2
+ export declare const VALID_QEMU_INFO_SIMPLE: readonly ["backup", "balloon", "block-jobs", "blockstats", "capture", "chardev", "cpus", "cpustats", "dump", "history", "hotpluggable-cpus", "ioapic", "iothreads", "irq", "jit", "kvm", "memdev", "memory-devices", "memory_size_summary", "mice", "migrate", "migrate_cache_size", "migrate_capabilities", "migrate_parameters", "name", "network", "numa", "opcount", "pci", "pic", "profile", "qdm", "qtree", "ramblock", "rdma", "roms", "savevm", "sev", "snapshots", "spice", "status", "tpm", "usb", "usbhost", "usernet", "uuid", "version", "vm-generation-id", "vnc"];
3
+ export declare const VALID_QEMU_INFO_OPTION: readonly ["block", "lapic", "mtree", "qom-tree", "registers", "sync-profile", "trace-events"];
4
+ export declare const VALID_QEMU_INFO_PARAM: readonly ["rocker-of-dpa-flows", "rocker-of-dpa-groups", "rocker-ports"];
5
+ export type QemuInfoSimple = (typeof VALID_QEMU_INFO_SIMPLE)[number];
6
+ export type QemuInfoOption = (typeof VALID_QEMU_INFO_OPTION)[number];
7
+ export type QemuInfoParam = (typeof VALID_QEMU_INFO_PARAM)[number];
8
+ /** One USB device attached to the guest, from `info usb`. */
9
+ export interface USBInfo {
10
+ device: string;
11
+ port: string;
12
+ speed: string;
13
+ /**
14
+ * Absent for a device QEMU reports without a product string - the trailing
15
+ * `, Product ..., ID: ...` is optional in the monitor's own output.
16
+ */
17
+ product?: string;
18
+ /** Absent for the same reason as {@link USBInfo.product}. */
19
+ id?: string;
20
+ }
21
+ /** One USB device present on the host, from `info usbhost`. */
22
+ export interface USBHostInfo {
23
+ bus: number;
24
+ addr: number;
25
+ port: string;
26
+ speed: string;
27
+ class: string;
28
+ vendorId: string;
29
+ productId: string;
30
+ name: string;
31
+ }
32
+ /** Narrows which host devices {@link QmMonitor.infoUsbhost} returns. */
33
+ export interface USBHostFilter {
34
+ vendorId?: RegExp;
35
+ productId?: RegExp;
36
+ name?: RegExp;
37
+ }
38
+ /**
39
+ * QEMU monitor access for one guest, over
40
+ * `POST /nodes/{node}/qemu/{vmid}/monitor`.
41
+ *
42
+ * The monitor is a debugging interface: commands are passed through
43
+ * unvalidated and replies are unstructured text whose format is not stable
44
+ * across QEMU versions. Prefer a real endpoint wherever one exists.
45
+ */
46
+ export declare class QmMonitor {
47
+ readonly node: string;
48
+ readonly vmid: number;
49
+ /** Send a raw monitor command and return its unparsed reply. */
50
+ readonly monitor: (command: string) => Promise<string>;
51
+ constructor(proxmox: Proxmox.Api, node: string, vmid: number);
52
+ info(type: QemuInfoSimple): Promise<string>;
53
+ info(type: QemuInfoOption, ...args: string[]): Promise<string>;
54
+ info(type: QemuInfoParam, arg1: string, ...args: string[]): Promise<string>;
55
+ /**
56
+ * USB devices currently attached to the guest.
57
+ *
58
+ * @throws if the reply has lines the device pattern did not match, which
59
+ * means QEMU changed the format and the result would be silently short.
60
+ */
61
+ infoUsb(): Promise<USBInfo[]>;
62
+ /**
63
+ * USB devices present on the host, optionally narrowed by
64
+ * vendor id, product id or name.
65
+ */
66
+ infoUsbhost(filter?: USBHostFilter): Promise<USBHostInfo[]>;
67
+ /**
68
+ * Attach a host USB device by vendor and product id.
69
+ *
70
+ * @param id Identifier for the new device, used to detach it later.
71
+ */
72
+ deviceAddById(id: string, params: {
73
+ vendorId: string;
74
+ productId: string;
75
+ }): Promise<string>;
76
+ /**
77
+ * Attach a host USB device by physical port, which survives swapping a
78
+ * device for another of the same model.
79
+ */
80
+ deviceAddByPort(id: string, params: {
81
+ bus: number;
82
+ port: string;
83
+ }): Promise<string>;
84
+ /** Detach a device previously added under `id`. */
85
+ deviceDel(id: string): Promise<string>;
86
+ /**
87
+ * Attach every host device matching `filter` that is not already present.
88
+ *
89
+ * The first is added as `id`, subsequent ones as `id-1`, `id-2` and so on.
90
+ *
91
+ * @returns the ids that were attached.
92
+ * @throws if `id` is already attached to the guest.
93
+ */
94
+ deviceAddMissing(id: string, filter: USBHostFilter): Promise<string[]>;
95
+ }
96
+ //# sourceMappingURL=qm-monitor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qm-monitor.d.ts","sourceRoot":"","sources":["../src/qm-monitor.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAK1C,eAAO,MAAM,sBAAsB,YACjC,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,SAAS,EACT,MAAM,EACN,UAAU,EACV,MAAM,EACN,SAAS,EACT,mBAAmB,EACnB,QAAQ,EACR,WAAW,EACX,KAAK,EACL,KAAK,EACL,KAAK,EACL,QAAQ,EACR,gBAAgB,EAChB,qBAAqB,EACrB,MAAM,EACN,SAAS,EACT,oBAAoB,EACpB,sBAAsB,EACtB,oBAAoB,EACpB,MAAM,EACN,SAAS,EACT,MAAM,EACN,SAAS,EACT,KAAK,EACL,KAAK,EACL,SAAS,EACT,KAAK,EACL,OAAO,EACP,UAAU,EACV,MAAM,EACN,MAAM,EACN,QAAQ,EACR,KAAK,EACL,WAAW,EACX,OAAO,EACP,QAAQ,EACR,KAAK,EACL,KAAK,EACL,SAAS,EACT,SAAS,EACT,MAAM,EACN,SAAS,EACT,kBAAkB,EAClB,KAAK,CACG,CAAC;AAEX,eAAO,MAAM,sBAAsB,YACjC,OAAO,EACP,OAAO,EACP,OAAO,EACP,UAAU,EACV,WAAW,EACX,cAAc,EACd,cAAc,CACN,CAAC;AAEX,eAAO,MAAM,qBAAqB,YAChC,qBAAqB,EACrB,sBAAsB,EACtB,cAAc,CACN,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AACrE,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAA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AAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/D,IAAI,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAU5E;;;;;OAKG;IACG,OAAO,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC,CAiBlC;IAED;;;OAGG;IACG,WAAW,CAAC,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAqChE;IAED;;;;OAIG;IACG,aAAa,CACjB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAC9C,OAAO,CAAC,MAAM,CAAC,CAMjB;IAED;;;OAGG;IACG,eAAe,CACnB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GACpC,OAAO,CAAC,MAAM,CAAC,CAIjB;IAED,mDAAmD;IAC7C,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAE3C;IAED;;;;;;;OAOG;IACG,gBAAgB,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAiB3E;CACF"}
@@ -0,0 +1,212 @@
1
+ // Proxmox-API Interactive proxmox API for developpers how do not like reading docs
2
+ // Copyright (C) 2020-2022 Chemouni Uriel <uchemouni@gmail.com>
3
+ //
4
+ // This program is free software: you can redistribute it and/or modify
5
+ // it under the terms of the GNU General Public License as published by
6
+ // the Free Software Foundation, either version 3 of the License, or
7
+ // (at your option) any later version.
8
+ //
9
+ // This program is distributed in the hope that it will be useful,
10
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ // GNU General Public License for more details.
13
+ //
14
+ // You should have received a copy of the GNU General Public License
15
+ // along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ // 'mem', // ERROR: VM XXX qmp command 'human-monitor-command' failed - got timeout
17
+ // 'tlb', // ERROR: VM XXX qmp command 'human-monitor-command' failed - got timeout
18
+ export const VALID_QEMU_INFO_SIMPLE = [
19
+ "backup",
20
+ "balloon",
21
+ "block-jobs",
22
+ "blockstats",
23
+ "capture",
24
+ "chardev",
25
+ "cpus",
26
+ "cpustats",
27
+ "dump",
28
+ "history",
29
+ "hotpluggable-cpus",
30
+ "ioapic",
31
+ "iothreads",
32
+ "irq",
33
+ "jit",
34
+ "kvm",
35
+ "memdev",
36
+ "memory-devices",
37
+ "memory_size_summary",
38
+ "mice",
39
+ "migrate",
40
+ "migrate_cache_size",
41
+ "migrate_capabilities",
42
+ "migrate_parameters",
43
+ "name",
44
+ "network",
45
+ "numa",
46
+ "opcount",
47
+ "pci",
48
+ "pic",
49
+ "profile",
50
+ "qdm",
51
+ "qtree",
52
+ "ramblock",
53
+ "rdma",
54
+ "roms",
55
+ "savevm",
56
+ "sev",
57
+ "snapshots",
58
+ "spice",
59
+ "status",
60
+ "tpm",
61
+ "usb",
62
+ "usbhost",
63
+ "usernet",
64
+ "uuid",
65
+ "version",
66
+ "vm-generation-id",
67
+ "vnc",
68
+ ];
69
+ export const VALID_QEMU_INFO_OPTION = [
70
+ "block",
71
+ "lapic",
72
+ "mtree",
73
+ "qom-tree",
74
+ "registers",
75
+ "sync-profile",
76
+ "trace-events",
77
+ ];
78
+ export const VALID_QEMU_INFO_PARAM = [
79
+ "rocker-of-dpa-flows",
80
+ "rocker-of-dpa-groups",
81
+ "rocker-ports",
82
+ ];
83
+ // Device 1.1, Port 1, Speed 1.5 Mb/s, Product USB OPTICAL MOUSE , ID: mouse
84
+ // Device 1.0, Port 2, Speed 12 Mb/s, Product Gaming KB , ID: keyboard
85
+ const GUEST_USB = /Device ([\d.]+), Port ([\d.]+), Speed ([\d KMGTbfs/.]+)(?:, Product (.+), ID: (.+))?/g;
86
+ // Bus 1, Addr 4, Port 2, Speed 480 Mb/s
87
+ // Class 00: USB device 1234:5678, Some Device
88
+ const HOST_USB = /Bus (\d+), Addr (\d+), Port ([\d.]+), Speed ([\d KMGTbfs/.]+)[\r\n]\s+Class (\d+): USB device ([0-9a-f]{4}):([0-9a-f]{4}), (.*)/gm;
89
+ /** Strip an optional `0x` prefix from a USB vendor or product id. */
90
+ function bareHexId(value) {
91
+ return value.replace(/^0x/i, "");
92
+ }
93
+ /**
94
+ * QEMU monitor access for one guest, over
95
+ * `POST /nodes/{node}/qemu/{vmid}/monitor`.
96
+ *
97
+ * The monitor is a debugging interface: commands are passed through
98
+ * unvalidated and replies are unstructured text whose format is not stable
99
+ * across QEMU versions. Prefer a real endpoint wherever one exists.
100
+ */
101
+ export class QmMonitor {
102
+ node;
103
+ vmid;
104
+ /** Send a raw monitor command and return its unparsed reply. */
105
+ monitor;
106
+ constructor(proxmox, node, vmid) {
107
+ this.node = node;
108
+ this.vmid = vmid;
109
+ const post = proxmox.nodes.$(node).qemu.$(vmid).monitor.$post;
110
+ this.monitor = (command) => post({ command });
111
+ }
112
+ /** Run `info <type>` and return the raw reply. */
113
+ async info(type, ...args) {
114
+ const suffix = args.length > 0 ? ` ${args.join(" ")}` : "";
115
+ return this.monitor(`info ${type}${suffix}`);
116
+ }
117
+ /**
118
+ * USB devices currently attached to the guest.
119
+ *
120
+ * @throws if the reply has lines the device pattern did not match, which
121
+ * means QEMU changed the format and the result would be silently short.
122
+ */
123
+ async infoUsb() {
124
+ const text = await this.info("usb");
125
+ const expected = (text.match(/[\r\n]+/g) ?? []).length;
126
+ const devices = [];
127
+ for (const match of text.matchAll(GUEST_USB)) {
128
+ const [, device = "", port = "", speed = "", product, id] = match;
129
+ devices.push({ device, port, speed, product, id });
130
+ }
131
+ if (devices.length !== expected) {
132
+ throw new Error(`Parsed ${devices.length} USB devices but the reply has ${expected} lines. ` +
133
+ `The monitor output format may have changed:\n${text}`);
134
+ }
135
+ return devices;
136
+ }
137
+ /**
138
+ * USB devices present on the host, optionally narrowed by
139
+ * vendor id, product id or name.
140
+ */
141
+ async infoUsbhost(filter) {
142
+ const text = await this.info("usbhost");
143
+ const devices = [];
144
+ for (const match of text.matchAll(HOST_USB)) {
145
+ const [, bus = "", addr = "", port = "", speed = "", deviceClass = "", vendorId = "", productId = "", name = "",] = match;
146
+ devices.push({
147
+ bus: Number(bus),
148
+ addr: Number(addr),
149
+ port,
150
+ speed,
151
+ class: deviceClass,
152
+ vendorId,
153
+ productId,
154
+ name,
155
+ });
156
+ }
157
+ if (!filter)
158
+ return devices;
159
+ return devices.filter((usb) => (!filter.name || filter.name.test(usb.name)) &&
160
+ // Each of these tested `usb.name` before, so filtering by vendor or
161
+ // product id matched on the wrong field entirely.
162
+ (!filter.vendorId || filter.vendorId.test(usb.vendorId)) &&
163
+ (!filter.productId || filter.productId.test(usb.productId)));
164
+ }
165
+ /**
166
+ * Attach a host USB device by vendor and product id.
167
+ *
168
+ * @param id Identifier for the new device, used to detach it later.
169
+ */
170
+ async deviceAddById(id, params) {
171
+ const vendorId = bareHexId(params.vendorId);
172
+ const productId = bareHexId(params.productId);
173
+ return this.monitor(`device_add usb-host,vendorid=0x${vendorId},productid=0x${productId},id=${id}`);
174
+ }
175
+ /**
176
+ * Attach a host USB device by physical port, which survives swapping a
177
+ * device for another of the same model.
178
+ */
179
+ async deviceAddByPort(id, params) {
180
+ return this.monitor(`device_add usb-host,hostbus=${params.bus},hostport=${params.port},id=${id}`);
181
+ }
182
+ /** Detach a device previously added under `id`. */
183
+ async deviceDel(id) {
184
+ return this.monitor(`device_del ${id}`);
185
+ }
186
+ /**
187
+ * Attach every host device matching `filter` that is not already present.
188
+ *
189
+ * The first is added as `id`, subsequent ones as `id-1`, `id-2` and so on.
190
+ *
191
+ * @returns the ids that were attached.
192
+ * @throws if `id` is already attached to the guest.
193
+ */
194
+ async deviceAddMissing(id, filter) {
195
+ const attached = await this.infoUsb();
196
+ if (attached.some((device) => device.id === id)) {
197
+ throw new Error(`USB device ${id} already present`);
198
+ }
199
+ const candidates = await this.infoUsbhost(filter);
200
+ const added = [];
201
+ // Sequential, not concurrent: these were previously fired without being
202
+ // awaited at all, so failures vanished and the guest saw an unbounded
203
+ // burst of monitor commands.
204
+ for (const [index, device] of candidates.entries()) {
205
+ const deviceId = index ? `${id}-${index}` : id;
206
+ await this.deviceAddByPort(deviceId, device);
207
+ added.push(deviceId);
208
+ }
209
+ return added;
210
+ }
211
+ }
212
+ //# sourceMappingURL=qm-monitor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qm-monitor.js","sourceRoot":"","sources":["../src/qm-monitor.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,gEAAgE;AAChE,EAAE;AACF,uEAAuE;AACvE,uEAAuE;AACvE,oEAAoE;AACpE,sCAAsC;AACtC,EAAE;AACF,kEAAkE;AAClE,iEAAiE;AACjE,gEAAgE;AAChE,+CAA+C;AAC/C,EAAE;AACF,oEAAoE;AACpE,wEAAwE;AAIxE,mFAAmF;AACnF,mFAAmF;AAEnF,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,QAAQ;IACR,SAAS;IACT,YAAY;IACZ,YAAY;IACZ,SAAS;IACT,SAAS;IACT,MAAM;IACN,UAAU;IACV,MAAM;IACN,SAAS;IACT,mBAAmB;IACnB,QAAQ;IACR,WAAW;IACX,KAAK;IACL,KAAK;IACL,KAAK;IACL,QAAQ;IACR,gBAAgB;IAChB,qBAAqB;IACrB,MAAM;IACN,SAAS;IACT,oBAAoB;IACpB,sBAAsB;IACtB,oBAAoB;IACpB,MAAM;IACN,SAAS;IACT,MAAM;IACN,SAAS;IACT,KAAK;IACL,KAAK;IACL,SAAS;IACT,KAAK;IACL,OAAO;IACP,UAAU;IACV,MAAM;IACN,MAAM;IACN,QAAQ;IACR,KAAK;IACL,WAAW;IACX,OAAO;IACP,Q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proxmox-api",
3
+ "version": "2.0.0",
4
+ "type": "module",
5
+ "description": "Cutting edge javascript / TypeScript / ESM Proxmox API",
6
+ "keywords": [
7
+ "proxmox",
8
+ "client",
9
+ "typing",
10
+ "api",
11
+ "typescript",
12
+ "async",
13
+ "promise"
14
+ ],
15
+ "author": "Uriel Chemouni <uchemouni@gmail.com> (https://uriel.ovh/)",
16
+ "contributors": [
17
+ "Janic Bellmann <contact@janic.dev>"
18
+ ],
19
+ "license": "GPL-3.0",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/virtbase/proxmox-api.git",
23
+ "directory": "packages/api"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/virtbase/proxmox-api/issues"
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "engines": {
32
+ "node": ">=18"
33
+ },
34
+ "sideEffects": false,
35
+ "exports": {
36
+ ".": {
37
+ "types": "./dist/index.d.ts",
38
+ "default": "./dist/index.js"
39
+ }
40
+ },
41
+ "main": "./dist/index.js",
42
+ "types": "./dist/index.d.ts",
43
+ "files": [
44
+ "dist",
45
+ "src",
46
+ "CHANGELOG.md"
47
+ ],
48
+ "scripts": {
49
+ "build": "tsc",
50
+ "clean": "git clean -xdf .cache .turbo dist node_modules",
51
+ "dev": "tsc --watch",
52
+ "lint:package": "publint --strict && attw --pack . --ignore-rules cjs-resolves-to-esm",
53
+ "prepack": "bun run build",
54
+ "test": "bun test",
55
+ "typecheck": "tsc --noEmit --emitDeclarationOnly false"
56
+ },
57
+ "devDependencies": {
58
+ "@arethetypeswrong/cli": "^0.18.2",
59
+ "@biomejs/biome": "catalog:",
60
+ "@types/bun": "catalog:",
61
+ "@virtbase/tsconfig": "workspace:*",
62
+ "publint": "^0.3.12",
63
+ "typescript": "catalog:"
64
+ }
65
+ }
@@ -0,0 +1,39 @@
1
+ import type { ApiParamType, ApiRequestable } from "../proxy.js";
2
+
3
+ export interface RecordedCall {
4
+ method: string;
5
+ path: string;
6
+ pathTemplate: string;
7
+ params?: ApiParamType;
8
+ }
9
+
10
+ /**
11
+ * An {@link ApiRequestable} that records calls and replays queued replies.
12
+ *
13
+ * For tests about what the client *sends*. Tests about the wire format drive a
14
+ * real `http.Server` instead - see `proxmox-engine.test.ts`.
15
+ */
16
+ export class RecordingEngine implements ApiRequestable {
17
+ readonly calls: RecordedCall[] = [];
18
+ private readonly replies: unknown[];
19
+
20
+ constructor(...replies: unknown[]) {
21
+ this.replies = replies;
22
+ }
23
+
24
+ doRequest(
25
+ method: string,
26
+ path: string,
27
+ pathTemplate: string,
28
+ params?: ApiParamType,
29
+ ): Promise<unknown> {
30
+ this.calls.push({ method, path, pathTemplate, params });
31
+ return Promise.resolve(this.replies.shift());
32
+ }
33
+
34
+ get last(): RecordedCall {
35
+ const call = this.calls.at(-1);
36
+ if (!call) throw new Error("no calls recorded");
37
+ return call;
38
+ }
39
+ }