@ornncompute/cli 1.0.260 → 1.0.262
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 +32 -1
- package/package.json +1 -1
- package/src/admin-benchmark.mjs +292 -0
- package/src/admin-command-handlers.mjs +8 -2
- package/src/admin-fleet.mjs +458 -0
- package/src/admin-shell.mjs +15 -2
- package/src/catalog-shell.mjs +100 -13
- package/vendor/capabilities/cli.js +2013 -1006
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
import { ADMIN_MUTATION_SAFETY, AdminMutationError, runAdminMutation } from "./admin-mutations.mjs";
|
|
2
|
+
|
|
3
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
4
|
+
|
|
5
|
+
function usageError(message, field) {
|
|
6
|
+
return new AdminMutationError(message, {
|
|
7
|
+
code: "usage_error",
|
|
8
|
+
...(field ? { field } : {}),
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function parseOptions(argv, allowed, usage) {
|
|
13
|
+
const options = {};
|
|
14
|
+
const positionals = [];
|
|
15
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
16
|
+
const argument = argv[index];
|
|
17
|
+
if (!argument.startsWith("--")) {
|
|
18
|
+
positionals.push(argument);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const separator = argument.indexOf("=");
|
|
22
|
+
const name = argument.slice(2, separator === -1 ? undefined : separator);
|
|
23
|
+
if (!allowed.has(name)) throw usageError(`${usage}\nUnknown option: --${name}`, name);
|
|
24
|
+
if (options[name] !== undefined) {
|
|
25
|
+
throw usageError(`${usage}\n--${name} may be supplied only once.`, name);
|
|
26
|
+
}
|
|
27
|
+
const inline = separator !== -1;
|
|
28
|
+
const value = inline ? argument.slice(separator + 1) : argv[index + 1];
|
|
29
|
+
if (value === undefined || (!inline && value.startsWith("--"))) {
|
|
30
|
+
throw usageError(`${usage}\n--${name} requires a value.`, name);
|
|
31
|
+
}
|
|
32
|
+
options[name] = value;
|
|
33
|
+
if (!inline) index += 1;
|
|
34
|
+
}
|
|
35
|
+
return { options, positionals };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function requireUuid(value, name, usage) {
|
|
39
|
+
if (!value || !UUID.test(value)) {
|
|
40
|
+
throw usageError(`${usage}\n${name} must be a UUID.`, name);
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function onePositional(positionals, usage, field) {
|
|
46
|
+
if (positionals.length !== 1 || !positionals[0]) throw usageError(usage, field);
|
|
47
|
+
return positionals[0];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function noPositionals(positionals, usage) {
|
|
51
|
+
if (positionals.length !== 0) throw usageError(usage);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function booleanValue(value, name, usage) {
|
|
55
|
+
if (value === undefined) return undefined;
|
|
56
|
+
if (value === "true") return true;
|
|
57
|
+
if (value === "false") return false;
|
|
58
|
+
throw usageError(`${usage}\n--${name} must be true or false.`, name);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function integerValue(value, name, usage, { min = 0, max = Number.MAX_SAFE_INTEGER } = {}) {
|
|
62
|
+
if (typeof value !== "string" || !/^(?:0|[1-9]\d*)$/.test(value)) {
|
|
63
|
+
throw usageError(`${usage}\n--${name} must be an integer from ${min} to ${max}.`, name);
|
|
64
|
+
}
|
|
65
|
+
const parsed = Number(value);
|
|
66
|
+
if (!Number.isSafeInteger(parsed) || parsed < min || parsed > max) {
|
|
67
|
+
throw usageError(`${usage}\n--${name} must be an integer from ${min} to ${max}.`, name);
|
|
68
|
+
}
|
|
69
|
+
return parsed;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function enumValue(value, name, allowed, usage) {
|
|
73
|
+
if (!allowed.includes(value)) {
|
|
74
|
+
throw usageError(`${usage}\n--${name} must be ${allowed.join("|")}.`, name);
|
|
75
|
+
}
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const DEPLOY_USAGE =
|
|
80
|
+
"Usage: ornn admin nodes deploy <node-id> --tenant UUID [--reservation UUID] [--user UUID] [--network public|private] [--notes TEXT]";
|
|
81
|
+
const UPDATE_USAGE =
|
|
82
|
+
"Usage: ornn admin nodes update <node-id> [--hostname NAME] [--facility UUID] [--gpu-type TYPE] [--gpu-count N] [--cpu TYPE] [--boot-image SHA] [--agent-updates-excluded true|false]\n--gpu-count 0 records a CPU node and clears the GPU type. Pass --gpu-type \"\" to clear the type without changing the count.";
|
|
83
|
+
const AGENT_USAGE =
|
|
84
|
+
"Usage: ornn admin nodes agent-update <node-id> --version VERSION [--force true|false]";
|
|
85
|
+
const MAINTENANCE_USAGE =
|
|
86
|
+
"Usage: ornn admin nodes maintenance [--node UUID] [--organization UUID] [--batch UUID] [--cursor CURSOR]";
|
|
87
|
+
const DOWNTIME_FIELDS =
|
|
88
|
+
"--organization UUID --service gpu|cpu|weka|storage|network|other --affected TEXT --summary TEXT --notes TEXT --started TIME [--ended TIME|null]";
|
|
89
|
+
const DOWNTIME_UPDATE_FIELDS =
|
|
90
|
+
"--organization UUID --service gpu|cpu|weka|storage|network|other --affected TEXT --summary TEXT --notes TEXT --started TIME --ended TIME|null";
|
|
91
|
+
|
|
92
|
+
function parseDeploy(argv) {
|
|
93
|
+
const { options, positionals } = parseOptions(
|
|
94
|
+
argv,
|
|
95
|
+
new Set(["tenant", "reservation", "user", "network", "notes", "idempotency-key"]),
|
|
96
|
+
DEPLOY_USAGE
|
|
97
|
+
);
|
|
98
|
+
const nodeId = onePositional(positionals, DEPLOY_USAGE, "node-id");
|
|
99
|
+
const targetTenantId = requireUuid(options.tenant, "tenant", DEPLOY_USAGE);
|
|
100
|
+
if (options.network !== undefined) enumValue(options.network, "network", ["public", "private"], DEPLOY_USAGE);
|
|
101
|
+
return {
|
|
102
|
+
input: {
|
|
103
|
+
nodeId,
|
|
104
|
+
targetTenantId,
|
|
105
|
+
...(options.reservation !== undefined
|
|
106
|
+
? { commerceReservationId: requireUuid(options.reservation, "reservation", DEPLOY_USAGE) }
|
|
107
|
+
: {}),
|
|
108
|
+
...(options.user !== undefined
|
|
109
|
+
? { targetAuthUserId: requireUuid(options.user, "user", DEPLOY_USAGE) }
|
|
110
|
+
: {}),
|
|
111
|
+
...(options.network ? { networkMode: options.network } : {}),
|
|
112
|
+
...(options.notes ? { notes: options.notes } : {}),
|
|
113
|
+
},
|
|
114
|
+
idempotencyKey: options["idempotency-key"],
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function parseUpdate(argv) {
|
|
119
|
+
const { options, positionals } = parseOptions(
|
|
120
|
+
argv,
|
|
121
|
+
new Set([
|
|
122
|
+
"hostname",
|
|
123
|
+
"facility",
|
|
124
|
+
"gpu-type",
|
|
125
|
+
"gpu-count",
|
|
126
|
+
"cpu",
|
|
127
|
+
"boot-image",
|
|
128
|
+
"agent-updates-excluded",
|
|
129
|
+
"idempotency-key",
|
|
130
|
+
]),
|
|
131
|
+
UPDATE_USAGE
|
|
132
|
+
);
|
|
133
|
+
const nodeId = onePositional(positionals, UPDATE_USAGE, "node-id");
|
|
134
|
+
const input = { nodeId };
|
|
135
|
+
if (options.hostname) input.hostname = options.hostname;
|
|
136
|
+
if (options.facility !== undefined) {
|
|
137
|
+
input.facilityId = requireUuid(options.facility, "facility", UPDATE_USAGE);
|
|
138
|
+
}
|
|
139
|
+
if (options["gpu-type"] !== undefined) {
|
|
140
|
+
input.gpuType = options["gpu-type"].trim();
|
|
141
|
+
}
|
|
142
|
+
if (options["gpu-count"] !== undefined) {
|
|
143
|
+
input.gpuCount = integerValue(options["gpu-count"], "gpu-count", UPDATE_USAGE);
|
|
144
|
+
}
|
|
145
|
+
if (input.gpuCount === 0 && input.gpuType) {
|
|
146
|
+
throw usageError(
|
|
147
|
+
`${UPDATE_USAGE}\n--gpu-count 0 records a CPU node, so leave --gpu-type empty.`,
|
|
148
|
+
"gpu-type"
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
if (input.gpuCount === 0) input.gpuType = "";
|
|
152
|
+
if (options.cpu) input.cpu = options.cpu;
|
|
153
|
+
if (options["boot-image"]) input.bootImageSha256 = options["boot-image"];
|
|
154
|
+
const agentUpdatesExcluded = booleanValue(
|
|
155
|
+
options["agent-updates-excluded"],
|
|
156
|
+
"agent-updates-excluded",
|
|
157
|
+
UPDATE_USAGE
|
|
158
|
+
);
|
|
159
|
+
if (agentUpdatesExcluded !== undefined) input.agentUpdatesExcluded = agentUpdatesExcluded;
|
|
160
|
+
if (Object.keys(input).length === 1) {
|
|
161
|
+
throw usageError(`${UPDATE_USAGE}\nSupply at least one field to update.`);
|
|
162
|
+
}
|
|
163
|
+
return { input, idempotencyKey: options["idempotency-key"] };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function parseAgentUpdate(argv) {
|
|
167
|
+
const { options, positionals } = parseOptions(
|
|
168
|
+
argv,
|
|
169
|
+
new Set(["version", "force", "idempotency-key"]),
|
|
170
|
+
AGENT_USAGE
|
|
171
|
+
);
|
|
172
|
+
const nodeId = requireUuid(onePositional(positionals, AGENT_USAGE, "node-id"), "node-id", AGENT_USAGE);
|
|
173
|
+
if (!options.version) throw usageError(`${AGENT_USAGE}\n--version is required.`, "version");
|
|
174
|
+
return {
|
|
175
|
+
input: {
|
|
176
|
+
node_id: nodeId,
|
|
177
|
+
desired_agent_version: options.version,
|
|
178
|
+
...(options.force === undefined
|
|
179
|
+
? {}
|
|
180
|
+
: { force: booleanValue(options.force, "force", AGENT_USAGE) }),
|
|
181
|
+
},
|
|
182
|
+
idempotencyKey: options["idempotency-key"],
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function parseMaintenance(argv) {
|
|
187
|
+
const { options, positionals } = parseOptions(
|
|
188
|
+
argv,
|
|
189
|
+
new Set(["node", "organization", "batch", "cursor"]),
|
|
190
|
+
MAINTENANCE_USAGE
|
|
191
|
+
);
|
|
192
|
+
noPositionals(positionals, MAINTENANCE_USAGE);
|
|
193
|
+
return {
|
|
194
|
+
input: {
|
|
195
|
+
...(options.node ? { node_id: requireUuid(options.node, "node", MAINTENANCE_USAGE) } : {}),
|
|
196
|
+
...(options.organization
|
|
197
|
+
? { organization_id: requireUuid(options.organization, "organization", MAINTENANCE_USAGE) }
|
|
198
|
+
: {}),
|
|
199
|
+
...(options.batch ? { batch_id: requireUuid(options.batch, "batch", MAINTENANCE_USAGE) } : {}),
|
|
200
|
+
...(options.cursor ? { cursor: options.cursor } : {}),
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function parseRecord(argv) {
|
|
206
|
+
const usage = "Usage: ornn admin nodes maintenance show <record-id>";
|
|
207
|
+
const { positionals } = parseOptions(argv, new Set(), usage);
|
|
208
|
+
return { input: { id: requireUuid(onePositional(positionals, usage, "record-id"), "record-id", usage) } };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function parsePoolGet(argv) {
|
|
212
|
+
const usage = "Usage: ornn admin nodes test-pool";
|
|
213
|
+
const { positionals } = parseOptions(argv, new Set(), usage);
|
|
214
|
+
noPositionals(positionals, usage);
|
|
215
|
+
return { input: {} };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function parsePoolUpdate(argv) {
|
|
219
|
+
const usage =
|
|
220
|
+
"Usage: ornn admin nodes test-pool update --request-id UUID --size N --ttl MINUTES --machine t4|n4 [--prepare-turnover true|false]";
|
|
221
|
+
const { options, positionals } = parseOptions(
|
|
222
|
+
argv,
|
|
223
|
+
new Set(["request-id", "size", "ttl", "machine", "prepare-turnover", "idempotency-key"]),
|
|
224
|
+
usage
|
|
225
|
+
);
|
|
226
|
+
noPositionals(positionals, usage);
|
|
227
|
+
return {
|
|
228
|
+
input: {
|
|
229
|
+
request_id: requireUuid(options["request-id"], "request-id", usage),
|
|
230
|
+
desired_size: integerValue(options.size, "size", usage),
|
|
231
|
+
ttl_minutes: integerValue(options.ttl, "ttl", usage, { min: 30, max: 480 }),
|
|
232
|
+
machine: enumValue(options.machine, "machine", ["t4", "n4"], usage),
|
|
233
|
+
...(options["prepare-turnover"] === undefined
|
|
234
|
+
? {}
|
|
235
|
+
: {
|
|
236
|
+
prepare_turnover: booleanValue(options["prepare-turnover"], "prepare-turnover", usage),
|
|
237
|
+
}),
|
|
238
|
+
},
|
|
239
|
+
idempotencyKey: options["idempotency-key"],
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function parsePoolRuns(argv) {
|
|
244
|
+
const usage = "Usage: ornn admin nodes test-pool runs";
|
|
245
|
+
const { positionals } = parseOptions(argv, new Set(), usage);
|
|
246
|
+
noPositionals(positionals, usage);
|
|
247
|
+
return { input: {} };
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function parsePoolCreate(argv) {
|
|
251
|
+
const usage =
|
|
252
|
+
"Usage: ornn admin nodes test-pool runs create --run-id UUID --ttl MINUTES [--machine t4|n4]";
|
|
253
|
+
const { options, positionals } = parseOptions(
|
|
254
|
+
argv,
|
|
255
|
+
new Set(["run-id", "ttl", "machine", "idempotency-key"]),
|
|
256
|
+
usage
|
|
257
|
+
);
|
|
258
|
+
noPositionals(positionals, usage);
|
|
259
|
+
return {
|
|
260
|
+
input: {
|
|
261
|
+
run_id: requireUuid(options["run-id"], "run-id", usage),
|
|
262
|
+
ttl_minutes: integerValue(options.ttl, "ttl", usage, { min: 30, max: 480 }),
|
|
263
|
+
...(options.machine ? { machine: enumValue(options.machine, "machine", ["t4", "n4"], usage) } : {}),
|
|
264
|
+
},
|
|
265
|
+
idempotencyKey: options["idempotency-key"],
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function parsePoolDelete(argv) {
|
|
270
|
+
const usage = "Usage: ornn admin nodes test-pool runs delete <run-id>";
|
|
271
|
+
const { options, positionals } = parseOptions(argv, new Set(["idempotency-key"]), usage);
|
|
272
|
+
return {
|
|
273
|
+
input: { run_id: requireUuid(onePositional(positionals, usage, "run-id"), "run-id", usage) },
|
|
274
|
+
idempotencyKey: options["idempotency-key"],
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const SERVICES = ["gpu", "cpu", "weka", "storage", "network", "other"];
|
|
279
|
+
|
|
280
|
+
function downtimeBody(options, usage, { notesRequired = false, endedRequired = false } = {}) {
|
|
281
|
+
if (notesRequired && options.notes === undefined) {
|
|
282
|
+
throw usageError(
|
|
283
|
+
`${usage}\n--notes is required. Pass --notes "" to clear saved notes.`,
|
|
284
|
+
"notes"
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
if (endedRequired && options.ended === undefined) {
|
|
288
|
+
throw usageError(
|
|
289
|
+
`${usage}\n--ended is required. Pass --ended null to leave the incident open.`,
|
|
290
|
+
"ended"
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
organizationId: requireUuid(options.organization, "organization", usage),
|
|
295
|
+
serviceType: enumValue(options.service, "service", SERVICES, usage),
|
|
296
|
+
affectedResources: options.affected,
|
|
297
|
+
summary: options.summary,
|
|
298
|
+
notes: options.notes ?? "",
|
|
299
|
+
startedAt: options.started,
|
|
300
|
+
endedAt: options.ended === undefined || options.ended === "null" ? null : options.ended,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function requireDowntimeText(options, usage) {
|
|
305
|
+
for (const name of ["organization", "service", "affected", "summary", "started"]) {
|
|
306
|
+
if (!options[name]) throw usageError(`${usage}\n--${name} is required.`, name);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function parseDowntimeList(argv) {
|
|
311
|
+
const usage =
|
|
312
|
+
"Usage: ornn admin downtime list [--organization UUID] [--status all|ongoing|resolved] [--query TEXT] [--from TIME] [--to TIME] [--limit N] [--cursor CURSOR]";
|
|
313
|
+
const { options, positionals } = parseOptions(
|
|
314
|
+
argv,
|
|
315
|
+
new Set(["organization", "status", "query", "from", "to", "limit", "cursor"]),
|
|
316
|
+
usage
|
|
317
|
+
);
|
|
318
|
+
noPositionals(positionals, usage);
|
|
319
|
+
if (options.status) enumValue(options.status, "status", ["all", "ongoing", "resolved"], usage);
|
|
320
|
+
return {
|
|
321
|
+
input: {
|
|
322
|
+
...(options.organization
|
|
323
|
+
? { organizationId: requireUuid(options.organization, "organization", usage) }
|
|
324
|
+
: {}),
|
|
325
|
+
...(options.status ? { status: options.status } : {}),
|
|
326
|
+
...(options.query ? { q: options.query } : {}),
|
|
327
|
+
...(options.from ? { from: options.from } : {}),
|
|
328
|
+
...(options.to ? { to: options.to } : {}),
|
|
329
|
+
...(options.limit ? { limit: integerValue(options.limit, "limit", usage, { min: 1, max: 100 }) } : {}),
|
|
330
|
+
...(options.cursor ? { cursor: options.cursor } : {}),
|
|
331
|
+
},
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function parseDowntimeCreate(argv) {
|
|
336
|
+
const usage = `Usage: ornn admin downtime create ${DOWNTIME_FIELDS}`;
|
|
337
|
+
const { options, positionals } = parseOptions(
|
|
338
|
+
argv,
|
|
339
|
+
new Set(["organization", "service", "affected", "summary", "notes", "started", "ended", "idempotency-key"]),
|
|
340
|
+
usage
|
|
341
|
+
);
|
|
342
|
+
noPositionals(positionals, usage);
|
|
343
|
+
requireDowntimeText(options, usage);
|
|
344
|
+
return { input: downtimeBody(options, usage), idempotencyKey: options["idempotency-key"] };
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function parseDowntimeUpdate(argv) {
|
|
348
|
+
const usage = `Usage: ornn admin downtime update <incident-id> --version N ${DOWNTIME_UPDATE_FIELDS}`;
|
|
349
|
+
const { options, positionals } = parseOptions(
|
|
350
|
+
argv,
|
|
351
|
+
new Set([
|
|
352
|
+
"version",
|
|
353
|
+
"organization",
|
|
354
|
+
"service",
|
|
355
|
+
"affected",
|
|
356
|
+
"summary",
|
|
357
|
+
"notes",
|
|
358
|
+
"started",
|
|
359
|
+
"ended",
|
|
360
|
+
"idempotency-key",
|
|
361
|
+
]),
|
|
362
|
+
usage
|
|
363
|
+
);
|
|
364
|
+
requireDowntimeText(options, usage);
|
|
365
|
+
if (!options.version) throw usageError(`${usage}\n--version is required.`, "version");
|
|
366
|
+
return {
|
|
367
|
+
input: {
|
|
368
|
+
id: requireUuid(onePositional(positionals, usage, "incident-id"), "incident-id", usage),
|
|
369
|
+
version: integerValue(options.version, "version", usage, { min: 1 }),
|
|
370
|
+
...downtimeBody(options, usage, { notesRequired: true, endedRequired: true }),
|
|
371
|
+
},
|
|
372
|
+
idempotencyKey: options["idempotency-key"],
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const WRITE_CONSEQUENCE = {
|
|
377
|
+
"node.deploy": "This node will be deployed to the selected tenant.",
|
|
378
|
+
"node.update": "The supplied node fields will be saved.",
|
|
379
|
+
"agent-update.request": "This agent version will be requested for the node.",
|
|
380
|
+
"test-pool.update": "The test pool will be resized. Shrinking deletes pool resources.",
|
|
381
|
+
"test-pool.run.create": "A test-pool run will be created and expires with its TTL.",
|
|
382
|
+
"test-pool.run.delete": "This test-pool run and its resources will be deleted.",
|
|
383
|
+
"downtime.create": "This customer downtime incident will be recorded.",
|
|
384
|
+
"downtime.update": "This downtime incident will be replaced with the supplied fields.",
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
function reviewFor(capabilityId, input) {
|
|
388
|
+
const consequence = WRITE_CONSEQUENCE[capabilityId];
|
|
389
|
+
if (!consequence) {
|
|
390
|
+
throw new AdminMutationError("Admin mutation review is incomplete.", {
|
|
391
|
+
code: "admin_review_incomplete",
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
const fields = Object.entries(input).map(([label, value]) => ({
|
|
395
|
+
label,
|
|
396
|
+
value:
|
|
397
|
+
label === "gpuType" && value === ""
|
|
398
|
+
? "cleared"
|
|
399
|
+
: label === "endedAt" && value === null
|
|
400
|
+
? "open"
|
|
401
|
+
: value,
|
|
402
|
+
}));
|
|
403
|
+
return { title: capabilityId, fields, consequence };
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function command(capabilityId, parse, write = false) {
|
|
407
|
+
return {
|
|
408
|
+
capabilityId,
|
|
409
|
+
...(write ? { safety: ADMIN_MUTATION_SAFETY.eligibleHumanOnly } : {}),
|
|
410
|
+
parse: (argv) => {
|
|
411
|
+
const parsed = parse(argv);
|
|
412
|
+
return {
|
|
413
|
+
input: parsed.input,
|
|
414
|
+
...(write
|
|
415
|
+
? {
|
|
416
|
+
mutation: {
|
|
417
|
+
idempotencyKey: parsed.idempotencyKey,
|
|
418
|
+
safety: ADMIN_MUTATION_SAFETY.eligibleHumanOnly,
|
|
419
|
+
},
|
|
420
|
+
}
|
|
421
|
+
: {}),
|
|
422
|
+
};
|
|
423
|
+
},
|
|
424
|
+
run: async ({ input, runtime, execute }) => {
|
|
425
|
+
if (!write) {
|
|
426
|
+
return {
|
|
427
|
+
data: await execute(input),
|
|
428
|
+
exitCode: 0,
|
|
429
|
+
outcome: { class: "ready", phase: "complete" },
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
const result = await runAdminMutation({
|
|
433
|
+
...runtime,
|
|
434
|
+
safety: ADMIN_MUTATION_SAFETY.eligibleHumanOnly,
|
|
435
|
+
stdout: runtime.stderr,
|
|
436
|
+
prepare: async () => ({ review: reviewFor(capabilityId, input), value: input }),
|
|
437
|
+
execute: async () => execute(input, { confirmed: true }),
|
|
438
|
+
});
|
|
439
|
+
return { data: result.data, exitCode: 0, outcome: result.outcome };
|
|
440
|
+
},
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export const adminFleetHandlers = [
|
|
445
|
+
command("node.deploy", parseDeploy, true),
|
|
446
|
+
command("node.update", parseUpdate, true),
|
|
447
|
+
command("agent-update.request", parseAgentUpdate, true),
|
|
448
|
+
command("maintenance-history.list", parseMaintenance),
|
|
449
|
+
command("maintenance-history.get", parseRecord),
|
|
450
|
+
command("test-pool.get", parsePoolGet),
|
|
451
|
+
command("test-pool.update", parsePoolUpdate, true),
|
|
452
|
+
command("test-pool.run.list", parsePoolRuns),
|
|
453
|
+
command("test-pool.run.create", parsePoolCreate, true),
|
|
454
|
+
command("test-pool.run.delete", parsePoolDelete, true),
|
|
455
|
+
command("downtime.list", parseDowntimeList),
|
|
456
|
+
command("downtime.create", parseDowntimeCreate, true),
|
|
457
|
+
command("downtime.update", parseDowntimeUpdate, true),
|
|
458
|
+
];
|
package/src/admin-shell.mjs
CHANGED
|
@@ -185,7 +185,17 @@ function parseAdminInput(capability, argv) {
|
|
|
185
185
|
const allowed = [...help.human.matchAll(/--([a-z0-9-]+)/g)].map((match) => match[1]);
|
|
186
186
|
const { options, positionals } = parseOptions(argv, allowed, usage);
|
|
187
187
|
const nodeCommand = (help.acceptedReferences ?? []).includes("canonical node ID");
|
|
188
|
-
|
|
188
|
+
const singleIdFields = {
|
|
189
|
+
"admin nodes test-result": "job_id",
|
|
190
|
+
"admin nodes diagnosis show": "id",
|
|
191
|
+
};
|
|
192
|
+
const idField = singleIdFields[command];
|
|
193
|
+
if (idField) {
|
|
194
|
+
if (positionals.length !== 1) throw new AdminUsageError(usage);
|
|
195
|
+
} else if (
|
|
196
|
+
(nodeCommand && positionals.length !== 1) ||
|
|
197
|
+
(!nodeCommand && positionals.length !== 0)
|
|
198
|
+
) {
|
|
189
199
|
throw new AdminUsageError(usage);
|
|
190
200
|
}
|
|
191
201
|
|
|
@@ -205,6 +215,7 @@ function parseAdminInput(capability, argv) {
|
|
|
205
215
|
positiveInteger(options.limit, "limit", maxLimit) ??
|
|
206
216
|
(directoryPagination ? 25 : DEFAULT_PAGE_LIMIT);
|
|
207
217
|
const input = {};
|
|
218
|
+
if (idField) input[idField] = positionals[0];
|
|
208
219
|
if (nodeCommand) input.node_id = positionals[0];
|
|
209
220
|
if (capability.id === "organization.list") {
|
|
210
221
|
const supplier = booleanOption(options.supplier, "supplier");
|
|
@@ -232,7 +243,9 @@ function parseAdminInput(capability, argv) {
|
|
|
232
243
|
if (options.end) input.end = options.end;
|
|
233
244
|
if (options.before) input.before = options.before;
|
|
234
245
|
if (options.stream) input.stream = options.stream;
|
|
235
|
-
if (options.cursor &&
|
|
246
|
+
if (options.cursor && ["admin nodes logs", "admin nodes diagnosis list"].includes(command)) {
|
|
247
|
+
input.cursor = options.cursor;
|
|
248
|
+
}
|
|
236
249
|
const maxPoints = positiveInteger(options["max-points"], "max-points", 500);
|
|
237
250
|
if (maxPoints !== undefined) input.max_points = maxPoints;
|
|
238
251
|
const count = positiveInteger(options.count, "count", 500);
|
package/src/catalog-shell.mjs
CHANGED
|
@@ -777,27 +777,122 @@ const DIRECT_GATEWAY_PREFIXES = [
|
|
|
777
777
|
];
|
|
778
778
|
const DIRECT_GATEWAY_PATHS = new Set(["/v1/orchestrator/supplier-gateway-regions"]);
|
|
779
779
|
|
|
780
|
-
|
|
780
|
+
// Same 1:1 owner set as apps/mcp/lib/tools/admin.ts isDirectOrchestratorOwnerPath.
|
|
781
|
+
const STAFF_ORCHESTRATOR_ROOTS = new Set([
|
|
782
|
+
"allocations",
|
|
783
|
+
"agent-releases",
|
|
784
|
+
"customer-profiles",
|
|
785
|
+
"diagnosis-remote",
|
|
786
|
+
"fake-remote-run",
|
|
787
|
+
"force-updates",
|
|
788
|
+
"images",
|
|
789
|
+
"maintenance-history",
|
|
790
|
+
"remote",
|
|
791
|
+
"ssh-bastions",
|
|
792
|
+
"supplier-node-configs",
|
|
793
|
+
"virtual-machines",
|
|
794
|
+
]);
|
|
795
|
+
const STAFF_NODE_ACTIONS = new Set([
|
|
796
|
+
"assign",
|
|
797
|
+
"authenticate",
|
|
798
|
+
"clean",
|
|
799
|
+
"detach",
|
|
800
|
+
"keys",
|
|
801
|
+
"mark-clean",
|
|
802
|
+
"packet-key",
|
|
803
|
+
"sanitize-drives",
|
|
804
|
+
"ssh-relay",
|
|
805
|
+
"terminate",
|
|
806
|
+
"transfer",
|
|
807
|
+
"update",
|
|
808
|
+
"virtual-machine-capacity",
|
|
809
|
+
]);
|
|
810
|
+
const RESERVATION_STAFF_ACTIONS = new Set([
|
|
811
|
+
"apply-owner",
|
|
812
|
+
"node-rollout",
|
|
813
|
+
"notices",
|
|
814
|
+
"operations",
|
|
815
|
+
"runtime-lease",
|
|
816
|
+
]);
|
|
817
|
+
|
|
818
|
+
function isDirectOrchestratorOwnerPath(pathname, method) {
|
|
819
|
+
if (!pathname.startsWith("/v1/orchestrator/")) return false;
|
|
820
|
+
const segments = pathname.slice("/v1/orchestrator/".length).split("/").filter(Boolean);
|
|
821
|
+
const [root, second, third, fourth] = segments;
|
|
822
|
+
if (!root) return false;
|
|
823
|
+
if (STAFF_ORCHESTRATOR_ROOTS.has(root)) return true;
|
|
824
|
+
if (root === "nodes" && segments.length === 1) return method === "GET" || method === "HEAD";
|
|
825
|
+
if (root === "nodes" && second === "ghost") return true;
|
|
826
|
+
if (root === "nodes" && second && segments.length === 2) return true;
|
|
827
|
+
if (root === "nodes" && second && third === "virtual-machines" && segments.length === 3) {
|
|
828
|
+
return method !== "GET" && method !== "HEAD";
|
|
829
|
+
}
|
|
830
|
+
if (
|
|
831
|
+
root === "nodes" &&
|
|
832
|
+
second &&
|
|
833
|
+
third === "virtual-machines" &&
|
|
834
|
+
fourth &&
|
|
835
|
+
segments.length === 4 &&
|
|
836
|
+
method === "DELETE"
|
|
837
|
+
) {
|
|
838
|
+
return true;
|
|
839
|
+
}
|
|
840
|
+
if (root === "nodes" && second && segments.length === 3 && STAFF_NODE_ACTIONS.has(third)) {
|
|
841
|
+
return true;
|
|
842
|
+
}
|
|
843
|
+
if (root === "nodes" && second && third === "sanitize-drives" && fourth) return true;
|
|
844
|
+
if (root === "controllers" && second && segments.length === 2) return true;
|
|
845
|
+
if (root === "disk-build-workers" && segments.length <= 2) return true;
|
|
846
|
+
if (
|
|
847
|
+
root === "drives" &&
|
|
848
|
+
(second === "provisioning" || second === "transfers") &&
|
|
849
|
+
segments.length === 2
|
|
850
|
+
) {
|
|
851
|
+
return true;
|
|
852
|
+
}
|
|
853
|
+
if (root === "networks" && second === "provisioning" && segments.length === 2) return true;
|
|
854
|
+
if (root === "drives" && second && third === "filestore") return true;
|
|
855
|
+
if (root === "networks" && second && third === "gateway") return true;
|
|
856
|
+
if (root === "storage" && (second === "organizations" || second === "volumes")) return true;
|
|
857
|
+
if (root === "reservations" && second && third && RESERVATION_STAFF_ACTIONS.has(third)) {
|
|
858
|
+
return true;
|
|
859
|
+
}
|
|
860
|
+
return false;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
function isDirectOwnerSessionPath(pathname, method) {
|
|
864
|
+
return (
|
|
865
|
+
pathname === "/v1/benchmark" ||
|
|
866
|
+
pathname.startsWith("/v1/benchmark/") ||
|
|
867
|
+
pathname === "/v1/observability" ||
|
|
868
|
+
pathname.startsWith("/v1/observability/") ||
|
|
869
|
+
isDirectOrchestratorOwnerPath(pathname, method)
|
|
870
|
+
);
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
function isDirectGatewayPath(path, method = "GET") {
|
|
781
874
|
const pathname = String(path).split("?")[0];
|
|
782
875
|
return (
|
|
783
876
|
DIRECT_GATEWAY_PATHS.has(pathname) ||
|
|
784
877
|
DIRECT_GATEWAY_PREFIXES.some(
|
|
785
878
|
(prefix) => pathname === prefix || pathname.startsWith(`${prefix}/`)
|
|
786
|
-
)
|
|
879
|
+
) ||
|
|
880
|
+
isDirectOwnerSessionPath(pathname, method)
|
|
787
881
|
);
|
|
788
882
|
}
|
|
789
883
|
|
|
790
884
|
function adminFetch(io, path, init = {}) {
|
|
885
|
+
const method = init.method ?? "GET";
|
|
791
886
|
const request = {
|
|
792
887
|
endpoint: path,
|
|
793
888
|
env: io.env,
|
|
794
889
|
fetchImpl: io.fetchImpl,
|
|
795
|
-
method
|
|
890
|
+
method,
|
|
796
891
|
...(init.body !== undefined ? { body: init.body } : {}),
|
|
797
892
|
...(init.headers !== undefined ? { headers: init.headers } : {}),
|
|
798
893
|
...((init.signal ?? io.signal) !== undefined ? { signal: init.signal ?? io.signal } : {}),
|
|
799
894
|
};
|
|
800
|
-
return isDirectGatewayPath(path) || (path === "/v1/staff/invites" &&
|
|
895
|
+
return isDirectGatewayPath(path, method) || (path === "/v1/staff/invites" && method === "POST")
|
|
801
896
|
? cliRequest(request)
|
|
802
897
|
: operatorRequest(request);
|
|
803
898
|
}
|
|
@@ -957,15 +1052,7 @@ async function executeCapability(
|
|
|
957
1052
|
customerCapabilityFetch(io, path, init, authSnapshot, true),
|
|
958
1053
|
fetch: async (path, init = {}) => {
|
|
959
1054
|
if (executionRuntime?.transport) return executionRuntime.transport(path, init);
|
|
960
|
-
if (audience === "admin")
|
|
961
|
-
// Shared observability capabilities use their owner namespace;
|
|
962
|
-
// the CLI reaches those same node-scoped routes through staff auth.
|
|
963
|
-
const endpoint =
|
|
964
|
-
capability.id === "telemetry.latest" || capability.id === "logs.latest"
|
|
965
|
-
? path.replace(/^\/v1\/observability\//, "/")
|
|
966
|
-
: path;
|
|
967
|
-
return adminFetch(io, endpoint, init);
|
|
968
|
-
}
|
|
1055
|
+
if (audience === "admin") return adminFetch(io, path, init);
|
|
969
1056
|
if (capability.domain === "listings" && listingSession === undefined) {
|
|
970
1057
|
// Resolve listing visibility before the request, never after a committed mutation.
|
|
971
1058
|
listingSession = await getCliSession((path, init) =>
|