@ornncompute/cli 1.0.264 → 1.0.266

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/README.md CHANGED
@@ -127,8 +127,15 @@ volumes files list | upload | download | delete
127
127
  volumes folders delete
128
128
  volume-mounts candidates | show | attach | wait | detach
129
129
  external-buckets list | show | connect | update-credentials | verify | import | disconnect
130
+ disks list | show | create | import | upload | delete
130
131
  ```
131
132
 
133
+ `disks upload` streams a local qcow2 file to the signed storage link that
134
+ `POST /v1/orchestrator/disks/uploads` returns (local development sends it through
135
+ the gateway), then completes the upload. Staff disk and base-image commands are
136
+ `ornn admin disks rebuild|prewarm|builders` and `ornn admin images
137
+ list|upload|delete`; see the [staff reference](../../docs/cli.md#staff-namespace).
138
+
132
139
  `ssh-keys list` uses backend cursors; see [pagination](../../docs/cli.md#advanced-customer-resources).
133
140
  Organization key deletion saves removal on reservation lists before revoking the
134
141
  account key. If preparation fails, retry the deletion; re-registering the key
@@ -210,6 +217,8 @@ ornn admin ssh
210
217
  ornn admin gifts
211
218
  ornn admin inference
212
219
  ornn admin downtime
220
+ ornn admin disks
221
+ ornn admin images
213
222
  ```
214
223
 
215
224
  Supplier networking is available under the existing supplier root:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ornncompute/cli",
3
- "version": "1.0.264",
3
+ "version": "1.0.266",
4
4
  "description": "Command-line interface for Ornn compute access workflows.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -2,6 +2,7 @@ import { adminSupplierNetworkingHandlers } from "./admin-supplier-networking.mjs
2
2
  import { adminSshHandlers } from "./admin-ssh.mjs";
3
3
  import { adminCapacityReservationHandlers } from "./admin-capacity-reservations.mjs";
4
4
  import { adminCreditHandlers } from "./admin-credits.mjs";
5
+ import { adminDiskHandlers } from "./admin-disks.mjs";
5
6
  import { adminGiftHandlers } from "./admin-gifts.mjs";
6
7
  import { adminEnrollmentHandlers } from "./admin-enrollment.mjs";
7
8
  import { adminNodeDiagnosticsHandlers } from "./admin-node-diagnostics.mjs";
@@ -16,6 +17,7 @@ const handlers = [
16
17
  ...adminSshHandlers,
17
18
  ...adminCapacityReservationHandlers,
18
19
  ...adminCreditHandlers,
20
+ ...adminDiskHandlers,
19
21
  ...adminGiftHandlers,
20
22
  ...adminEnrollmentHandlers,
21
23
  ...adminNodeDiagnosticsHandlers,
@@ -0,0 +1,226 @@
1
+ import { completeImageUpload, postImageObject } from "../vendor/api-client/orchestrator.js";
2
+ import { diskBuildersSetCapability } from "../vendor/capabilities/cli.js";
3
+
4
+ import { ADMIN_MUTATION_SAFETY, AdminMutationError, runAdminMutation } from "./admin-mutations.mjs";
5
+ import { parseSemanticArguments } from "./interaction-runtime.mjs";
6
+ import { uploadQcow2File } from "./qcow2-upload.mjs";
7
+
8
+ const direct = { safety: ADMIN_MUTATION_SAFETY.direct };
9
+
10
+ function usageError(capability, detail, field) {
11
+ return new AdminMutationError(
12
+ [`Usage: ${capability.cli.vnext.human}`, detail].filter(Boolean).join("\n"),
13
+ { code: "usage_error", ...(field ? { field } : {}) }
14
+ );
15
+ }
16
+
17
+ function validated(capability, schema, input) {
18
+ const parsed = schema.safeParse(input);
19
+ if (!parsed.success) throw usageError(capability, parsed.error.issues[0]?.message);
20
+ return parsed.data;
21
+ }
22
+
23
+ function semanticArguments(argv, capability, positionals) {
24
+ const { $positionals, ...options } = parseSemanticArguments(argv);
25
+ if ($positionals.length !== positionals) throw usageError(capability);
26
+ return { positionals: $positionals, options };
27
+ }
28
+
29
+ function rejectExtra(capability, extra) {
30
+ const [name] = Object.keys(extra);
31
+ if (name) throw usageError(capability, `Unknown option: --${name}`, name);
32
+ }
33
+
34
+ function reviewed(title, fields, consequence) {
35
+ return ({ execute, input, mutation, runtime }) =>
36
+ runAdminMutation({
37
+ ...runtime,
38
+ ...mutation,
39
+ prepare: async () => ({
40
+ review: { title, fields: fields(input), consequence },
41
+ value: input,
42
+ }),
43
+ execute: (value) => execute(value, { confirmed: true }),
44
+ });
45
+ }
46
+
47
+ /** `--disk` repeats, one disk ID each; none rebuilds every image-built disk. */
48
+ function parseRebuild(argv, capability) {
49
+ const diskIds = [];
50
+ for (let index = 0; index < argv.length; index += 1) {
51
+ const argument = argv[index];
52
+ const inline = argument.startsWith("--disk=") ? argument.slice("--disk=".length) : undefined;
53
+ if (argument !== "--disk" && inline === undefined) {
54
+ throw usageError(capability, argument.startsWith("--") ? `Unknown option: ${argument}` : "");
55
+ }
56
+ const value = inline ?? argv[(index += 1)];
57
+ if (!value || value.startsWith("--")) {
58
+ throw usageError(capability, "--disk requires a disk ID.", "disk");
59
+ }
60
+ diskIds.push(value);
61
+ }
62
+ return {
63
+ input: validated(capability, capability.input, diskIds.length ? { disk_ids: diskIds } : {}),
64
+ mutation: direct,
65
+ };
66
+ }
67
+
68
+ function parsePrewarm(argv, capability) {
69
+ const {
70
+ positionals: [diskId],
71
+ options: { enabled, ...extra },
72
+ } = semanticArguments(argv, capability, 1);
73
+ rejectExtra(capability, extra);
74
+ if (enabled !== "true" && enabled !== "false") {
75
+ throw usageError(capability, "--enabled must be true or false.", "enabled");
76
+ }
77
+ return {
78
+ input: validated(capability, capability.input, {
79
+ disk_id: diskId,
80
+ prewarm: enabled === "true",
81
+ }),
82
+ mutation: direct,
83
+ };
84
+ }
85
+
86
+ function parseBuilders(argv, capability) {
87
+ const {
88
+ options: { count, ...extra },
89
+ } = semanticArguments(argv, capability, 0);
90
+ rejectExtra(capability, extra);
91
+ if (count === undefined) return { input: {} };
92
+ return {
93
+ input: validated(capability, diskBuildersSetCapability.input, {
94
+ desired_count: Number(count),
95
+ }),
96
+ mutation: direct,
97
+ };
98
+ }
99
+
100
+ async function runBuilders({ execute, fetch, input, mutation, role, runtime }) {
101
+ if (!mutation) {
102
+ return {
103
+ data: await execute(input),
104
+ exitCode: 0,
105
+ outcome: { class: "ready", phase: "complete" },
106
+ };
107
+ }
108
+ return runAdminMutation({
109
+ ...runtime,
110
+ ...mutation,
111
+ prepare: async () => ({
112
+ review: {
113
+ title: "Set the disk builder count",
114
+ fields: [{ label: "Builders", value: input.desired_count }],
115
+ consequence:
116
+ "Starts or drains dedicated disk builders. Builders above the count finish their current build first.",
117
+ },
118
+ value: input,
119
+ }),
120
+ execute: (value) =>
121
+ diskBuildersSetCapability.execute({ actor: "", confirmed: true, fetch, role }, value),
122
+ });
123
+ }
124
+
125
+ function parseImageUpload(argv, capability) {
126
+ const {
127
+ positionals: [path],
128
+ options: { name, osRelease, ...extra },
129
+ } = semanticArguments(argv, capability, 1);
130
+ rejectExtra(capability, extra);
131
+ const body = validated(capability, capability.input, {
132
+ display_name: name,
133
+ os_release: osRelease ?? null,
134
+ });
135
+ return { input: { path, ...body }, mutation: direct };
136
+ }
137
+
138
+ async function runImageUpload({ execute, fetch, input, mutation, runtime }) {
139
+ const { path, ...body } = input;
140
+ return runAdminMutation({
141
+ ...runtime,
142
+ ...mutation,
143
+ prepare: async () => ({
144
+ review: {
145
+ title: "Upload a base image",
146
+ fields: [
147
+ { label: "File", value: path },
148
+ { label: "Name", value: body.display_name },
149
+ { label: "OS release", value: body.os_release },
150
+ ],
151
+ consequence: "Adds a base image that new disks can be built from.",
152
+ },
153
+ value: input,
154
+ }),
155
+ execute: () =>
156
+ uploadQcow2File({
157
+ path,
158
+ fetchImpl: runtime.fetchImpl,
159
+ start: () => execute(body, { confirmed: true }),
160
+ sendLocal: (id, image_b64) => postImageObject(fetch, { id, image_b64 }),
161
+ complete: (id) => completeImageUpload(fetch, id, body),
162
+ }),
163
+ });
164
+ }
165
+
166
+ function parseImageDelete(argv, capability) {
167
+ const {
168
+ positionals: [imageId],
169
+ options,
170
+ } = semanticArguments(argv, capability, 1);
171
+ rejectExtra(capability, options);
172
+ return {
173
+ input: validated(capability, capability.input, { image_id: imageId }),
174
+ mutation: direct,
175
+ };
176
+ }
177
+
178
+ export const adminDiskHandlers = [
179
+ {
180
+ capabilityId: "disk.rebuild",
181
+ parse: parseRebuild,
182
+ run: reviewed(
183
+ "Rebuild disks",
184
+ (input) => [
185
+ { label: "Disks", value: input.disk_ids?.join(", ") ?? "every image-built disk" },
186
+ ],
187
+ "Disk builders rebuild each disk on the current recipe. A disk stays ready and keeps its ID; launches use the new build once it publishes."
188
+ ),
189
+ safety: ADMIN_MUTATION_SAFETY.direct,
190
+ },
191
+ {
192
+ capabilityId: "disk.prewarm.update",
193
+ parse: parsePrewarm,
194
+ run: reviewed(
195
+ "Change disk prewarming",
196
+ (input) => [
197
+ { label: "Disk", value: input.disk_id },
198
+ { label: "Prewarm", value: input.prewarm ? "on" : "off" },
199
+ ],
200
+ "While prewarming is on, VM hosts download this global disk in the background before a launch needs it."
201
+ ),
202
+ safety: ADMIN_MUTATION_SAFETY.direct,
203
+ },
204
+ {
205
+ capabilityId: "disk.builders.list",
206
+ parse: parseBuilders,
207
+ run: runBuilders,
208
+ safety: ADMIN_MUTATION_SAFETY.direct,
209
+ },
210
+ {
211
+ capabilityId: "image.upload.start",
212
+ parse: parseImageUpload,
213
+ run: runImageUpload,
214
+ safety: ADMIN_MUTATION_SAFETY.direct,
215
+ },
216
+ {
217
+ capabilityId: "image.delete",
218
+ parse: parseImageDelete,
219
+ run: reviewed(
220
+ "Delete a base image",
221
+ (input) => [{ label: "Image", value: input.image_id }],
222
+ "Removes the image; the owner refuses an image a disk still uses."
223
+ ),
224
+ safety: ADMIN_MUTATION_SAFETY.direct,
225
+ },
226
+ ];
@@ -40,6 +40,7 @@ import {
40
40
  executeExternalBucketCommand,
41
41
  writeExternalBucketResultHuman,
42
42
  } from "./external-bucket-commands.mjs";
43
+ import { executeDiskCommand } from "./disk-commands.mjs";
43
44
  import { executeEvidenceCommand } from "./evidence-commands.mjs";
44
45
  import { executeRegistryCommand } from "./registry-commands.mjs";
45
46
  import {
@@ -1010,6 +1011,13 @@ async function executeCapability(
1010
1011
  interaction: this,
1011
1012
  });
1012
1013
  },
1014
+ disks(command, diskInput) {
1015
+ return executeDiskCommand(command, diskInput, {
1016
+ fetch: (path, init) => customerCapabilityFetch(io, path, init, authSnapshot),
1017
+ fetchImpl: io.fetchImpl,
1018
+ interaction: this,
1019
+ });
1020
+ },
1013
1021
  registry(command, registryInput) {
1014
1022
  return executeRegistryCommand(command, registryInput, {
1015
1023
  fetch: (path, init) => customerCapabilityFetch(io, path, init, authSnapshot),
@@ -1251,6 +1259,7 @@ export async function runCatalogCli(argv, io, { version }) {
1251
1259
  runtime: {
1252
1260
  eligibleHuman,
1253
1261
  env: io.env,
1262
+ fetchImpl: io.fetchImpl,
1254
1263
  formatProvided: parsed.format !== undefined,
1255
1264
  machine,
1256
1265
  now: io.now,
@@ -0,0 +1,31 @@
1
+ import {
2
+ completeDiskUpload,
3
+ postDiskObject,
4
+ startDiskUpload,
5
+ } from "../vendor/api-client/orchestrator.js";
6
+
7
+ import { uploadQcow2File } from "./qcow2-upload.mjs";
8
+
9
+ /** `ornn disks upload <file> --name <name> [--disk <disk-id>]`, on the caller's session. */
10
+ export async function executeDiskCommand(command, input, { fetch, fetchImpl, interaction }) {
11
+ if (command !== "disk.upload") {
12
+ interaction.error("Unknown disk command.", { code: "unknown_command" });
13
+ }
14
+ const [path] = input.$positionals;
15
+ const display_name = input.name;
16
+ const disk = await uploadQcow2File({
17
+ path,
18
+ fetchImpl,
19
+ start: () =>
20
+ startDiskUpload(fetch, { display_name, ...(input.disk ? { disk_id: input.disk } : {}) }),
21
+ sendLocal: (id, disk_b64) => postDiskObject(fetch, { id, disk_b64 }),
22
+ complete: (id) => completeDiskUpload(fetch, id, { display_name }),
23
+ });
24
+ return interaction.result({
25
+ data: disk,
26
+ presentation: {
27
+ lines: [`Uploaded disk ${disk.id}: ${disk.display_name}.`],
28
+ next: `ornn disks show ${disk.id}`,
29
+ },
30
+ });
31
+ }
@@ -0,0 +1,85 @@
1
+ import { createReadStream } from "node:fs";
2
+ import { readFile, stat } from "node:fs/promises";
3
+
4
+ import { InteractionError } from "./interaction-runtime.mjs";
5
+
6
+ function failed(message, code) {
7
+ return new InteractionError(message, { code, exitCode: 1 });
8
+ }
9
+
10
+ async function localFile(path) {
11
+ let info;
12
+ try {
13
+ info = await stat(path);
14
+ } catch {
15
+ throw new InteractionError("The local qcow2 file was not found.", {
16
+ code: "local_file_not_found",
17
+ exitCode: 2,
18
+ field: "file",
19
+ });
20
+ }
21
+ if (!info.isFile()) {
22
+ throw new InteractionError("The upload source must be a file, not a directory.", {
23
+ code: "local_file_not_regular",
24
+ exitCode: 2,
25
+ field: "file",
26
+ });
27
+ }
28
+ return info.size;
29
+ }
30
+
31
+ /** Streams the file to its signed storage URL; only Google Cloud Storage links are followed. */
32
+ async function putSigned(target, path, size, fetchImpl) {
33
+ let url;
34
+ try {
35
+ url = new URL(target.upload_url);
36
+ } catch {
37
+ throw failed(
38
+ "Ornn returned an invalid upload link. Start the upload again.",
39
+ "unsafe_upload_link"
40
+ );
41
+ }
42
+ if (
43
+ url.protocol !== "https:" ||
44
+ !(url.hostname === "storage.googleapis.com" || url.hostname.endsWith(".storage.googleapis.com"))
45
+ ) {
46
+ throw failed(
47
+ "Ornn returned an unsafe upload link. Start the upload again.",
48
+ "unsafe_upload_link"
49
+ );
50
+ }
51
+ const headers = new Headers(target.upload_headers ?? {});
52
+ headers.set("content-length", String(size));
53
+ const response = await fetchImpl(url, {
54
+ body: createReadStream(path),
55
+ duplex: "half",
56
+ headers,
57
+ method: target.upload_method || "PUT",
58
+ redirect: "manual",
59
+ });
60
+ if (!response.ok) {
61
+ throw response.status === 403
62
+ ? failed(
63
+ "The upload link expired before the file finished uploading. Start the upload again.",
64
+ "upload_link_expired"
65
+ )
66
+ : failed("Storage could not accept the file. Start the upload again.", "upload_rejected");
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Starts an upload, sends the file where the owner's target says, then
72
+ * completes it. The owner validates the qcow2 file on completion.
73
+ */
74
+ export async function uploadQcow2File({ path, fetchImpl, start, sendLocal, complete }) {
75
+ const size = await localFile(path);
76
+ const target = await start();
77
+ if (target.upload_mode === "signed_put") {
78
+ await putSigned(target, path, size, fetchImpl);
79
+ } else if (target.upload_mode === "local_proxy") {
80
+ await sendLocal(target.id, (await readFile(path)).toString("base64"));
81
+ } else {
82
+ throw failed("Ornn returned an unsupported upload target.", "invalid_upload_target");
83
+ }
84
+ return complete(target.id);
85
+ }
@@ -242,9 +242,18 @@ function listDisks(request, query = {}, signal) {
242
242
  ...signal ? { signal } : {}
243
243
  });
244
244
  }
245
+ function getDisk(request, id, signal) {
246
+ return request(`/v1/orchestrator/disks/${encodeURIComponent(id)}`, {
247
+ method: "GET",
248
+ ...signal ? { signal } : {}
249
+ });
250
+ }
245
251
  function createDisk(request, body) {
246
252
  return request("/v1/orchestrator/disks", { method: "POST", body });
247
253
  }
254
+ function requestDiskRebuilds(request, body) {
255
+ return request("/v1/orchestrator/disks/rebuilds", { method: "POST", body });
256
+ }
248
257
  function updateDisk(request, id, body) {
249
258
  return request(`/v1/orchestrator/disks/${encodeURIComponent(id)}`, {
250
259
  method: "PATCH",
@@ -1102,6 +1111,7 @@ export {
1102
1111
  getControllerAccess,
1103
1112
  getCurrentShellSession,
1104
1113
  getCustomerServicingProfile,
1114
+ getDisk,
1105
1115
  getDrive,
1106
1116
  getEnrollmentAdminSshKey,
1107
1117
  getEnrollmentHost,
@@ -1192,6 +1202,7 @@ export {
1192
1202
  removeControllerNode,
1193
1203
  removeControllerVirtualMachine,
1194
1204
  requestAgentUpdate,
1205
+ requestDiskRebuilds,
1195
1206
  reservationEventsPath,
1196
1207
  revokeEnrollmentToken,
1197
1208
  rotateEnrollmentAdminSshKey,