@infernetprotocol/deploy-providers 0.1.22 → 0.1.25
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/package.json +2 -2
- package/src/digitalocean.js +258 -0
- package/src/index.js +96 -13
- package/src/pricing.js +6 -1
- package/src/providers/crusoe.js +278 -0
- package/src/providers/datacrunch.js +301 -0
- package/src/providers/hyperstack.js +277 -0
- package/src/providers/lambda.js +396 -0
- package/src/providers/runpod.js +382 -0
- package/src/providers/tensordock.js +362 -0
- package/src/providers/voltagepark.js +281 -0
- package/src/vast.js +245 -0
- package/src/vllm-bootstrap.js +145 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hyperstack adapter — IPIP-0019 DeployProvider implementation.
|
|
3
|
+
*
|
|
4
|
+
* REST API: https://infrahub-api.nexgencloud.com/v1
|
|
5
|
+
* Docs: https://infrahub-doc.nexgencloud.com/
|
|
6
|
+
* Auth: api_key header (Bearer-style token, but sent as `api_key`).
|
|
7
|
+
*
|
|
8
|
+
* VM-based with cloud-init via the `user_data` field on
|
|
9
|
+
* POST /core/virtual-machines.
|
|
10
|
+
*
|
|
11
|
+
* Verified against current docs: 2026-05-01.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { DeployProvider, NotSupportedError } from "./base.js";
|
|
15
|
+
import { canonicalize, aliasesFor } from "../gpu-normalize.js";
|
|
16
|
+
import * as state from "../state.js";
|
|
17
|
+
import { composeInstallScript, pollVllmHealth } from "../vllm-bootstrap.js";
|
|
18
|
+
|
|
19
|
+
const API_BASE = "https://infrahub-api.nexgencloud.com/v1";
|
|
20
|
+
const DEFAULT_INSTALLER = process.env.INFERNET_INSTALLER_URL ?? "https://infernetprotocol.com/install.sh";
|
|
21
|
+
|
|
22
|
+
export class HyperstackProvider extends DeployProvider {
|
|
23
|
+
constructor(config = {}) {
|
|
24
|
+
super({ ...config, providerId: "hyperstack" });
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async _request(method, path, body) {
|
|
28
|
+
const res = await fetch(`${API_BASE}${path}`, {
|
|
29
|
+
method,
|
|
30
|
+
headers: {
|
|
31
|
+
"api_key": this.config.apiKey,
|
|
32
|
+
"Content-Type": "application/json",
|
|
33
|
+
"Accept": "application/json"
|
|
34
|
+
},
|
|
35
|
+
body: body ? JSON.stringify(body) : undefined
|
|
36
|
+
});
|
|
37
|
+
const json = await res.json().catch(() => ({}));
|
|
38
|
+
if (!res.ok || json?.status === false) {
|
|
39
|
+
const msg = json?.message ?? json?.error ?? res.statusText ?? `HTTP ${res.status}`;
|
|
40
|
+
const err = new Error(`Hyperstack API error: ${msg}`);
|
|
41
|
+
err.status = res.status;
|
|
42
|
+
err.body = json;
|
|
43
|
+
throw err;
|
|
44
|
+
}
|
|
45
|
+
return json;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async validateAuth() {
|
|
49
|
+
// /core/profile returns the authenticated user info.
|
|
50
|
+
const data = await this._request("GET", "/core/profile");
|
|
51
|
+
if (!data?.profile) throw new Error("Hyperstack: API key invalid");
|
|
52
|
+
return { ok: true, accountInfo: data.profile };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async listGpuTypes() {
|
|
56
|
+
const data = await this._request("GET", "/core/flavors");
|
|
57
|
+
return (data?.data ?? data?.flavors ?? []).map((f) => ({
|
|
58
|
+
id: f.name,
|
|
59
|
+
name: f.gpu ?? f.name,
|
|
60
|
+
vramGb: f.gpu_memory_gb ?? null,
|
|
61
|
+
pricePerHour: f.cost_per_hour ?? null
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async listRegions() {
|
|
66
|
+
const data = await this._request("GET", "/core/regions");
|
|
67
|
+
return (data?.regions ?? data?.data ?? []).map((r) => ({ id: r.name, name: r.name }));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async findOffers(request = {}) {
|
|
71
|
+
const flavors = (await this._request("GET", "/core/flavors"))?.data
|
|
72
|
+
?? (await this._request("GET", "/core/flavors"))?.flavors
|
|
73
|
+
?? [];
|
|
74
|
+
|
|
75
|
+
const wantCanonical = request.gpu ? canonicalize(request.gpu) : null;
|
|
76
|
+
const aliases = wantCanonical
|
|
77
|
+
? [wantCanonical, ...aliasesFor(wantCanonical)].map((a) => a.toLowerCase())
|
|
78
|
+
: null;
|
|
79
|
+
|
|
80
|
+
const offers = [];
|
|
81
|
+
for (const f of flavors) {
|
|
82
|
+
const gpuStr = (f.gpu ?? f.name ?? "").toLowerCase();
|
|
83
|
+
if (aliases && !aliases.some((a) => gpuStr.includes(a))) continue;
|
|
84
|
+
const vramGb = f.gpu_memory_gb ?? 0;
|
|
85
|
+
if (request.vramMin && vramGb < request.vramMin) continue;
|
|
86
|
+
const price = f.cost_per_hour ?? 0;
|
|
87
|
+
if (request.maxPricePerHour != null && price > request.maxPricePerHour) continue;
|
|
88
|
+
|
|
89
|
+
for (const reg of f.regions ?? [f.region].filter(Boolean)) {
|
|
90
|
+
if (request.region && reg !== request.region) continue;
|
|
91
|
+
offers.push({
|
|
92
|
+
providerId: "hyperstack",
|
|
93
|
+
offerId: `${f.name}@${reg}`,
|
|
94
|
+
gpu: { name: f.gpu ?? f.name, count: f.gpu_count ?? 1, vramGb },
|
|
95
|
+
cpu: f.cpu ? { cores: f.cpu } : undefined,
|
|
96
|
+
ramGb: f.ram ?? undefined,
|
|
97
|
+
diskGb: f.disk ?? undefined,
|
|
98
|
+
region: reg,
|
|
99
|
+
pricePerHour: price,
|
|
100
|
+
deployStyle: "vm-ssh",
|
|
101
|
+
available: true,
|
|
102
|
+
raw: { flavor_name: f.name, region: reg, flavor: f }
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return offers;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
_buildUserData(envMap, opts = {}) {
|
|
110
|
+
if (opts.engine === "vllm") {
|
|
111
|
+
return composeInstallScript({ infernetEnv: envMap, vllmConfig: opts.vllmConfig ?? {} });
|
|
112
|
+
}
|
|
113
|
+
const exports = Object.entries(envMap).map(([k, v]) => `export ${k}=${JSON.stringify(String(v))}`).join("\n");
|
|
114
|
+
return ["#!/bin/bash", "set -eux", exports,
|
|
115
|
+
`curl -fsSL ${DEFAULT_INSTALLER} | bash`,
|
|
116
|
+
"infernet register || true", "infernet start || true"].join("\n");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async createNode(request = {}) {
|
|
120
|
+
const {
|
|
121
|
+
gpu, name, flavorName, region, sshKeyName,
|
|
122
|
+
env = {}, controlPlaneUrl = "", engine = "ollama", model = null,
|
|
123
|
+
hourlyPrice = 0, vramGb = 0, gpuCount = 1
|
|
124
|
+
} = request;
|
|
125
|
+
|
|
126
|
+
if (!sshKeyName) {
|
|
127
|
+
throw new Error("hyperstack: createNode requires sshKeyName (upload via /core/keypairs first)");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
let finalFlavor = flavorName;
|
|
131
|
+
let finalRegion = region;
|
|
132
|
+
if (!finalFlavor) {
|
|
133
|
+
const offers = await this.findOffers({ gpu, region });
|
|
134
|
+
if (offers.length === 0) throw new Error(`hyperstack: no flavor matched gpu="${gpu}"`);
|
|
135
|
+
offers.sort((a, b) => a.pricePerHour - b.pricePerHour);
|
|
136
|
+
finalFlavor = offers[0].raw.flavor_name;
|
|
137
|
+
finalRegion = finalRegion ?? offers[0].raw.region;
|
|
138
|
+
}
|
|
139
|
+
if (!finalRegion) throw new Error("hyperstack: createNode requires region");
|
|
140
|
+
|
|
141
|
+
const localId = state.generateNodeId();
|
|
142
|
+
const vmName = name ?? localId;
|
|
143
|
+
|
|
144
|
+
const userData = this._buildUserData({
|
|
145
|
+
INFERNET_NODE_NAME: vmName,
|
|
146
|
+
INFERNET_CONTROL_PLANE_URL: controlPlaneUrl,
|
|
147
|
+
INFERNET_ENGINE: engine,
|
|
148
|
+
...(model ? { INFERNET_MODEL: model } : {}),
|
|
149
|
+
...env
|
|
150
|
+
}, { engine, vllmConfig: { model, ...(request.vllm ?? {}) } });
|
|
151
|
+
|
|
152
|
+
const data = await this._request("POST", "/core/virtual-machines", {
|
|
153
|
+
name: vmName,
|
|
154
|
+
environment_name: finalRegion,
|
|
155
|
+
image_name: "Ubuntu Server 22.04 LTS R535 CUDA 12.2",
|
|
156
|
+
flavor_name: finalFlavor,
|
|
157
|
+
key_name: sshKeyName,
|
|
158
|
+
count: 1,
|
|
159
|
+
assign_floating_ip: true,
|
|
160
|
+
user_data: userData,
|
|
161
|
+
security_rules: [{ direction: "ingress", protocol: "tcp", port_range_min: 46337, port_range_max: 46337 }]
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const vm = data?.instances?.[0] ?? data?.instance ?? data;
|
|
165
|
+
const vmId = vm?.id ?? vm?.uuid;
|
|
166
|
+
if (!vmId) throw new Error("hyperstack: create returned no instance id");
|
|
167
|
+
|
|
168
|
+
const record = {
|
|
169
|
+
id: localId,
|
|
170
|
+
provider: "hyperstack",
|
|
171
|
+
providerNodeId: String(vmId),
|
|
172
|
+
name: vmName,
|
|
173
|
+
gpu: gpu ?? finalFlavor,
|
|
174
|
+
gpuCount,
|
|
175
|
+
vramGb,
|
|
176
|
+
region: finalRegion,
|
|
177
|
+
hourlyPrice,
|
|
178
|
+
engine,
|
|
179
|
+
model: model ?? undefined,
|
|
180
|
+
status: "creating",
|
|
181
|
+
createdAt: new Date().toISOString(),
|
|
182
|
+
controlPlaneUrl
|
|
183
|
+
};
|
|
184
|
+
await state.saveNode(record);
|
|
185
|
+
return record;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async waitUntilReady(node, timeoutMs = 5 * 60 * 1000) {
|
|
189
|
+
if (!node?.providerNodeId) throw new Error("hyperstack: waitUntilReady requires node.providerNodeId");
|
|
190
|
+
const deadline = Date.now() + timeoutMs;
|
|
191
|
+
while (Date.now() < deadline) {
|
|
192
|
+
const data = await this._request("GET", `/core/virtual-machines/${node.providerNodeId}`);
|
|
193
|
+
const vm = data?.instance ?? data;
|
|
194
|
+
const status = (vm?.status ?? "").toUpperCase();
|
|
195
|
+
const ip = vm?.floating_ip ?? vm?.fixed_ip ?? null;
|
|
196
|
+
if (status === "ACTIVE" && ip) {
|
|
197
|
+
const endpointUrl = `http://${ip}:46337`;
|
|
198
|
+
return state.updateNode(node.id, { status: "running", endpointUrl, ip });
|
|
199
|
+
}
|
|
200
|
+
await new Promise((r) => setTimeout(r, 5000));
|
|
201
|
+
}
|
|
202
|
+
await state.updateNode(node.id, { status: "error", error_log: "vm did not reach ACTIVE in time" });
|
|
203
|
+
throw new Error(`Hyperstack VM ${node.providerNodeId} did not reach ACTIVE within ${Math.round(timeoutMs / 1000)}s`);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async bootstrapNode(node, request = {}) {
|
|
207
|
+
if (!node?.endpointUrl && !node?.ip) return { ok: false, reason: "no endpointUrl/ip on node" };
|
|
208
|
+
if ((request.engine ?? node.engine) === "vllm") {
|
|
209
|
+
return pollVllmHealth(node.ip ?? node.endpointUrl, { port: request.vllm?.port ?? 8000 });
|
|
210
|
+
}
|
|
211
|
+
const healthEndpoint = `${node.endpointUrl}/health`;
|
|
212
|
+
const deadline = Date.now() + 5 * 60 * 1000;
|
|
213
|
+
let lastErr = null;
|
|
214
|
+
while (Date.now() < deadline) {
|
|
215
|
+
try {
|
|
216
|
+
const ctrl = new AbortController();
|
|
217
|
+
const t = setTimeout(() => ctrl.abort(), 5000);
|
|
218
|
+
const res = await fetch(healthEndpoint, { signal: ctrl.signal });
|
|
219
|
+
clearTimeout(t);
|
|
220
|
+
if (res.ok) return { ok: true, healthEndpoint };
|
|
221
|
+
lastErr = `HTTP ${res.status}`;
|
|
222
|
+
} catch (err) { lastErr = err?.message ?? String(err); }
|
|
223
|
+
await new Promise((r) => setTimeout(r, 10000));
|
|
224
|
+
}
|
|
225
|
+
return { ok: false, reason: lastErr ?? "bootstrap health-check timed out", healthEndpoint };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async getNode(nodeId) {
|
|
229
|
+
const local = await state.loadNode(nodeId);
|
|
230
|
+
if (!local || local.provider !== "hyperstack") throw new Error(`hyperstack: no local record for nodeId=${nodeId}`);
|
|
231
|
+
try {
|
|
232
|
+
const data = await this._request("GET", `/core/virtual-machines/${local.providerNodeId}`);
|
|
233
|
+
const vm = data?.instance ?? data;
|
|
234
|
+
if (vm?.status) local.liveStatus = vm.status;
|
|
235
|
+
} catch { /* best-effort */ }
|
|
236
|
+
return local;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async listNodes() {
|
|
240
|
+
const all = await state.listNodes();
|
|
241
|
+
return all.filter((n) => n.provider === "hyperstack");
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
async stopNode(nodeId) {
|
|
245
|
+
const local = await state.loadNode(nodeId);
|
|
246
|
+
if (!local || local.provider !== "hyperstack") throw new Error(`hyperstack: no local record for nodeId=${nodeId}`);
|
|
247
|
+
await this._request("GET", `/core/virtual-machines/${local.providerNodeId}/stop`);
|
|
248
|
+
await state.updateNode(nodeId, { status: "stopped" });
|
|
249
|
+
return { ok: true };
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
async startNode(nodeId) {
|
|
253
|
+
const local = await state.loadNode(nodeId);
|
|
254
|
+
if (!local || local.provider !== "hyperstack") throw new Error(`hyperstack: no local record for nodeId=${nodeId}`);
|
|
255
|
+
await this._request("GET", `/core/virtual-machines/${local.providerNodeId}/start`);
|
|
256
|
+
await state.updateNode(nodeId, { status: "running" });
|
|
257
|
+
return { ok: true };
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
async destroyNode(nodeId) {
|
|
261
|
+
const local = await state.loadNode(nodeId);
|
|
262
|
+
if (!local || local.provider !== "hyperstack") throw new Error(`hyperstack: no local record for nodeId=${nodeId}`);
|
|
263
|
+
await this._request("DELETE", `/core/virtual-machines/${local.providerNodeId}`);
|
|
264
|
+
await state.updateNode(nodeId, { status: "destroyed" });
|
|
265
|
+
return { ok: true };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async logs(nodeId, _opts = {}) {
|
|
269
|
+
const local = await state.loadNode(nodeId).catch(() => null);
|
|
270
|
+
const err = new NotSupportedError("logs", "hyperstack");
|
|
271
|
+
const sshHint = local?.ip ? `\nSSH and tail the daemon log:\n ssh ubuntu@${local.ip} 'tail -200 /var/log/infernet/daemon.log'` : "";
|
|
272
|
+
err.message = `hyperstack: VM logs are not exposed via the API.\nView at: https://infrahub.nexgencloud.com/dashboard` + sshHint;
|
|
273
|
+
throw err;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export default HyperstackProvider;
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lambda Cloud adapter — IPIP-0019 DeployProvider implementation.
|
|
3
|
+
*
|
|
4
|
+
* Lambda's REST API is at https://cloud.lambdalabs.com/api/v1/
|
|
5
|
+
* Auth via HTTP Basic with the API key as the username (password empty).
|
|
6
|
+
*
|
|
7
|
+
* VM-based (not Docker). createNode launches an instance with a
|
|
8
|
+
* pre-uploaded SSH key; bootstrapNode is currently a health-check stub
|
|
9
|
+
* because Lambda's API doesn't expose cloud-init / user-data — operators
|
|
10
|
+
* need to either bake a custom AMI or SSH-in to run the installer.
|
|
11
|
+
*
|
|
12
|
+
* If the operator passes `bootstrap: "ssh"`, bootstrapNode will execute
|
|
13
|
+
* the installer via SSH (requires the matching private key on the local
|
|
14
|
+
* machine — pass via INFERNET_LAMBDA_SSH_KEY_PATH).
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { spawn } from "node:child_process";
|
|
18
|
+
import { DeployProvider, NotSupportedError } from "./base.js";
|
|
19
|
+
import { canonicalize, aliasesFor } from "../gpu-normalize.js";
|
|
20
|
+
import * as state from "../state.js";
|
|
21
|
+
import { composeInstallScript, pollVllmHealth } from "../vllm-bootstrap.js";
|
|
22
|
+
|
|
23
|
+
const API_BASE = "https://cloud.lambdalabs.com/api/v1";
|
|
24
|
+
|
|
25
|
+
const DEFAULT_INSTALLER =
|
|
26
|
+
process.env.INFERNET_INSTALLER_URL
|
|
27
|
+
?? "https://infernetprotocol.com/install.sh";
|
|
28
|
+
|
|
29
|
+
export class LambdaProvider extends DeployProvider {
|
|
30
|
+
constructor(config = {}) {
|
|
31
|
+
super({ ...config, providerId: "lambda" });
|
|
32
|
+
this._authHeader = "Basic " + Buffer.from(`${config.apiKey}:`).toString("base64");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async _request(method, path, body) {
|
|
36
|
+
const res = await fetch(`${API_BASE}${path}`, {
|
|
37
|
+
method,
|
|
38
|
+
headers: {
|
|
39
|
+
Authorization: this._authHeader,
|
|
40
|
+
"Content-Type": "application/json"
|
|
41
|
+
},
|
|
42
|
+
body: body ? JSON.stringify(body) : undefined
|
|
43
|
+
});
|
|
44
|
+
const json = await res.json().catch(() => ({}));
|
|
45
|
+
if (!res.ok) {
|
|
46
|
+
const msg = json?.error?.message ?? json?.message ?? res.statusText ?? `HTTP ${res.status}`;
|
|
47
|
+
const err = new Error(`Lambda Cloud API error: ${msg}`);
|
|
48
|
+
err.status = res.status;
|
|
49
|
+
err.body = json;
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
return json?.data ?? json;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ---- Discovery ----
|
|
56
|
+
|
|
57
|
+
async validateAuth() {
|
|
58
|
+
// Listing instances is the cheapest auth probe — empty list still
|
|
59
|
+
// returns 200 with valid creds.
|
|
60
|
+
await this._request("GET", "/instances");
|
|
61
|
+
return { ok: true };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async listGpuTypes() {
|
|
65
|
+
const types = await this._request("GET", "/instance-types");
|
|
66
|
+
// Response shape: { "gpu_1x_a100": { instance_type: { name, description, ... } } }
|
|
67
|
+
const out = [];
|
|
68
|
+
const entries = Array.isArray(types) ? types : Object.entries(types);
|
|
69
|
+
for (const entry of entries) {
|
|
70
|
+
const [_id, val] = Array.isArray(entry) ? entry : [entry?.id ?? null, entry];
|
|
71
|
+
const t = val?.instance_type ?? val;
|
|
72
|
+
if (!t?.name) continue;
|
|
73
|
+
out.push({
|
|
74
|
+
id: t.name,
|
|
75
|
+
name: t.description ?? t.name,
|
|
76
|
+
vramGb: t?.specs?.gpus?.[0]?.memory_gib ?? null,
|
|
77
|
+
pricePerHour: (t?.price_cents_per_hour ?? 0) / 100
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async listRegions() {
|
|
84
|
+
const types = await this._request("GET", "/instance-types");
|
|
85
|
+
const regions = new Set();
|
|
86
|
+
const entries = Array.isArray(types) ? types : Object.entries(types);
|
|
87
|
+
for (const entry of entries) {
|
|
88
|
+
const [_id, val] = Array.isArray(entry) ? entry : [null, entry];
|
|
89
|
+
const r = val?.regions_with_capacity_available ?? [];
|
|
90
|
+
for (const reg of r) regions.add(reg.name ?? reg);
|
|
91
|
+
}
|
|
92
|
+
return [...regions].map((r) => ({ id: r, name: r }));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async findOffers(request = {}) {
|
|
96
|
+
const types = await this._request("GET", "/instance-types");
|
|
97
|
+
const wantCanonical = request.gpu ? canonicalize(request.gpu) : null;
|
|
98
|
+
const aliases = wantCanonical
|
|
99
|
+
? [wantCanonical, ...aliasesFor(wantCanonical)].map((a) => a.toLowerCase())
|
|
100
|
+
: null;
|
|
101
|
+
|
|
102
|
+
const offers = [];
|
|
103
|
+
const entries = Array.isArray(types) ? types : Object.entries(types);
|
|
104
|
+
for (const entry of entries) {
|
|
105
|
+
const [_id, val] = Array.isArray(entry) ? entry : [null, entry];
|
|
106
|
+
const t = val?.instance_type ?? val;
|
|
107
|
+
const regionsAvail = val?.regions_with_capacity_available ?? [];
|
|
108
|
+
if (!t?.name) continue;
|
|
109
|
+
|
|
110
|
+
const desc = (t.description ?? t.name).toLowerCase();
|
|
111
|
+
if (aliases && !aliases.some((a) => desc.includes(a))) continue;
|
|
112
|
+
|
|
113
|
+
const vramGb = t?.specs?.gpus?.[0]?.memory_gib ?? 0;
|
|
114
|
+
if (request.vramMin && vramGb < request.vramMin) continue;
|
|
115
|
+
|
|
116
|
+
const pricePerHour = (t?.price_cents_per_hour ?? 0) / 100;
|
|
117
|
+
if (request.maxPricePerHour != null && pricePerHour > request.maxPricePerHour) continue;
|
|
118
|
+
|
|
119
|
+
for (const reg of regionsAvail) {
|
|
120
|
+
if (request.region && (reg.name ?? reg) !== request.region) continue;
|
|
121
|
+
offers.push({
|
|
122
|
+
providerId: "lambda",
|
|
123
|
+
offerId: `${t.name}@${reg.name ?? reg}`,
|
|
124
|
+
gpu: {
|
|
125
|
+
name: t.description ?? t.name,
|
|
126
|
+
count: t?.specs?.gpus?.length ?? 1,
|
|
127
|
+
vramGb
|
|
128
|
+
},
|
|
129
|
+
cpu: t?.specs?.vcpus ? { cores: t.specs.vcpus } : undefined,
|
|
130
|
+
ramGb: t?.specs?.memory_gib ?? undefined,
|
|
131
|
+
diskGb: t?.specs?.storage_gib ?? undefined,
|
|
132
|
+
region: reg.name ?? reg,
|
|
133
|
+
pricePerHour,
|
|
134
|
+
deployStyle: "vm-ssh",
|
|
135
|
+
available: true,
|
|
136
|
+
raw: { instance_type_name: t.name, region: reg.name ?? reg, instance_type: t }
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return offers;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// ---- Lifecycle ----
|
|
144
|
+
|
|
145
|
+
async createNode(request = {}) {
|
|
146
|
+
const {
|
|
147
|
+
gpu, gpuCount = 1, name, region, instanceTypeName,
|
|
148
|
+
sshKeyNames, fileSystemNames = [],
|
|
149
|
+
env = {}, controlPlaneUrl = "", engine = "ollama", model = null,
|
|
150
|
+
hourlyPrice = 0, vramGb = 0
|
|
151
|
+
} = request;
|
|
152
|
+
|
|
153
|
+
if (!sshKeyNames || sshKeyNames.length === 0) {
|
|
154
|
+
throw new Error(
|
|
155
|
+
"lambda: createNode requires sshKeyNames (upload a key first via /api/v1/ssh-keys " +
|
|
156
|
+
"or the Lambda dashboard, then pass [\"key-name\"])"
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Resolve instance type from canonical GPU if not given explicitly.
|
|
161
|
+
const finalType = instanceTypeName ?? await this._pickInstanceType({ gpu, region });
|
|
162
|
+
if (!finalType) {
|
|
163
|
+
throw new Error(`lambda: no instance type matched gpu="${gpu}" in region="${region ?? "any"}"`);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const finalRegion = region ?? await this._pickRegion(finalType);
|
|
167
|
+
if (!finalRegion) {
|
|
168
|
+
throw new Error(`lambda: no region with capacity for instance type "${finalType}"`);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const localId = state.generateNodeId();
|
|
172
|
+
const vmName = name ?? localId;
|
|
173
|
+
|
|
174
|
+
const data = await this._request("POST", "/instance-operations/launch", {
|
|
175
|
+
region_name: finalRegion,
|
|
176
|
+
instance_type_name: finalType,
|
|
177
|
+
ssh_key_names: sshKeyNames,
|
|
178
|
+
file_system_names: fileSystemNames,
|
|
179
|
+
quantity: gpuCount > 1 ? 1 : 1, // Lambda's "quantity" is # of instances, not GPUs
|
|
180
|
+
name: vmName
|
|
181
|
+
// Note: Lambda's launch API does NOT accept a user-data /
|
|
182
|
+
// cloud-init field. Bootstrap happens post-launch via SSH.
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const ids = data?.instance_ids ?? [];
|
|
186
|
+
const vmId = ids[0];
|
|
187
|
+
if (!vmId) throw new Error("lambda: launch returned no instance id");
|
|
188
|
+
|
|
189
|
+
const record = {
|
|
190
|
+
id: localId,
|
|
191
|
+
provider: "lambda",
|
|
192
|
+
providerNodeId: vmId,
|
|
193
|
+
name: vmName,
|
|
194
|
+
gpu: gpu ?? finalType,
|
|
195
|
+
gpuCount,
|
|
196
|
+
vramGb,
|
|
197
|
+
region: finalRegion,
|
|
198
|
+
hourlyPrice,
|
|
199
|
+
engine,
|
|
200
|
+
model: model ?? undefined,
|
|
201
|
+
status: "creating",
|
|
202
|
+
createdAt: new Date().toISOString(),
|
|
203
|
+
controlPlaneUrl,
|
|
204
|
+
envForBootstrap: {
|
|
205
|
+
INFERNET_NODE_NAME: vmName,
|
|
206
|
+
INFERNET_CONTROL_PLANE_URL: controlPlaneUrl,
|
|
207
|
+
INFERNET_ENGINE: engine,
|
|
208
|
+
...(model ? { INFERNET_MODEL: model } : {}),
|
|
209
|
+
...env
|
|
210
|
+
},
|
|
211
|
+
sshKeyNames
|
|
212
|
+
};
|
|
213
|
+
await state.saveNode(record);
|
|
214
|
+
return record;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async _pickInstanceType({ gpu, region }) {
|
|
218
|
+
const offers = await this.findOffers({ gpu, region });
|
|
219
|
+
if (offers.length === 0) return null;
|
|
220
|
+
offers.sort((a, b) => a.pricePerHour - b.pricePerHour);
|
|
221
|
+
return offers[0].raw?.instance_type_name ?? null;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async _pickRegion(typeName) {
|
|
225
|
+
const types = await this._request("GET", "/instance-types");
|
|
226
|
+
const entries = Array.isArray(types) ? types : Object.entries(types);
|
|
227
|
+
for (const entry of entries) {
|
|
228
|
+
const [_id, val] = Array.isArray(entry) ? entry : [null, entry];
|
|
229
|
+
const t = val?.instance_type ?? val;
|
|
230
|
+
if (t?.name !== typeName) continue;
|
|
231
|
+
const regs = val?.regions_with_capacity_available ?? [];
|
|
232
|
+
return regs[0]?.name ?? regs[0] ?? null;
|
|
233
|
+
}
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
async waitUntilReady(node, timeoutMs = 5 * 60 * 1000) {
|
|
238
|
+
if (!node?.providerNodeId) {
|
|
239
|
+
throw new Error("lambda: waitUntilReady requires node.providerNodeId");
|
|
240
|
+
}
|
|
241
|
+
const deadline = Date.now() + timeoutMs;
|
|
242
|
+
while (Date.now() < deadline) {
|
|
243
|
+
const inst = await this._request("GET", `/instances/${node.providerNodeId}`);
|
|
244
|
+
const status = (inst?.status ?? "").toLowerCase();
|
|
245
|
+
if (status === "active" || status === "running") {
|
|
246
|
+
const ip = inst?.ip ?? null;
|
|
247
|
+
const endpointUrl = ip ? `http://${ip}:46337` : null;
|
|
248
|
+
return state.updateNode(node.id, { status: "running", endpointUrl, ip });
|
|
249
|
+
}
|
|
250
|
+
await new Promise((r) => setTimeout(r, 5000));
|
|
251
|
+
}
|
|
252
|
+
await state.updateNode(node.id, {
|
|
253
|
+
status: "error",
|
|
254
|
+
error_log: `instance did not reach ACTIVE within ${Math.round(timeoutMs / 1000)}s`
|
|
255
|
+
});
|
|
256
|
+
throw new Error(
|
|
257
|
+
`Lambda instance ${node.providerNodeId} did not reach ACTIVE within ${Math.round(timeoutMs / 1000)}s`
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async bootstrapNode(node, request = {}) {
|
|
262
|
+
// Lambda doesn't take cloud-init, so bootstrap must SSH in. We do
|
|
263
|
+
// it ourselves only if the operator explicitly opts in via
|
|
264
|
+
// request.bootstrap === "ssh" AND has the matching private key
|
|
265
|
+
// on disk (path via env or request.sshKeyPath).
|
|
266
|
+
if (request.bootstrap !== "ssh") {
|
|
267
|
+
return {
|
|
268
|
+
ok: false,
|
|
269
|
+
reason:
|
|
270
|
+
"lambda: cloud-init is not supported by Lambda's API. " +
|
|
271
|
+
"Pass { bootstrap: 'ssh' } and provide sshKeyPath (or set " +
|
|
272
|
+
"INFERNET_LAMBDA_SSH_KEY_PATH) to run the installer over SSH, " +
|
|
273
|
+
"or pre-bake an AMI with the Infernet daemon installed."
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
if (!node?.ip) {
|
|
277
|
+
return { ok: false, reason: "no node.ip — call waitUntilReady first" };
|
|
278
|
+
}
|
|
279
|
+
const sshKeyPath = request.sshKeyPath ?? process.env.INFERNET_LAMBDA_SSH_KEY_PATH;
|
|
280
|
+
if (!sshKeyPath) {
|
|
281
|
+
return { ok: false, reason: "ssh bootstrap requested but no sshKeyPath" };
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Build the remote command. For vLLM, swap to the shared
|
|
285
|
+
// composeInstallScript so the install + systemd unit + Infernet
|
|
286
|
+
// daemon are all set up consistently with the cloud-init providers.
|
|
287
|
+
let remoteCmd;
|
|
288
|
+
if ((request.engine ?? node.engine) === "vllm") {
|
|
289
|
+
const script = composeInstallScript({
|
|
290
|
+
infernetEnv: node.envForBootstrap ?? {},
|
|
291
|
+
vllmConfig: { model: node.model, ...(request.vllm ?? {}) }
|
|
292
|
+
});
|
|
293
|
+
// Pipe the script to bash via stdin to avoid quoting issues.
|
|
294
|
+
remoteCmd = `cat <<'INFERNET_BOOTSTRAP_EOF' | sudo bash -s\n${script}\nINFERNET_BOOTSTRAP_EOF`;
|
|
295
|
+
} else {
|
|
296
|
+
const envExports = Object.entries(node.envForBootstrap ?? {})
|
|
297
|
+
.map(([k, v]) => `export ${k}=${JSON.stringify(String(v))}`)
|
|
298
|
+
.join("\n");
|
|
299
|
+
remoteCmd = [
|
|
300
|
+
"set -eux",
|
|
301
|
+
envExports,
|
|
302
|
+
`curl -fsSL ${DEFAULT_INSTALLER} | bash`,
|
|
303
|
+
"infernet register || true",
|
|
304
|
+
"infernet start || true"
|
|
305
|
+
].join(" && ");
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const code = await new Promise((resolve, reject) => {
|
|
309
|
+
const args = [
|
|
310
|
+
"-i", sshKeyPath,
|
|
311
|
+
"-o", "StrictHostKeyChecking=no",
|
|
312
|
+
"-o", "UserKnownHostsFile=/dev/null",
|
|
313
|
+
`ubuntu@${node.ip}`,
|
|
314
|
+
remoteCmd
|
|
315
|
+
];
|
|
316
|
+
const child = spawn("ssh", args, { stdio: "inherit" });
|
|
317
|
+
child.on("exit", resolve);
|
|
318
|
+
child.on("error", reject);
|
|
319
|
+
});
|
|
320
|
+
if (code !== 0) {
|
|
321
|
+
return { ok: false, reason: `ssh bootstrap exited ${code}` };
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// Health-check: vLLM polls /v1/models, otherwise daemon /health.
|
|
325
|
+
if ((request.engine ?? node.engine) === "vllm") {
|
|
326
|
+
return pollVllmHealth(node.ip, { port: request.vllm?.port ?? 8000 });
|
|
327
|
+
}
|
|
328
|
+
const healthEndpoint = `${node.endpointUrl}/health`;
|
|
329
|
+
try {
|
|
330
|
+
const ctrl = new AbortController();
|
|
331
|
+
setTimeout(() => ctrl.abort(), 5000);
|
|
332
|
+
const res = await fetch(healthEndpoint, { signal: ctrl.signal });
|
|
333
|
+
return { ok: res.ok, healthEndpoint };
|
|
334
|
+
} catch (err) {
|
|
335
|
+
return { ok: false, reason: err?.message ?? String(err), healthEndpoint };
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
async getNode(nodeId) {
|
|
340
|
+
const local = await state.loadNode(nodeId);
|
|
341
|
+
if (!local || local.provider !== "lambda") {
|
|
342
|
+
throw new Error(`lambda: no local record for nodeId=${nodeId}`);
|
|
343
|
+
}
|
|
344
|
+
try {
|
|
345
|
+
const inst = await this._request("GET", `/instances/${local.providerNodeId}`);
|
|
346
|
+
if (inst?.status) local.liveStatus = inst.status;
|
|
347
|
+
} catch { /* best-effort */ }
|
|
348
|
+
return local;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
async listNodes() {
|
|
352
|
+
const all = await state.listNodes();
|
|
353
|
+
return all.filter((n) => n.provider === "lambda");
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
async stopNode(_nodeId) {
|
|
357
|
+
// Lambda doesn't support pausing instances — only terminate. Be honest.
|
|
358
|
+
throw new NotSupportedError(
|
|
359
|
+
"stopNode",
|
|
360
|
+
"lambda"
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
async startNode(_nodeId) {
|
|
365
|
+
throw new NotSupportedError(
|
|
366
|
+
"startNode",
|
|
367
|
+
"lambda"
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
async destroyNode(nodeId) {
|
|
372
|
+
const local = await state.loadNode(nodeId);
|
|
373
|
+
if (!local || local.provider !== "lambda") {
|
|
374
|
+
throw new Error(`lambda: no local record for nodeId=${nodeId}`);
|
|
375
|
+
}
|
|
376
|
+
await this._request("POST", "/instance-operations/terminate", {
|
|
377
|
+
instance_ids: [local.providerNodeId]
|
|
378
|
+
});
|
|
379
|
+
await state.updateNode(nodeId, { status: "destroyed" });
|
|
380
|
+
return { ok: true };
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
async logs(nodeId, _opts = {}) {
|
|
384
|
+
const local = await state.loadNode(nodeId).catch(() => null);
|
|
385
|
+
const err = new NotSupportedError("logs", "lambda");
|
|
386
|
+
const sshHint = local?.ip
|
|
387
|
+
? `\nSSH and tail the daemon log:\n ssh ubuntu@${local.ip} 'tail -200 /var/log/infernet/daemon.log'`
|
|
388
|
+
: "";
|
|
389
|
+
err.message =
|
|
390
|
+
`lambda: instance logs are not exposed via the API.\n` +
|
|
391
|
+
`View at: https://cloud.lambdalabs.com/instances` + sshHint;
|
|
392
|
+
throw err;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export default LambdaProvider;
|