@virtbase/proxmox-api 3.0.0 → 4.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.
- package/CHANGELOG.md +10 -53
- package/LICENSE +22 -0
- package/README.md +81 -82
- package/dist/client.d.ts +13 -7
- package/dist/client.js +23 -23
- package/dist/errors.d.ts +364 -0
- package/dist/errors.js +372 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -18
- package/dist/model.d.ts +28408 -28157
- package/dist/model.js +4 -16
- package/dist/proxmox-engine.d.ts +273 -54
- package/dist/proxmox-engine.js +772 -248
- package/dist/proxy.d.ts +61 -19
- package/dist/proxy.js +118 -33
- package/dist/qm-monitor.d.ts +225 -25
- package/dist/qm-monitor.js +152 -52
- package/dist/schema-info.d.ts +12 -0
- package/dist/schema-info.js +13 -0
- package/dist/tasks.d.ts +129 -0
- package/dist/tasks.js +132 -0
- package/package.json +33 -34
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/model.d.ts.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/proxmox-engine.d.ts.map +0 -1
- package/dist/proxmox-engine.js.map +0 -1
- package/dist/proxy.d.ts.map +0 -1
- package/dist/proxy.js.map +0 -1
- package/dist/qm-monitor.d.ts.map +0 -1
- package/dist/qm-monitor.js.map +0 -1
- package/src/__tests__/helpers.ts +0 -39
- package/src/__tests__/proxmox-engine.test.ts +0 -393
- package/src/__tests__/proxy.test.ts +0 -190
- package/src/__tests__/qm-monitor.test.ts +0 -215
- package/src/client.ts +0 -58
- package/src/index.ts +0 -34
- package/src/model.ts +0 -32101
- package/src/proxmox-engine.ts +0 -452
- package/src/proxy.ts +0 -195
- package/src/qm-monitor.ts +0 -303
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2026 Janic Bellmann
|
|
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 <https://www.gnu.org/licenses/>.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { describe, expect, test } from "bun:test";
|
|
19
|
-
import type { ApiParamType, ApiRequestable } from "../proxy.js";
|
|
20
|
-
import { buildApiProxy } from "../proxy.js";
|
|
21
|
-
|
|
22
|
-
interface Call {
|
|
23
|
-
method: string;
|
|
24
|
-
path: string;
|
|
25
|
-
template: string;
|
|
26
|
-
params?: ApiParamType;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function recorder() {
|
|
30
|
-
const calls: Call[] = [];
|
|
31
|
-
const engine: ApiRequestable = {
|
|
32
|
-
doRequest(method, path, template, params) {
|
|
33
|
-
calls.push({ method, path, template, params });
|
|
34
|
-
return Promise.resolve(null);
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
// These tests walk arbitrary paths rather than the generated surface, so
|
|
38
|
-
// the root is deliberately untyped.
|
|
39
|
-
// biome-ignore lint/suspicious/noExplicitAny: untyped root, see above.
|
|
40
|
-
return { calls, api: buildApiProxy<any>(engine, "/api2/json") };
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
describe("path building", () => {
|
|
44
|
-
test("property access becomes path segments", async () => {
|
|
45
|
-
const { calls, api } = recorder();
|
|
46
|
-
await api.cluster.resources.$get();
|
|
47
|
-
expect(calls[0]?.path).toBe("/api2/json/cluster/resources");
|
|
48
|
-
expect(calls[0]?.method).toBe("get");
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test("$() substitutes a path variable", async () => {
|
|
52
|
-
const { calls, api } = recorder();
|
|
53
|
-
await api.nodes.$("pve1").qemu.$(100).config.$get();
|
|
54
|
-
expect(calls[0]?.path).toBe("/api2/json/nodes/pve1/qemu/100/config");
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test("the template keeps substituted values out, for grouping", async () => {
|
|
58
|
-
const { calls, api } = recorder();
|
|
59
|
-
await api.nodes.$("pve1").qemu.$(100).config.$get();
|
|
60
|
-
expect(calls[0]?.template).toBe("/api2/json/nodes/*/qemu/*/config");
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test("each verb maps to its method", async () => {
|
|
64
|
-
const { calls, api } = recorder();
|
|
65
|
-
await api.pools.$get();
|
|
66
|
-
await api.pools.$post();
|
|
67
|
-
await api.pools.$put();
|
|
68
|
-
await api.pools.$delete();
|
|
69
|
-
expect(calls.map((c) => c.method)).toEqual([
|
|
70
|
-
"get",
|
|
71
|
-
"post",
|
|
72
|
-
"put",
|
|
73
|
-
"delete",
|
|
74
|
-
]);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test("parameters are handed to the engine untouched", async () => {
|
|
78
|
-
const { calls, api } = recorder();
|
|
79
|
-
await api.nodes.$get({ full: true, tags: ["a", "b"] });
|
|
80
|
-
expect(calls[0]?.params).toEqual({ full: true, tags: ["a", "b"] });
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test("walking the path sends nothing", () => {
|
|
84
|
-
const { calls, api } = recorder();
|
|
85
|
-
const partial = api.nodes.$("pve1").qemu.$(100);
|
|
86
|
-
expect(calls).toHaveLength(0);
|
|
87
|
-
expect(partial).toBeDefined();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test("a partially walked path can be reused", async () => {
|
|
91
|
-
const { calls, api } = recorder();
|
|
92
|
-
const vm = api.nodes.$("pve1").qemu.$(100);
|
|
93
|
-
await vm.config.$get();
|
|
94
|
-
await vm.status.current.$get();
|
|
95
|
-
expect(calls.map((c) => c.path)).toEqual([
|
|
96
|
-
"/api2/json/nodes/pve1/qemu/100/config",
|
|
97
|
-
"/api2/json/nodes/pve1/qemu/100/status/current",
|
|
98
|
-
]);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe("segment escaping", () => {
|
|
103
|
-
test("a slash cannot invent a path level", async () => {
|
|
104
|
-
const { calls, api } = recorder();
|
|
105
|
-
await api.storage.$("local/iso").$get();
|
|
106
|
-
expect(calls[0]?.path).toBe("/api2/json/storage/local%2Fiso");
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test("a question mark cannot start a query string", async () => {
|
|
110
|
-
const { calls, api } = recorder();
|
|
111
|
-
await api.storage.$("we?rd").$get();
|
|
112
|
-
expect(calls[0]?.path).toBe("/api2/json/storage/we%3Frd");
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
test("a hash cannot truncate the path", async () => {
|
|
116
|
-
const { calls, api } = recorder();
|
|
117
|
-
await api.storage.$("we#rd").$get();
|
|
118
|
-
expect(calls[0]?.path).toBe("/api2/json/storage/we%23rd");
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test("colons survive, because UPIDs are full of them", async () => {
|
|
122
|
-
const { calls, api } = recorder();
|
|
123
|
-
await api.nodes.$("pve1").tasks.$("UPID:pve1:001:qmstart:").status.$get();
|
|
124
|
-
expect(calls[0]?.path).toBe(
|
|
125
|
-
"/api2/json/nodes/pve1/tasks/UPID:pve1:001:qmstart:/status",
|
|
126
|
-
);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
test("numbers are accepted as ids", async () => {
|
|
130
|
-
const { calls, api } = recorder();
|
|
131
|
-
await api.nodes.$("pve1").qemu.$(100).$get();
|
|
132
|
-
expect(calls[0]?.path).toBe("/api2/json/nodes/pve1/qemu/100");
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
describe("reserved names", () => {
|
|
137
|
-
test("toString describes the node instead of extending the path", () => {
|
|
138
|
-
const { api } = recorder();
|
|
139
|
-
expect(String(api.nodes)).toBe("ProxyApi{path:/api2/json/nodes}");
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
test("EventEmitter probes on the root do not mint segments", () => {
|
|
143
|
-
const { api } = recorder();
|
|
144
|
-
expect(api.on).toBeUndefined();
|
|
145
|
-
expect(api.emit).toBeUndefined();
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
test("those names stay usable deeper down", async () => {
|
|
149
|
-
const { calls, api } = recorder();
|
|
150
|
-
await api.cluster.on.$get();
|
|
151
|
-
expect(calls[0]?.path).toBe("/api2/json/cluster/on");
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test("a leading underscore escapes a reserved name at the root", async () => {
|
|
155
|
-
const { calls, api } = recorder();
|
|
156
|
-
await api._on.$get();
|
|
157
|
-
expect(calls[0]?.path).toBe("/api2/json/on");
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
test("symbols do not become segments", () => {
|
|
161
|
-
const { api } = recorder();
|
|
162
|
-
expect(api[Symbol.toStringTag]).toBeUndefined();
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
describe("awkward segment names", () => {
|
|
167
|
-
test("hyphenated segments work through bracket access", async () => {
|
|
168
|
-
const { calls, api } = recorder();
|
|
169
|
-
await api.nodes.$("pve1").qemu.$(100).agent["get-fsinfo"].$get();
|
|
170
|
-
expect(calls[0]?.path).toBe(
|
|
171
|
-
"/api2/json/nodes/pve1/qemu/100/agent/get-fsinfo",
|
|
172
|
-
);
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
test("the engine is reachable through a custom implementation", async () => {
|
|
176
|
-
const seen: string[] = [];
|
|
177
|
-
const api = buildApiProxy<Record<string, never>>(
|
|
178
|
-
{
|
|
179
|
-
doRequest(_method, path) {
|
|
180
|
-
seen.push(path);
|
|
181
|
-
return Promise.resolve("ok");
|
|
182
|
-
},
|
|
183
|
-
},
|
|
184
|
-
"/custom",
|
|
185
|
-
// biome-ignore lint/suspicious/noExplicitAny: as above.
|
|
186
|
-
) as any;
|
|
187
|
-
expect(await api.thing.$get()).toBe("ok");
|
|
188
|
-
expect(seen).toEqual(["/custom/thing"]);
|
|
189
|
-
});
|
|
190
|
-
});
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2026 Janic Bellmann
|
|
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 <https://www.gnu.org/licenses/>.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import { describe, expect, test } from "bun:test";
|
|
19
|
-
import type { Proxmox } from "../model.js";
|
|
20
|
-
import { buildApiProxy } from "../proxy.js";
|
|
21
|
-
import { QmMonitor } from "../qm-monitor.js";
|
|
22
|
-
import { RecordingEngine } from "./helpers.js";
|
|
23
|
-
|
|
24
|
-
function monitor(...replies: string[]) {
|
|
25
|
-
const engine = new RecordingEngine(...replies);
|
|
26
|
-
const api = buildApiProxy<Proxmox.Api>(engine, "/api2/json");
|
|
27
|
-
return { engine, qm: new QmMonitor(api, "pve1", 100) };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** The command string sent by the nth monitor call. */
|
|
31
|
-
function commandAt(engine: RecordingEngine, index: number): string {
|
|
32
|
-
const params = engine.calls[index]?.params;
|
|
33
|
-
if (!params) throw new Error(`no monitor call recorded at index ${index}`);
|
|
34
|
-
return (params as { command: string }).command;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
describe("command construction", () => {
|
|
38
|
-
test("targets the guest's monitor endpoint", async () => {
|
|
39
|
-
const { engine, qm } = monitor("");
|
|
40
|
-
await qm.monitor("info status");
|
|
41
|
-
expect(engine.last.path).toBe("/api2/json/nodes/pve1/qemu/100/monitor");
|
|
42
|
-
expect(engine.last.method).toBe("post");
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test("exposes node and vmid", () => {
|
|
46
|
-
const { qm } = monitor();
|
|
47
|
-
expect(qm.node).toBe("pve1");
|
|
48
|
-
expect(qm.vmid).toBe(100);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test("info builds `info <type>`", async () => {
|
|
52
|
-
const { engine, qm } = monitor("");
|
|
53
|
-
await qm.info("status");
|
|
54
|
-
expect(commandAt(engine, 0)).toBe("info status");
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test("info appends arguments with no trailing space when absent", async () => {
|
|
58
|
-
const { engine, qm } = monitor("", "");
|
|
59
|
-
await qm.info("block");
|
|
60
|
-
await qm.info("mtree", "-f");
|
|
61
|
-
expect(commandAt(engine, 0)).toBe("info block");
|
|
62
|
-
expect(commandAt(engine, 1)).toBe("info mtree -f");
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
describe("infoUsb", () => {
|
|
67
|
-
const twoDevices =
|
|
68
|
-
"Device 1.1, Port 1, Speed 1.5 Mb/s, Product USB OPTICAL MOUSE , ID: mouse\n" +
|
|
69
|
-
"Device 1.0, Port 2, Speed 12 Mb/s, Product Gaming KB , ID: keyboard\n";
|
|
70
|
-
|
|
71
|
-
test("parses attached devices", async () => {
|
|
72
|
-
const { qm } = monitor(twoDevices);
|
|
73
|
-
const devices = await qm.infoUsb();
|
|
74
|
-
expect(devices).toHaveLength(2);
|
|
75
|
-
expect(devices[0]).toEqual({
|
|
76
|
-
device: "1.1",
|
|
77
|
-
port: "1",
|
|
78
|
-
speed: "1.5 Mb/s",
|
|
79
|
-
product: "USB OPTICAL MOUSE ",
|
|
80
|
-
id: "mouse",
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test("a device with no product string yields undefined, not a crash", async () => {
|
|
85
|
-
const { qm } = monitor("Device 1.1, Port 1, Speed 1.5 Mb/s\n");
|
|
86
|
-
const [device] = await qm.infoUsb();
|
|
87
|
-
expect(device?.product).toBeUndefined();
|
|
88
|
-
expect(device?.id).toBeUndefined();
|
|
89
|
-
expect(device?.device).toBe("1.1");
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test("throws when the reply has lines it could not parse", async () => {
|
|
93
|
-
const { qm } = monitor(
|
|
94
|
-
"Device 1.1, Port 1, Speed 1.5 Mb/s, Product M , ID: mouse\nsomething else\n",
|
|
95
|
-
);
|
|
96
|
-
expect(qm.infoUsb()).rejects.toThrow(/format may have changed/);
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
describe("infoUsbhost", () => {
|
|
101
|
-
const hostDevices =
|
|
102
|
-
"Bus 1, Addr 4, Port 2, Speed 480 Mb/s\n Class 00: USB device 046d:c52b, Logitech Receiver\n" +
|
|
103
|
-
"Bus 2, Addr 5, Port 3, Speed 12 Mb/s\n Class 03: USB device 1a2b:3c4d, Some Keyboard\n";
|
|
104
|
-
|
|
105
|
-
test("parses host devices", async () => {
|
|
106
|
-
const { qm } = monitor(hostDevices);
|
|
107
|
-
const devices = await qm.infoUsbhost();
|
|
108
|
-
expect(devices).toHaveLength(2);
|
|
109
|
-
expect(devices[0]).toEqual({
|
|
110
|
-
bus: 1,
|
|
111
|
-
addr: 4,
|
|
112
|
-
port: "2",
|
|
113
|
-
speed: "480 Mb/s",
|
|
114
|
-
class: "00",
|
|
115
|
-
vendorId: "046d",
|
|
116
|
-
productId: "c52b",
|
|
117
|
-
name: "Logitech Receiver",
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test("filters by name", async () => {
|
|
122
|
-
const { qm } = monitor(hostDevices);
|
|
123
|
-
const devices = await qm.infoUsbhost({ name: /Logitech/ });
|
|
124
|
-
expect(devices.map((d) => d.name)).toEqual(["Logitech Receiver"]);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test("filters by vendorId against the vendor id, not the name", async () => {
|
|
128
|
-
const { qm } = monitor(hostDevices);
|
|
129
|
-
const devices = await qm.infoUsbhost({ vendorId: /046d/ });
|
|
130
|
-
expect(devices.map((d) => d.name)).toEqual(["Logitech Receiver"]);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test("filters by productId against the product id", async () => {
|
|
134
|
-
const { qm } = monitor(hostDevices);
|
|
135
|
-
const devices = await qm.infoUsbhost({ productId: /3c4d/ });
|
|
136
|
-
expect(devices.map((d) => d.name)).toEqual(["Some Keyboard"]);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
test("filters combine", async () => {
|
|
140
|
-
const { qm } = monitor(hostDevices);
|
|
141
|
-
expect(
|
|
142
|
-
await qm.infoUsbhost({ vendorId: /046d/, productId: /3c4d/ }),
|
|
143
|
-
).toHaveLength(0);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
describe("device attachment", () => {
|
|
148
|
-
test("deviceAddById strips a 0x prefix and does not mutate its argument", async () => {
|
|
149
|
-
const { engine, qm } = monitor("");
|
|
150
|
-
const params = { vendorId: "0x046d", productId: "0xc52b" };
|
|
151
|
-
await qm.deviceAddById("usb0", params);
|
|
152
|
-
expect(commandAt(engine, 0)).toBe(
|
|
153
|
-
"device_add usb-host,vendorid=0x046d,productid=0xc52b,id=usb0",
|
|
154
|
-
);
|
|
155
|
-
expect(params).toEqual({ vendorId: "0x046d", productId: "0xc52b" });
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
test("deviceAddByPort addresses the physical port", async () => {
|
|
159
|
-
const { engine, qm } = monitor("");
|
|
160
|
-
await qm.deviceAddByPort("front2", { bus: 2, port: "4" });
|
|
161
|
-
expect(commandAt(engine, 0)).toBe(
|
|
162
|
-
"device_add usb-host,hostbus=2,hostport=4,id=front2",
|
|
163
|
-
);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
test("deviceDel detaches by id", async () => {
|
|
167
|
-
const { engine, qm } = monitor("");
|
|
168
|
-
await qm.deviceDel("usb0");
|
|
169
|
-
expect(commandAt(engine, 0)).toBe("device_del usb0");
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
describe("deviceAddMissing", () => {
|
|
174
|
-
const hostDevices =
|
|
175
|
-
"Bus 1, Addr 4, Port 2, Speed 480 Mb/s\n Class 00: USB device 046d:c52b, Logitech Receiver\n" +
|
|
176
|
-
"Bus 2, Addr 5, Port 3, Speed 12 Mb/s\n Class 03: USB device 1a2b:3c4d, Some Keyboard\n";
|
|
177
|
-
|
|
178
|
-
test("attaches each match, suffixing after the first", async () => {
|
|
179
|
-
const { engine, qm } = monitor("", hostDevices, "", "");
|
|
180
|
-
const added = await qm.deviceAddMissing("usb", {});
|
|
181
|
-
|
|
182
|
-
expect(added).toEqual(["usb", "usb-1"]);
|
|
183
|
-
expect(commandAt(engine, 2)).toBe(
|
|
184
|
-
"device_add usb-host,hostbus=1,hostport=2,id=usb",
|
|
185
|
-
);
|
|
186
|
-
expect(commandAt(engine, 3)).toBe(
|
|
187
|
-
"device_add usb-host,hostbus=2,hostport=3,id=usb-1",
|
|
188
|
-
);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
test("refuses when the id is already attached", async () => {
|
|
192
|
-
const { qm } = monitor(
|
|
193
|
-
"Device 1.1, Port 1, Speed 1.5 Mb/s, Product M , ID: usb\n",
|
|
194
|
-
);
|
|
195
|
-
expect(qm.deviceAddMissing("usb", {})).rejects.toThrow(/already present/);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test("awaits each attach, so a failure propagates", async () => {
|
|
199
|
-
const engine = new RecordingEngine("", hostDevices);
|
|
200
|
-
const original = engine.doRequest.bind(engine);
|
|
201
|
-
engine.doRequest = (method, path, template, params) => {
|
|
202
|
-
const command = (params as { command?: string })?.command ?? "";
|
|
203
|
-
if (command.startsWith("device_add")) {
|
|
204
|
-
return Promise.reject(new Error("monitor refused"));
|
|
205
|
-
}
|
|
206
|
-
return original(method, path, template, params);
|
|
207
|
-
};
|
|
208
|
-
const qm = new QmMonitor(
|
|
209
|
-
buildApiProxy<Proxmox.Api>(engine, "/api2/json"),
|
|
210
|
-
"pve1",
|
|
211
|
-
100,
|
|
212
|
-
);
|
|
213
|
-
expect(qm.deviceAddMissing("usb", {})).rejects.toThrow("monitor refused");
|
|
214
|
-
});
|
|
215
|
-
});
|
package/src/client.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
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
|
-
|
|
17
|
-
import type { Proxmox } from "./model.js";
|
|
18
|
-
import type { ProxmoxEngineOptions } from "./proxmox-engine.js";
|
|
19
|
-
import { ProxmoxEngine } from "./proxmox-engine.js";
|
|
20
|
-
import type { ApiRequestable } from "./proxy.js";
|
|
21
|
-
import { buildApiProxy } from "./proxy.js";
|
|
22
|
-
|
|
23
|
-
/** Every path this client builds hangs off the JSON API root. */
|
|
24
|
-
const BASE_PATH = "/api2/json";
|
|
25
|
-
|
|
26
|
-
function isRequestable(
|
|
27
|
-
value: ProxmoxEngineOptions | ApiRequestable,
|
|
28
|
-
): value is ApiRequestable {
|
|
29
|
-
return "doRequest" in value;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Build a typed Proxmox API client.
|
|
34
|
-
*
|
|
35
|
-
* @param options Connection options, or any {@link ApiRequestable} to send
|
|
36
|
-
* requests through - a pre-built {@link ProxmoxEngine} whose session you
|
|
37
|
-
* want to keep, or a stub for tests.
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```ts
|
|
41
|
-
* const proxmox = proxmoxApi({
|
|
42
|
-
* host: "192.0.2.10",
|
|
43
|
-
* port: 8006,
|
|
44
|
-
* tokenID: "root@pam!automation",
|
|
45
|
-
* tokenSecret: "12345678-1234-1234-1234-1234567890ab",
|
|
46
|
-
* });
|
|
47
|
-
*
|
|
48
|
-
* const nodes = await proxmox.nodes.$get();
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export function proxmoxApi(
|
|
52
|
-
options: ProxmoxEngineOptions | ApiRequestable,
|
|
53
|
-
): Proxmox.Api {
|
|
54
|
-
const engine = isRequestable(options) ? options : new ProxmoxEngine(options);
|
|
55
|
-
return buildApiProxy<Proxmox.Api>(engine, BASE_PATH);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export default proxmoxApi;
|
package/src/index.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
export { proxmoxApi as default, proxmoxApi } from "./client.js";
|
|
17
|
-
export type { Proxmox } from "./model.js";
|
|
18
|
-
export {
|
|
19
|
-
ProxmoxEngine,
|
|
20
|
-
type ProxmoxEngineOptions,
|
|
21
|
-
type ProxmoxEngineOptionsCommon,
|
|
22
|
-
type ProxmoxEngineOptionsPass,
|
|
23
|
-
type ProxmoxEngineOptionsToken,
|
|
24
|
-
} from "./proxmox-engine.js";
|
|
25
|
-
export type { ApiParamType, ApiRequestable } from "./proxy.js";
|
|
26
|
-
export {
|
|
27
|
-
QmMonitor,
|
|
28
|
-
type USBHostFilter,
|
|
29
|
-
type USBHostInfo,
|
|
30
|
-
type USBInfo,
|
|
31
|
-
} from "./qm-monitor.js";
|
|
32
|
-
|
|
33
|
-
// for stress test
|
|
34
|
-
// export { buildApiProxy } from './proxy';
|