@homeflare/distilled-proxmox 0.2.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/LICENSE +201 -0
- package/README.md +87 -0
- package/dist/credentials.d.ts +41 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/credentials.js +67 -0
- package/dist/credentials.js.map +1 -0
- package/dist/errors.d.ts +128 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +91 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +18 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +167 -0
- package/dist/protocol.js.map +1 -0
- package/dist/protocol.test.d.ts +2 -0
- package/dist/protocol.test.d.ts.map +1 -0
- package/dist/protocol.test.js +64 -0
- package/dist/protocol.test.js.map +1 -0
- package/dist/retry.d.ts +50 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +43 -0
- package/dist/retry.js.map +1 -0
- package/dist/services/access.d.ts +975 -0
- package/dist/services/access.d.ts.map +1 -0
- package/dist/services/access.js +1208 -0
- package/dist/services/access.js.map +1 -0
- package/dist/services/cluster.d.ts +5940 -0
- package/dist/services/cluster.d.ts.map +1 -0
- package/dist/services/cluster.js +7405 -0
- package/dist/services/cluster.js.map +1 -0
- package/dist/services/index.d.ts +7 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +8 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/nodes.d.ts +7887 -0
- package/dist/services/nodes.d.ts.map +1 -0
- package/dist/services/nodes.js +10253 -0
- package/dist/services/nodes.js.map +1 -0
- package/dist/services/pools.d.ts +133 -0
- package/dist/services/pools.d.ts.map +1 -0
- package/dist/services/pools.js +183 -0
- package/dist/services/pools.js.map +1 -0
- package/dist/services/storage.d.ts +317 -0
- package/dist/services/storage.d.ts.map +1 -0
- package/dist/services/storage.js +239 -0
- package/dist/services/storage.js.map +1 -0
- package/dist/services/version.d.ts +20 -0
- package/dist/services/version.d.ts.map +1 -0
- package/dist/services/version.js +27 -0
- package/dist/services/version.js.map +1 -0
- package/dist/task.d.ts +51 -0
- package/dist/task.d.ts.map +1 -0
- package/dist/task.js +60 -0
- package/dist/task.js.map +1 -0
- package/dist/traits.d.ts +12 -0
- package/dist/traits.d.ts.map +1 -0
- package/dist/traits.js +14 -0
- package/dist/traits.js.map +1 -0
- package/package.json +81 -0
- package/src/credentials.ts +101 -0
- package/src/errors.ts +152 -0
- package/src/index.ts +33 -0
- package/src/protocol.test.ts +101 -0
- package/src/protocol.ts +204 -0
- package/src/retry.ts +74 -0
- package/src/services/access.ts +2722 -0
- package/src/services/cluster.ts +18550 -0
- package/src/services/index.ts +7 -0
- package/src/services/nodes.ts +25537 -0
- package/src/services/pools.ts +397 -0
- package/src/services/storage.ts +711 -0
- package/src/services/version.ts +54 -0
- package/src/task.ts +87 -0
- package/src/traits.ts +45 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// AUTO-GENERATED by scripts/generate.ts from .generated-specs (apidata.js, via scripts/apidoc.ts — see its header). Do not edit.
|
|
2
|
+
import * as S from "@distilled.cloud/core/schema";
|
|
3
|
+
import * as API from "@distilled.cloud/core/api";
|
|
4
|
+
import * as T from "../traits.ts";
|
|
5
|
+
import {
|
|
6
|
+
ProxmoxProtocol,
|
|
7
|
+
type ProxmoxOpError,
|
|
8
|
+
type ProxmoxOpContext,
|
|
9
|
+
} from "../protocol.ts";
|
|
10
|
+
import * as Retry from "../retry.ts";
|
|
11
|
+
|
|
12
|
+
export type { ProxmoxOpError, ProxmoxOpContext };
|
|
13
|
+
|
|
14
|
+
export interface GetVersionRequest {}
|
|
15
|
+
export const GetVersionRequest = /*@__PURE__*/ S.suspend(() =>
|
|
16
|
+
S.Struct({}).pipe(T.Http({ method: "GET", uri: "/version", code: 200 })),
|
|
17
|
+
).annotate({
|
|
18
|
+
identifier: "GetVersionRequest",
|
|
19
|
+
}) as any as S.Schema<GetVersionRequest>;
|
|
20
|
+
|
|
21
|
+
export type GetVersionResponseConsole = "applet" | "vv" | "html5" | "xtermjs";
|
|
22
|
+
export const GetVersionResponseConsole = S.String;
|
|
23
|
+
|
|
24
|
+
export interface GetVersionResponse {
|
|
25
|
+
console?: GetVersionResponseConsole;
|
|
26
|
+
release: string;
|
|
27
|
+
repoid: string;
|
|
28
|
+
version: string;
|
|
29
|
+
}
|
|
30
|
+
export const GetVersionResponse = /*@__PURE__*/ S.suspend(() =>
|
|
31
|
+
S.Struct({
|
|
32
|
+
console: S.optional(GetVersionResponseConsole),
|
|
33
|
+
release: S.String,
|
|
34
|
+
repoid: S.String,
|
|
35
|
+
version: S.String,
|
|
36
|
+
}),
|
|
37
|
+
).annotate({
|
|
38
|
+
identifier: "GetVersionResponse",
|
|
39
|
+
}) as any as S.Schema<GetVersionResponse>;
|
|
40
|
+
|
|
41
|
+
export type GetVersionError = ProxmoxOpError;
|
|
42
|
+
/** API version details, including some parts of the global datacenter config. */
|
|
43
|
+
export const getVersion: API.OperationMethod<
|
|
44
|
+
GetVersionRequest,
|
|
45
|
+
GetVersionResponse,
|
|
46
|
+
GetVersionError,
|
|
47
|
+
ProxmoxOpContext
|
|
48
|
+
> = /*@__PURE__*/ API.make(() => ({
|
|
49
|
+
input: GetVersionRequest,
|
|
50
|
+
output: GetVersionResponse,
|
|
51
|
+
errors: [],
|
|
52
|
+
protocol: ProxmoxProtocol,
|
|
53
|
+
retry: Retry.Retry,
|
|
54
|
+
}));
|
package/src/task.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Awaiting a PVE task — trap (a) from `src/protocol.ts`'s header.
|
|
3
|
+
*
|
|
4
|
+
* PVE answers a long-running action (VM start, backup, migration, …) with
|
|
5
|
+
* HTTP 200 and a bare UPID string the moment the task is QUEUED, not once
|
|
6
|
+
* it finishes. The only way to know whether it actually succeeded is to
|
|
7
|
+
* poll `GET /nodes/{node}/tasks/{upid}/status` — this package's generated
|
|
8
|
+
* `Services.nodes.getNodeTaskStatus` — until the response carries an
|
|
9
|
+
* `exitstatus`, and then check that value.
|
|
10
|
+
*
|
|
11
|
+
* ⛔ `exitstatus` IS COMPARED FOR EXACT EQUALITY TO `"OK"`, NEVER A PREFIX
|
|
12
|
+
* OR SUBSTRING CHECK. PVE also answers `"OK (warnings)"` (the task
|
|
13
|
+
* finished with recoverable warnings) — `startsWith("OK")` would treat
|
|
14
|
+
* that as an ordinary success and swallow the warning entirely, and
|
|
15
|
+
* `includes("OK")` is even looser. Anything other than the literal
|
|
16
|
+
* string `"OK"` — `"OK (warnings)"` included — fails with
|
|
17
|
+
* {@link ProxmoxTaskFailed}, carrying the vendor's own text verbatim so a
|
|
18
|
+
* caller that wants to treat warnings as success can still do so by
|
|
19
|
+
* matching on the message.
|
|
20
|
+
*
|
|
21
|
+
* `awaitTask` does not itself apply a deadline — wrap the call with
|
|
22
|
+
* `Effect.timeout` (or `Retry.transient`/a caller-supplied policy) the way
|
|
23
|
+
* any other Effect program composes one; a fixed timeout baked in here
|
|
24
|
+
* would be wrong for a backup that legitimately runs for hours and right
|
|
25
|
+
* for a config reload that should fail fast, and this module cannot know
|
|
26
|
+
* which operation queued the UPID it was handed.
|
|
27
|
+
*/
|
|
28
|
+
import * as Effect from "effect/Effect";
|
|
29
|
+
import type * as Duration from "effect/Duration";
|
|
30
|
+
import type { ProxmoxOpContext } from "./protocol.ts";
|
|
31
|
+
import { ProxmoxTaskFailed } from "./errors.ts";
|
|
32
|
+
import * as nodes from "./services/nodes.ts";
|
|
33
|
+
import type {
|
|
34
|
+
GetNodeTaskStatusError,
|
|
35
|
+
GetNodeTaskStatusResponse,
|
|
36
|
+
} from "./services/nodes.ts";
|
|
37
|
+
|
|
38
|
+
/** Identifies one PVE task. `node` is the cluster member that OWNS the task — see the module header. */
|
|
39
|
+
export interface TaskRef {
|
|
40
|
+
readonly node: string;
|
|
41
|
+
readonly upid: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface AwaitTaskOptions {
|
|
45
|
+
/** Delay between polls. Default 1 second. */
|
|
46
|
+
readonly pollInterval?: Duration.Input;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Poll a task to completion. Resolves with the FINAL status response (so a
|
|
51
|
+
* caller can read `pid`/`starttime`/etc. without a second call) once
|
|
52
|
+
* `exitstatus` is exactly `"OK"`; fails with {@link ProxmoxTaskFailed}
|
|
53
|
+
* for any other `exitstatus`, or with whatever `getNodeTaskStatus` itself
|
|
54
|
+
* failed with (a typed HTTP error, `ClusterNodeUnreachable` if the node
|
|
55
|
+
* this task lives on drops out of the cluster mid-poll, …).
|
|
56
|
+
*/
|
|
57
|
+
export const awaitTask = (
|
|
58
|
+
ref: TaskRef,
|
|
59
|
+
options: AwaitTaskOptions = {},
|
|
60
|
+
): Effect.Effect<
|
|
61
|
+
GetNodeTaskStatusResponse,
|
|
62
|
+
ProxmoxTaskFailed | GetNodeTaskStatusError,
|
|
63
|
+
ProxmoxOpContext
|
|
64
|
+
> =>
|
|
65
|
+
Effect.gen(function* () {
|
|
66
|
+
const pollInterval = options.pollInterval ?? "1 second";
|
|
67
|
+
while (true) {
|
|
68
|
+
const status = yield* nodes.getNodeTaskStatus({
|
|
69
|
+
node: ref.node,
|
|
70
|
+
upid: ref.upid,
|
|
71
|
+
});
|
|
72
|
+
if (status.exitstatus === undefined) {
|
|
73
|
+
yield* Effect.sleep(pollInterval);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
if (status.exitstatus !== "OK") {
|
|
77
|
+
return yield* Effect.fail(
|
|
78
|
+
new ProxmoxTaskFailed({
|
|
79
|
+
node: ref.node,
|
|
80
|
+
upid: ref.upid,
|
|
81
|
+
exitstatus: status.exitstatus,
|
|
82
|
+
}),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return status;
|
|
86
|
+
}
|
|
87
|
+
});
|
package/src/traits.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxmox VE SDK trait surface — hand-written.
|
|
3
|
+
*
|
|
4
|
+
* Re-exports the generic protocol traits from core so generated operations
|
|
5
|
+
* import everything from one place. PVE speaks form-urlencoded/query REST
|
|
6
|
+
* with a `{"data": …}` envelope and no bare-array response bodies of its
|
|
7
|
+
* own shape beyond what `RawResponse`/`RawResponseRoot` already cover (see
|
|
8
|
+
* `scripts/convert.ts`'s header), so there are no PVE-specific traits.
|
|
9
|
+
*/
|
|
10
|
+
export {
|
|
11
|
+
Body,
|
|
12
|
+
Header,
|
|
13
|
+
Query,
|
|
14
|
+
Label,
|
|
15
|
+
Http,
|
|
16
|
+
ResponseCode,
|
|
17
|
+
HttpBody,
|
|
18
|
+
FormDataFile,
|
|
19
|
+
KeyDictionary,
|
|
20
|
+
UnionCases,
|
|
21
|
+
applyErrorMatchers,
|
|
22
|
+
getErrorMatchers,
|
|
23
|
+
type HttpTrait,
|
|
24
|
+
type ErrorMatcher,
|
|
25
|
+
bodySymbol,
|
|
26
|
+
headerSymbol,
|
|
27
|
+
querySymbol,
|
|
28
|
+
labelSymbol,
|
|
29
|
+
httpSymbol,
|
|
30
|
+
responseCodeSymbol,
|
|
31
|
+
httpBodySymbol,
|
|
32
|
+
formDataFileSymbol,
|
|
33
|
+
keyDictionarySymbol,
|
|
34
|
+
unionCasesSymbol,
|
|
35
|
+
errorMatchersSymbol,
|
|
36
|
+
} from "@distilled.cloud/core/trait";
|
|
37
|
+
|
|
38
|
+
// Bearer-REST protocol traits (bare-payload responses; PVE has no
|
|
39
|
+
// sensitive-member marking today — every generated member is plain).
|
|
40
|
+
export {
|
|
41
|
+
RawResponse,
|
|
42
|
+
RawResponseRoot,
|
|
43
|
+
rawResponseSymbol,
|
|
44
|
+
rawResponseRootSymbol,
|
|
45
|
+
} from "@distilled.cloud/core/protocol-rest";
|