@ornncompute/cli 1.0.325 → 1.0.327
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 +7 -4
- package/package.json +1 -1
- package/src/api-client.mjs +4 -2
- package/src/catalog-shell.mjs +27 -7
- package/src/connect-mode-handlers.mjs +27 -5
- package/src/machine-reference.mjs +7 -4
- package/src/network-commands.mjs +32 -1
package/README.md
CHANGED
|
@@ -88,9 +88,9 @@ ornn completion <bash|fish|zsh> --format human
|
|
|
88
88
|
ornn resources
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
With a login session, the CLI
|
|
92
|
-
approval. `ornn context` displays that
|
|
93
|
-
|
|
91
|
+
With a login session, the CLI defaults to Authorization's newest membership, regardless of
|
|
92
|
+
approval. `ornn context` displays that organization. Reserve browsing and purchasing still
|
|
93
|
+
require approval.
|
|
94
94
|
|
|
95
95
|
Node and VM requests use `@ornn/api-client/orchestrator`; CLI selection, polling,
|
|
96
96
|
and SSH remain here. VM readiness comes from the guest resource, separately from
|
|
@@ -98,7 +98,10 @@ physical-host readiness. Bare Metal uses the node's SSH endpoint and waits
|
|
|
98
98
|
when the service reports that the endpoint is unavailable. VM and Bare Metal
|
|
99
99
|
`connect` use the CLI's own key (`connect_ed25519` in the config directory),
|
|
100
100
|
saved as the user's `ornn connect (<email>)` organization key and assigned to the
|
|
101
|
-
reservation
|
|
101
|
+
reservation. When you give `ornn connect` a target, it checks your organizations
|
|
102
|
+
and uses the unique match's organization for the connection. VPN recovery uses
|
|
103
|
+
the reservation's owning organization. `--identity-file`
|
|
104
|
+
applies only to Slurm. See
|
|
102
105
|
[machine behavior](../../docs/cli.md#customer-workflows).
|
|
103
106
|
|
|
104
107
|
Directory-enabled Slurm access requires `ornn connect <cluster-id> --user <directory-username>`
|
package/package.json
CHANGED
package/src/api-client.mjs
CHANGED
|
@@ -79,11 +79,12 @@ export async function loadRequiredSession({ env = process.env } = {}) {
|
|
|
79
79
|
}
|
|
80
80
|
return session;
|
|
81
81
|
}
|
|
82
|
-
export function userCredentialHeaders(session) {
|
|
82
|
+
export function userCredentialHeaders(session, organizationId) {
|
|
83
83
|
if (!session?.accessToken) return {};
|
|
84
84
|
return userGatewayHeaders({
|
|
85
85
|
token: session.accessToken,
|
|
86
86
|
actor: "cli",
|
|
87
|
+
organizationId,
|
|
87
88
|
clientVersion: CLI_VERSION,
|
|
88
89
|
});
|
|
89
90
|
}
|
|
@@ -96,6 +97,7 @@ export async function cliRequest({
|
|
|
96
97
|
env = process.env,
|
|
97
98
|
fetchImpl = fetch,
|
|
98
99
|
method = "GET",
|
|
100
|
+
organizationId,
|
|
99
101
|
raw = false,
|
|
100
102
|
returnResponse = false,
|
|
101
103
|
session,
|
|
@@ -125,7 +127,7 @@ export async function cliRequest({
|
|
|
125
127
|
delete headers[name];
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
|
-
Object.assign(headers, userCredentialHeaders(authSession));
|
|
130
|
+
Object.assign(headers, userCredentialHeaders(authSession, organizationId));
|
|
129
131
|
|
|
130
132
|
let requestBody;
|
|
131
133
|
if (body !== undefined) {
|
package/src/catalog-shell.mjs
CHANGED
|
@@ -903,7 +903,7 @@ async function customerCapabilityFetch(
|
|
|
903
903
|
path,
|
|
904
904
|
init = {},
|
|
905
905
|
sessionSnapshot,
|
|
906
|
-
returnResponse = false
|
|
906
|
+
{ organizationId, returnResponse = false } = {}
|
|
907
907
|
) {
|
|
908
908
|
const authRequired = path !== "/v1/cli/status";
|
|
909
909
|
const session = sessionSnapshot?.current;
|
|
@@ -931,6 +931,7 @@ async function customerCapabilityFetch(
|
|
|
931
931
|
fetchImpl: io.fetchImpl,
|
|
932
932
|
headers: init.headers,
|
|
933
933
|
method,
|
|
934
|
+
organizationId,
|
|
934
935
|
...(authRequired && session ? { session } : {}),
|
|
935
936
|
...(init.body !== undefined ? { body: init.body } : {}),
|
|
936
937
|
signal: init.signal ?? io.signal,
|
|
@@ -1057,7 +1058,7 @@ async function executeCapability(
|
|
|
1057
1058
|
webBaseUrl: resolveAuthBaseUrl({ env: io.env }),
|
|
1058
1059
|
role,
|
|
1059
1060
|
fetchResponse: (path, init = {}) =>
|
|
1060
|
-
customerCapabilityFetch(io, path, init, authSnapshot, true),
|
|
1061
|
+
customerCapabilityFetch(io, path, init, authSnapshot, { returnResponse: true }),
|
|
1061
1062
|
fetch: async (path, init = {}) => {
|
|
1062
1063
|
if (executionRuntime?.transport) return executionRuntime.transport(path, init);
|
|
1063
1064
|
if (audience === "admin") return adminFetch(io, path, init);
|
|
@@ -1302,6 +1303,12 @@ export async function runCatalogCli(argv, io, { version }) {
|
|
|
1302
1303
|
}
|
|
1303
1304
|
|
|
1304
1305
|
const authSnapshot = {};
|
|
1306
|
+
const scopeOrganization = (context, organizationId) => ({
|
|
1307
|
+
...context,
|
|
1308
|
+
organizationId,
|
|
1309
|
+
fetch: (path, init) =>
|
|
1310
|
+
customerCapabilityFetch(io, path, init, authSnapshot, { organizationId }),
|
|
1311
|
+
});
|
|
1305
1312
|
const directConnectOptions = {
|
|
1306
1313
|
env: io.env,
|
|
1307
1314
|
now: io.now,
|
|
@@ -1345,6 +1352,7 @@ export async function runCatalogCli(argv, io, { version }) {
|
|
|
1345
1352
|
...(io.launchModeHandlers ?? []),
|
|
1346
1353
|
]),
|
|
1347
1354
|
networks: executeNetworkCommand,
|
|
1355
|
+
scopeOrganization,
|
|
1348
1356
|
sshKeys: (command, input, context) =>
|
|
1349
1357
|
executeSshKeyCommand(command, input, context, context.cli.interaction),
|
|
1350
1358
|
machines: (command, input, context) =>
|
|
@@ -1358,16 +1366,28 @@ export async function runCatalogCli(argv, io, { version }) {
|
|
|
1358
1366
|
stderr,
|
|
1359
1367
|
stdout,
|
|
1360
1368
|
}),
|
|
1361
|
-
resolveConnectTarget
|
|
1362
|
-
|
|
1369
|
+
async resolveConnectTarget(state) {
|
|
1370
|
+
if (io.connectModeHandlers) {
|
|
1371
|
+
return resolveConnectTargetWithHandlers(state, io.connectModeHandlers);
|
|
1372
|
+
}
|
|
1373
|
+
const { organizations = [] } = state.reference
|
|
1374
|
+
? await getCliSession(state.context.fetch)
|
|
1375
|
+
: {};
|
|
1376
|
+
const scopes = organizations.map((organization) => ({
|
|
1377
|
+
organization,
|
|
1378
|
+
context: scopeOrganization(state.context, organization.id),
|
|
1379
|
+
}));
|
|
1380
|
+
return resolveConnectTargetWithHandlers(
|
|
1363
1381
|
state,
|
|
1364
|
-
|
|
1382
|
+
[
|
|
1365
1383
|
createSlurmConnectModeHandler({ spawnProcess: io.spawnProcess }),
|
|
1366
1384
|
createBareMetalConnectModeHandler(directConnectOptions),
|
|
1367
1385
|
createVmConnectModeHandler(directConnectOptions),
|
|
1368
1386
|
kubernetesConnectModeHandler,
|
|
1369
|
-
]
|
|
1370
|
-
|
|
1387
|
+
],
|
|
1388
|
+
scopes
|
|
1389
|
+
);
|
|
1390
|
+
},
|
|
1371
1391
|
async continueConnect(state) {
|
|
1372
1392
|
if (io.connectModeHandlers) {
|
|
1373
1393
|
return continueConnectWithHandlers(state, io.connectModeHandlers);
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* authoritative server facts; target spelling is never a mode selector.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import { canonicalMachineId } from "./machine-reference.mjs";
|
|
13
|
+
|
|
12
14
|
function resolverErrorPriority(error) {
|
|
13
15
|
if (Number(error?.exitCode) === 2) return 2;
|
|
14
16
|
const status = Number(error?.status);
|
|
@@ -68,7 +70,7 @@ async function validateConnectModeInput(state, handler, resolved) {
|
|
|
68
70
|
}
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
export async function resolveConnectTargetWithHandlers(state, handlers = []) {
|
|
73
|
+
export async function resolveConnectTargetWithHandlers(state, handlers = [], scopes = []) {
|
|
72
74
|
for (const handler of handlers) {
|
|
73
75
|
if (
|
|
74
76
|
!handler ||
|
|
@@ -134,16 +136,36 @@ export async function resolveConnectTargetWithHandlers(state, handlers = []) {
|
|
|
134
136
|
}
|
|
135
137
|
}
|
|
136
138
|
|
|
139
|
+
const matches = [];
|
|
140
|
+
for (const { organization, context } of scopes.length ? scopes : [state]) {
|
|
141
|
+
const match = await findConnectTarget({ ...state, context }, handlers);
|
|
142
|
+
if (match) matches.push({ ...match, organization });
|
|
143
|
+
}
|
|
144
|
+
if (matches.length > 1) {
|
|
145
|
+
const candidates = matches.map(({ resolved, organization }) => {
|
|
146
|
+
const id =
|
|
147
|
+
canonicalMachineId(resolved.virtualMachine ?? resolved.machine) ?? resolved.cluster?.id;
|
|
148
|
+
return `${organization.name} (${id})`;
|
|
149
|
+
});
|
|
150
|
+
state.interaction.usage(
|
|
151
|
+
`This target matches more than one organization (${candidates.join(", ")}). Use the exact machine or cluster ID.`,
|
|
152
|
+
{ code: "connect_target_ambiguous", field: "machine" }
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
const match = matches[0];
|
|
156
|
+
if (!match) return null;
|
|
157
|
+
await validateConnectModeInput(state, match.handler, match.resolved);
|
|
158
|
+
return match.resolved;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function findConnectTarget(state, handlers) {
|
|
137
162
|
let strongestError = null;
|
|
138
163
|
let strongestPriority = 0;
|
|
139
164
|
for (const handler of handlers) {
|
|
140
165
|
if (handler.resolve === undefined) continue;
|
|
141
166
|
try {
|
|
142
167
|
const resolved = await handler.resolve(state);
|
|
143
|
-
if (resolved) {
|
|
144
|
-
await validateConnectModeInput(state, handler, resolved);
|
|
145
|
-
return resolved;
|
|
146
|
-
}
|
|
168
|
+
if (resolved) return { handler, resolved };
|
|
147
169
|
} catch (error) {
|
|
148
170
|
const priority = resolverErrorPriority(error);
|
|
149
171
|
if (priority > strongestPriority) {
|
|
@@ -115,10 +115,13 @@ function invalidGateway(interaction, message) {
|
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
export async function listActiveReservations(context, interaction) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
118
|
+
let customerId = context.organizationId;
|
|
119
|
+
if (!customerId) {
|
|
120
|
+
const session = context.cli?.session
|
|
121
|
+
? (await context.cli.session("context", {})).data
|
|
122
|
+
: await getCliSession(context.fetch);
|
|
123
|
+
customerId = text((session.selectedOrganization ?? session.selected_organization)?.id);
|
|
124
|
+
}
|
|
122
125
|
if (!customerId) {
|
|
123
126
|
interaction.usage("Select an organization before choosing a reservation.", {
|
|
124
127
|
code: "organization_required",
|
package/src/network-commands.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getCliSession } from "../vendor/api-client/authorization.js";
|
|
1
2
|
import { getReservation } from "../vendor/api-client/commerce.js";
|
|
2
3
|
import {
|
|
3
4
|
privateNetworkCreateCapability,
|
|
@@ -541,6 +542,30 @@ async function listVpnPayloads(context) {
|
|
|
541
542
|
return vpnPayloadRows(await vpnConnectionListCapability.execute(context, {}));
|
|
542
543
|
}
|
|
543
544
|
|
|
545
|
+
async function vpnReservationContext(context, reservationId) {
|
|
546
|
+
const runtime = interaction(context);
|
|
547
|
+
const { organizations = [] } = await getCliSession(context.fetch);
|
|
548
|
+
for (const { id } of organizations) {
|
|
549
|
+
const scoped = runtime.scopeOrganization(context, id);
|
|
550
|
+
let reservation;
|
|
551
|
+
try {
|
|
552
|
+
reservation = await getReservation(scoped.fetch, reservationId);
|
|
553
|
+
} catch (error) {
|
|
554
|
+
if (responseStatus(error) === 404) continue;
|
|
555
|
+
throw error;
|
|
556
|
+
}
|
|
557
|
+
if (reservation.reservationId?.toLowerCase() !== reservationId.toLowerCase()) {
|
|
558
|
+
runtime.error("The gateway returned a different capacity reservation.", {
|
|
559
|
+
code: "reservation_correlation_changed",
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
if (reservation.customerId === id) return scoped;
|
|
563
|
+
}
|
|
564
|
+
runtime.error("No reservation with that ID belongs to one of your organizations.", {
|
|
565
|
+
code: "reservation_not_found",
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
|
|
544
569
|
async function listVpnConnections(context, input) {
|
|
545
570
|
const runtime = interaction(context);
|
|
546
571
|
const [rawTarget] = exactPositionals(
|
|
@@ -550,6 +575,7 @@ async function listVpnConnections(context, input) {
|
|
|
550
575
|
"Usage: ornn vpn-connections list <canonical-reservation-id> [--limit <1-500>] [--cursor <cursor>]"
|
|
551
576
|
);
|
|
552
577
|
const target = requireCanonicalTarget(runtime, rawTarget);
|
|
578
|
+
context = await vpnReservationContext(context, target);
|
|
553
579
|
const connections = (await listVpnPayloads(context))
|
|
554
580
|
.map((payload) => projectVpnConnection(payload, target))
|
|
555
581
|
.sort((left, right) =>
|
|
@@ -735,6 +761,7 @@ async function configureVpnConnection(context, input) {
|
|
|
735
761
|
runtime.error(message, { code: code ?? "invalid_wireguard_private_key", field: "privateKey" });
|
|
736
762
|
}
|
|
737
763
|
const idempotencyKey = requireMutationKey(runtime, input);
|
|
764
|
+
context = await vpnReservationContext(context, target);
|
|
738
765
|
const existing = await listVpnPayloads(context);
|
|
739
766
|
const sameKey = existing.find((payload) => text(vpnPeer(payload).public_key) === publicKey);
|
|
740
767
|
let effectiveName = name;
|
|
@@ -811,6 +838,7 @@ async function disconnectVpnConnection(context, input) {
|
|
|
811
838
|
);
|
|
812
839
|
const target = requireCanonicalTarget(runtime, rawTarget);
|
|
813
840
|
const idempotencyKey = requireMutationKey(runtime, input);
|
|
841
|
+
context = await vpnReservationContext(context, target);
|
|
814
842
|
const matches = (await listVpnPayloads(context)).filter((payload) => {
|
|
815
843
|
const peer = vpnPeer(payload);
|
|
816
844
|
return CANONICAL_ID.test(reference)
|
|
@@ -933,7 +961,10 @@ async function connectPrivateTarget(context, input) {
|
|
|
933
961
|
const direct = await runtime.continueConnect(resolved);
|
|
934
962
|
if (direct) return runtime.result(direct);
|
|
935
963
|
}
|
|
936
|
-
if (resolved)
|
|
964
|
+
if (resolved) {
|
|
965
|
+
target = resolved.reservationId;
|
|
966
|
+
context = resolved.context ?? context;
|
|
967
|
+
}
|
|
937
968
|
}
|
|
938
969
|
if (!resolved && rawTarget && CANONICAL_ID.test(rawTarget)) {
|
|
939
970
|
try {
|