@infernetprotocol/deploy-providers 0.1.22 → 0.1.26
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,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Crusoe Cloud adapter — IPIP-0019 DeployProvider implementation.
|
|
3
|
+
*
|
|
4
|
+
* REST API: https://api.crusoecloud.site/v1alpha5/
|
|
5
|
+
* Docs: https://docs.crusoecloud.com/api/
|
|
6
|
+
* Auth: Bearer token from https://console.crusoecloud.com/security/tokens
|
|
7
|
+
*
|
|
8
|
+
* Crusoe scopes resources by project — pass `projectId` in the config or
|
|
9
|
+
* set CRUSOE_PROJECT_ID env var. Cloud-init via the `startup_script` field
|
|
10
|
+
* on POST /projects/{project_id}/compute/instances.
|
|
11
|
+
*
|
|
12
|
+
* Verified against current docs: 2026-05-01.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { DeployProvider, NotSupportedError } from "./base.js";
|
|
16
|
+
import { canonicalize, aliasesFor } from "../gpu-normalize.js";
|
|
17
|
+
import * as state from "../state.js";
|
|
18
|
+
import { composeInstallScript, pollVllmHealth } from "../vllm-bootstrap.js";
|
|
19
|
+
|
|
20
|
+
const API_BASE = "https://api.crusoecloud.site/v1alpha5";
|
|
21
|
+
const DEFAULT_INSTALLER = process.env.INFERNET_INSTALLER_URL ?? "https://infernetprotocol.com/install.sh";
|
|
22
|
+
|
|
23
|
+
export class CrusoeProvider extends DeployProvider {
|
|
24
|
+
constructor(config = {}) {
|
|
25
|
+
super({ ...config, providerId: "crusoe" });
|
|
26
|
+
this.projectId = config.projectId ?? process.env.CRUSOE_PROJECT_ID;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
_project(path = "") {
|
|
30
|
+
if (!this.projectId) throw new Error("crusoe: projectId required (config.projectId or CRUSOE_PROJECT_ID)");
|
|
31
|
+
return `/projects/${this.projectId}${path}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async _request(method, path, body) {
|
|
35
|
+
const res = await fetch(`${API_BASE}${path}`, {
|
|
36
|
+
method,
|
|
37
|
+
headers: {
|
|
38
|
+
"Authorization": `Bearer ${this.config.apiKey}`,
|
|
39
|
+
"Content-Type": "application/json"
|
|
40
|
+
},
|
|
41
|
+
body: body ? JSON.stringify(body) : undefined
|
|
42
|
+
});
|
|
43
|
+
const json = await res.json().catch(() => ({}));
|
|
44
|
+
if (!res.ok) {
|
|
45
|
+
const msg = json?.message ?? json?.error ?? res.statusText ?? `HTTP ${res.status}`;
|
|
46
|
+
const err = new Error(`Crusoe API error: ${msg}`);
|
|
47
|
+
err.status = res.status;
|
|
48
|
+
err.body = json;
|
|
49
|
+
throw err;
|
|
50
|
+
}
|
|
51
|
+
return json;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async validateAuth() {
|
|
55
|
+
const data = await this._request("GET", "/projects");
|
|
56
|
+
if (!Array.isArray(data?.items ?? data)) throw new Error("Crusoe: API key invalid");
|
|
57
|
+
return { ok: true, accountInfo: { projects: (data.items ?? data).length } };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async listGpuTypes() {
|
|
61
|
+
const data = await this._request("GET", "/compute/vms/products");
|
|
62
|
+
return (data?.items ?? data ?? []).map((p) => ({
|
|
63
|
+
id: p.product_name ?? p.name,
|
|
64
|
+
name: p.gpu_type ?? p.name,
|
|
65
|
+
vramGb: p.gpu_memory_gib ?? null,
|
|
66
|
+
pricePerHour: p.price_per_hour_usd ?? null
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async listRegions() {
|
|
71
|
+
const data = await this._request("GET", "/locations");
|
|
72
|
+
return (data?.items ?? data ?? []).map((r) => ({ id: r.name, name: r.display_name ?? r.name }));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async findOffers(request = {}) {
|
|
76
|
+
const products = (await this._request("GET", "/compute/vms/products"))?.items ?? [];
|
|
77
|
+
|
|
78
|
+
const wantCanonical = request.gpu ? canonicalize(request.gpu) : null;
|
|
79
|
+
const aliases = wantCanonical
|
|
80
|
+
? [wantCanonical, ...aliasesFor(wantCanonical)].map((a) => a.toLowerCase())
|
|
81
|
+
: null;
|
|
82
|
+
|
|
83
|
+
const offers = [];
|
|
84
|
+
for (const p of products) {
|
|
85
|
+
const gpuStr = (p.gpu_type ?? p.product_name ?? "").toLowerCase();
|
|
86
|
+
if (aliases && !aliases.some((a) => gpuStr.includes(a))) continue;
|
|
87
|
+
const vramGb = p.gpu_memory_gib ?? 0;
|
|
88
|
+
if (request.vramMin && vramGb < request.vramMin) continue;
|
|
89
|
+
const price = p.price_per_hour_usd ?? 0;
|
|
90
|
+
if (request.maxPricePerHour != null && price > request.maxPricePerHour) continue;
|
|
91
|
+
|
|
92
|
+
for (const loc of p.locations ?? []) {
|
|
93
|
+
if (request.region && loc !== request.region) continue;
|
|
94
|
+
offers.push({
|
|
95
|
+
providerId: "crusoe",
|
|
96
|
+
offerId: `${p.product_name ?? p.name}@${loc}`,
|
|
97
|
+
gpu: { name: p.gpu_type ?? p.name, count: p.gpu_count ?? 1, vramGb },
|
|
98
|
+
cpu: p.vcpu_count ? { cores: p.vcpu_count } : undefined,
|
|
99
|
+
ramGb: p.memory_gib,
|
|
100
|
+
diskGb: p.local_storage_gib,
|
|
101
|
+
region: loc,
|
|
102
|
+
pricePerHour: price,
|
|
103
|
+
deployStyle: "vm-ssh",
|
|
104
|
+
available: true,
|
|
105
|
+
raw: { product_name: p.product_name ?? p.name, location: loc, product: p }
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return offers;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
_buildStartupScript(envMap, opts = {}) {
|
|
113
|
+
if (opts.engine === "vllm") {
|
|
114
|
+
return composeInstallScript({ infernetEnv: envMap, vllmConfig: opts.vllmConfig ?? {} });
|
|
115
|
+
}
|
|
116
|
+
const exports = Object.entries(envMap).map(([k, v]) => `export ${k}=${JSON.stringify(String(v))}`).join("\n");
|
|
117
|
+
return ["#!/bin/bash", "set -eux", exports,
|
|
118
|
+
`curl -fsSL ${DEFAULT_INSTALLER} | bash`,
|
|
119
|
+
"infernet register || true", "infernet start || true"].join("\n");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async createNode(request = {}) {
|
|
123
|
+
const {
|
|
124
|
+
gpu, name, productName, region, sshPublicKey, image = "ubuntu22.04-nvidia-pcie-docker",
|
|
125
|
+
env = {}, controlPlaneUrl = "", engine = "ollama", model = null,
|
|
126
|
+
hourlyPrice = 0, vramGb = 0, gpuCount = 1
|
|
127
|
+
} = request;
|
|
128
|
+
|
|
129
|
+
if (!sshPublicKey) {
|
|
130
|
+
throw new Error("crusoe: createNode requires sshPublicKey");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let finalProduct = productName;
|
|
134
|
+
let finalLocation = region;
|
|
135
|
+
if (!finalProduct) {
|
|
136
|
+
const offers = await this.findOffers({ gpu, region });
|
|
137
|
+
if (offers.length === 0) throw new Error(`crusoe: no product matched gpu="${gpu}"`);
|
|
138
|
+
offers.sort((a, b) => a.pricePerHour - b.pricePerHour);
|
|
139
|
+
finalProduct = offers[0].raw.product_name;
|
|
140
|
+
finalLocation = finalLocation ?? offers[0].raw.location;
|
|
141
|
+
}
|
|
142
|
+
if (!finalLocation) throw new Error("crusoe: createNode requires region");
|
|
143
|
+
|
|
144
|
+
const localId = state.generateNodeId();
|
|
145
|
+
const vmName = name ?? localId;
|
|
146
|
+
|
|
147
|
+
const startupScript = this._buildStartupScript({
|
|
148
|
+
INFERNET_NODE_NAME: vmName,
|
|
149
|
+
INFERNET_CONTROL_PLANE_URL: controlPlaneUrl,
|
|
150
|
+
INFERNET_ENGINE: engine,
|
|
151
|
+
...(model ? { INFERNET_MODEL: model } : {}),
|
|
152
|
+
...env
|
|
153
|
+
}, { engine, vllmConfig: { model, ...(request.vllm ?? {}) } });
|
|
154
|
+
|
|
155
|
+
const data = await this._request("POST", this._project("/compute/instances"), {
|
|
156
|
+
name: vmName,
|
|
157
|
+
product_name: finalProduct,
|
|
158
|
+
location: finalLocation,
|
|
159
|
+
image,
|
|
160
|
+
ssh_public_key: sshPublicKey,
|
|
161
|
+
startup_script: startupScript
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const inst = data?.instance ?? data;
|
|
165
|
+
const vmId = inst?.id;
|
|
166
|
+
if (!vmId) throw new Error("crusoe: create returned no instance id");
|
|
167
|
+
|
|
168
|
+
const record = {
|
|
169
|
+
id: localId,
|
|
170
|
+
provider: "crusoe",
|
|
171
|
+
providerNodeId: vmId,
|
|
172
|
+
name: vmName,
|
|
173
|
+
gpu: gpu ?? finalProduct,
|
|
174
|
+
gpuCount,
|
|
175
|
+
vramGb,
|
|
176
|
+
region: finalLocation,
|
|
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("crusoe: waitUntilReady requires node.providerNodeId");
|
|
190
|
+
const deadline = Date.now() + timeoutMs;
|
|
191
|
+
while (Date.now() < deadline) {
|
|
192
|
+
const data = await this._request("GET", this._project(`/compute/instances/${node.providerNodeId}`));
|
|
193
|
+
const inst = data?.instance ?? data;
|
|
194
|
+
const state_ = (inst?.state ?? inst?.status ?? "").toUpperCase();
|
|
195
|
+
const ip = inst?.network_interfaces?.[0]?.ips?.[0]?.public_ipv4?.address
|
|
196
|
+
?? inst?.public_ip ?? null;
|
|
197
|
+
if ((state_ === "STATE_RUNNING" || state_ === "RUNNING") && ip) {
|
|
198
|
+
const endpointUrl = `http://${ip}:46337`;
|
|
199
|
+
return state.updateNode(node.id, { status: "running", endpointUrl, ip });
|
|
200
|
+
}
|
|
201
|
+
await new Promise((r) => setTimeout(r, 5000));
|
|
202
|
+
}
|
|
203
|
+
await state.updateNode(node.id, { status: "error", error_log: "instance did not reach RUNNING in time" });
|
|
204
|
+
throw new Error(`Crusoe instance ${node.providerNodeId} did not reach RUNNING within ${Math.round(timeoutMs / 1000)}s`);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async bootstrapNode(node, request = {}) {
|
|
208
|
+
if (!node?.endpointUrl && !node?.ip) return { ok: false, reason: "no endpointUrl/ip on node" };
|
|
209
|
+
if ((request.engine ?? node.engine) === "vllm") {
|
|
210
|
+
return pollVllmHealth(node.ip ?? node.endpointUrl, { port: request.vllm?.port ?? 8000 });
|
|
211
|
+
}
|
|
212
|
+
const healthEndpoint = `${node.endpointUrl}/health`;
|
|
213
|
+
const deadline = Date.now() + 5 * 60 * 1000;
|
|
214
|
+
let lastErr = null;
|
|
215
|
+
while (Date.now() < deadline) {
|
|
216
|
+
try {
|
|
217
|
+
const ctrl = new AbortController();
|
|
218
|
+
const t = setTimeout(() => ctrl.abort(), 5000);
|
|
219
|
+
const res = await fetch(healthEndpoint, { signal: ctrl.signal });
|
|
220
|
+
clearTimeout(t);
|
|
221
|
+
if (res.ok) return { ok: true, healthEndpoint };
|
|
222
|
+
lastErr = `HTTP ${res.status}`;
|
|
223
|
+
} catch (err) { lastErr = err?.message ?? String(err); }
|
|
224
|
+
await new Promise((r) => setTimeout(r, 10000));
|
|
225
|
+
}
|
|
226
|
+
return { ok: false, reason: lastErr ?? "bootstrap health-check timed out", healthEndpoint };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
async getNode(nodeId) {
|
|
230
|
+
const local = await state.loadNode(nodeId);
|
|
231
|
+
if (!local || local.provider !== "crusoe") throw new Error(`crusoe: no local record for nodeId=${nodeId}`);
|
|
232
|
+
try {
|
|
233
|
+
const data = await this._request("GET", this._project(`/compute/instances/${local.providerNodeId}`));
|
|
234
|
+
const inst = data?.instance ?? data;
|
|
235
|
+
if (inst?.state ?? inst?.status) local.liveStatus = inst.state ?? inst.status;
|
|
236
|
+
} catch { /* best-effort */ }
|
|
237
|
+
return local;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async listNodes() {
|
|
241
|
+
const all = await state.listNodes();
|
|
242
|
+
return all.filter((n) => n.provider === "crusoe");
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async stopNode(nodeId) {
|
|
246
|
+
const local = await state.loadNode(nodeId);
|
|
247
|
+
if (!local || local.provider !== "crusoe") throw new Error(`crusoe: no local record for nodeId=${nodeId}`);
|
|
248
|
+
await this._request("POST", this._project(`/compute/instances/${local.providerNodeId}/actions/stop`));
|
|
249
|
+
await state.updateNode(nodeId, { status: "stopped" });
|
|
250
|
+
return { ok: true };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async startNode(nodeId) {
|
|
254
|
+
const local = await state.loadNode(nodeId);
|
|
255
|
+
if (!local || local.provider !== "crusoe") throw new Error(`crusoe: no local record for nodeId=${nodeId}`);
|
|
256
|
+
await this._request("POST", this._project(`/compute/instances/${local.providerNodeId}/actions/start`));
|
|
257
|
+
await state.updateNode(nodeId, { status: "running" });
|
|
258
|
+
return { ok: true };
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async destroyNode(nodeId) {
|
|
262
|
+
const local = await state.loadNode(nodeId);
|
|
263
|
+
if (!local || local.provider !== "crusoe") throw new Error(`crusoe: no local record for nodeId=${nodeId}`);
|
|
264
|
+
await this._request("DELETE", this._project(`/compute/instances/${local.providerNodeId}`));
|
|
265
|
+
await state.updateNode(nodeId, { status: "destroyed" });
|
|
266
|
+
return { ok: true };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
async logs(nodeId, _opts = {}) {
|
|
270
|
+
const local = await state.loadNode(nodeId).catch(() => null);
|
|
271
|
+
const err = new NotSupportedError("logs", "crusoe");
|
|
272
|
+
const sshHint = local?.ip ? `\nSSH and tail the daemon log:\n ssh ubuntu@${local.ip} 'tail -200 /var/log/infernet/daemon.log'` : "";
|
|
273
|
+
err.message = `crusoe: instance logs are not exposed via the API.\nView at: https://console.crusoecloud.com/compute/instances` + sshHint;
|
|
274
|
+
throw err;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export default CrusoeProvider;
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DataCrunch adapter — IPIP-0019 DeployProvider implementation.
|
|
3
|
+
*
|
|
4
|
+
* REST API: https://api.datacrunch.io/v1
|
|
5
|
+
* Docs: https://api.datacrunch.io/v1/docs
|
|
6
|
+
* Auth: OAuth2 client_credentials. Operator gets client_id +
|
|
7
|
+
* client_secret from https://cloud.datacrunch.io/account/api;
|
|
8
|
+
* we exchange them for a short-lived bearer token on each
|
|
9
|
+
* provider instance.
|
|
10
|
+
*
|
|
11
|
+
* Pass `{ apiKey: client_id, apiSecret: client_secret }` to the constructor
|
|
12
|
+
* (or set DATACRUNCH_CLIENT_ID + DATACRUNCH_CLIENT_SECRET).
|
|
13
|
+
*
|
|
14
|
+
* VM-based with cloud-init via the `startup_script_id` field (script
|
|
15
|
+
* has to be pre-uploaded) OR raw inline via the `user_data` field on
|
|
16
|
+
* newer API versions. We use inline `user_data`.
|
|
17
|
+
*
|
|
18
|
+
* Verified against current docs: 2026-05-01.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { DeployProvider, NotSupportedError } from "./base.js";
|
|
22
|
+
import { canonicalize, aliasesFor } from "../gpu-normalize.js";
|
|
23
|
+
import * as state from "../state.js";
|
|
24
|
+
import { composeInstallScript, pollVllmHealth } from "../vllm-bootstrap.js";
|
|
25
|
+
|
|
26
|
+
const API_BASE = "https://api.datacrunch.io/v1";
|
|
27
|
+
const DEFAULT_INSTALLER = process.env.INFERNET_INSTALLER_URL ?? "https://infernetprotocol.com/install.sh";
|
|
28
|
+
|
|
29
|
+
export class DataCrunchProvider extends DeployProvider {
|
|
30
|
+
constructor(config = {}) {
|
|
31
|
+
super({ ...config, providerId: "datacrunch" });
|
|
32
|
+
this.clientId = config.apiKey;
|
|
33
|
+
this.clientSecret = config.apiSecret ?? process.env.DATACRUNCH_CLIENT_SECRET;
|
|
34
|
+
this._token = null;
|
|
35
|
+
this._tokenExpiresAt = 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async _getToken() {
|
|
39
|
+
if (this._token && Date.now() < this._tokenExpiresAt - 60_000) return this._token;
|
|
40
|
+
if (!this.clientSecret) throw new Error("datacrunch: apiSecret (client_secret) required");
|
|
41
|
+
const res = await fetch(`${API_BASE}/oauth2/token`, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: { "Content-Type": "application/json" },
|
|
44
|
+
body: JSON.stringify({
|
|
45
|
+
grant_type: "client_credentials",
|
|
46
|
+
client_id: this.clientId,
|
|
47
|
+
client_secret: this.clientSecret
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
const json = await res.json().catch(() => ({}));
|
|
51
|
+
if (!res.ok || !json?.access_token) {
|
|
52
|
+
throw new Error(`DataCrunch oauth2 error: ${json?.message ?? res.statusText}`);
|
|
53
|
+
}
|
|
54
|
+
this._token = json.access_token;
|
|
55
|
+
this._tokenExpiresAt = Date.now() + (json.expires_in ?? 3600) * 1000;
|
|
56
|
+
return this._token;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async _request(method, path, body) {
|
|
60
|
+
const token = await this._getToken();
|
|
61
|
+
const res = await fetch(`${API_BASE}${path}`, {
|
|
62
|
+
method,
|
|
63
|
+
headers: {
|
|
64
|
+
"Authorization": `Bearer ${token}`,
|
|
65
|
+
"Content-Type": "application/json"
|
|
66
|
+
},
|
|
67
|
+
body: body ? JSON.stringify(body) : undefined
|
|
68
|
+
});
|
|
69
|
+
const text = await res.text();
|
|
70
|
+
const json = text ? JSON.parse(text) : {};
|
|
71
|
+
if (!res.ok) {
|
|
72
|
+
const msg = json?.message ?? json?.error ?? res.statusText ?? `HTTP ${res.status}`;
|
|
73
|
+
const err = new Error(`DataCrunch API error: ${msg}`);
|
|
74
|
+
err.status = res.status;
|
|
75
|
+
err.body = json;
|
|
76
|
+
throw err;
|
|
77
|
+
}
|
|
78
|
+
return json;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async validateAuth() {
|
|
82
|
+
await this._getToken();
|
|
83
|
+
return { ok: true };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async listGpuTypes() {
|
|
87
|
+
const types = await this._request("GET", "/instance-types");
|
|
88
|
+
return (types ?? []).map((t) => ({
|
|
89
|
+
id: t.instance_type ?? t.id ?? t.name,
|
|
90
|
+
name: t.gpu_description ?? t.gpu ?? t.name,
|
|
91
|
+
vramGb: t.gpu_memory ? Math.round(t.gpu_memory / 1024) : null,
|
|
92
|
+
pricePerHour: t.price_per_hour ?? null
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async listRegions() {
|
|
97
|
+
const locs = await this._request("GET", "/locations");
|
|
98
|
+
return (locs ?? []).map((l) => ({ id: l.code ?? l.id, name: l.name ?? l.code }));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async findOffers(request = {}) {
|
|
102
|
+
const types = await this._request("GET", "/instance-types");
|
|
103
|
+
|
|
104
|
+
const wantCanonical = request.gpu ? canonicalize(request.gpu) : null;
|
|
105
|
+
const aliases = wantCanonical
|
|
106
|
+
? [wantCanonical, ...aliasesFor(wantCanonical)].map((a) => a.toLowerCase())
|
|
107
|
+
: null;
|
|
108
|
+
|
|
109
|
+
const offers = [];
|
|
110
|
+
for (const t of types ?? []) {
|
|
111
|
+
const gpuStr = (t.gpu_description ?? t.gpu ?? t.name ?? "").toLowerCase();
|
|
112
|
+
if (aliases && !aliases.some((a) => gpuStr.includes(a))) continue;
|
|
113
|
+
const vramGb = t.gpu_memory ? Math.round(t.gpu_memory / 1024) : 0;
|
|
114
|
+
if (request.vramMin && vramGb < request.vramMin) continue;
|
|
115
|
+
const price = t.price_per_hour ?? 0;
|
|
116
|
+
if (request.maxPricePerHour != null && price > request.maxPricePerHour) continue;
|
|
117
|
+
|
|
118
|
+
for (const loc of t.locations ?? [t.location].filter(Boolean) ?? []) {
|
|
119
|
+
if (request.region && loc !== request.region) continue;
|
|
120
|
+
offers.push({
|
|
121
|
+
providerId: "datacrunch",
|
|
122
|
+
offerId: `${t.instance_type ?? t.id}@${loc}`,
|
|
123
|
+
gpu: { name: t.gpu_description ?? t.gpu ?? t.name, count: t.gpu_count ?? 1, vramGb },
|
|
124
|
+
cpu: t.cpu_count ? { cores: t.cpu_count } : undefined,
|
|
125
|
+
ramGb: t.memory ? Math.round(t.memory / 1024) : undefined,
|
|
126
|
+
diskGb: t.storage ?? undefined,
|
|
127
|
+
region: loc,
|
|
128
|
+
pricePerHour: price,
|
|
129
|
+
deployStyle: "vm-ssh",
|
|
130
|
+
available: true,
|
|
131
|
+
raw: { instance_type: t.instance_type ?? t.id, location: loc, type: t }
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return offers;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
_buildUserData(envMap, opts = {}) {
|
|
139
|
+
if (opts.engine === "vllm") {
|
|
140
|
+
return composeInstallScript({ infernetEnv: envMap, vllmConfig: opts.vllmConfig ?? {} });
|
|
141
|
+
}
|
|
142
|
+
const exports = Object.entries(envMap).map(([k, v]) => `export ${k}=${JSON.stringify(String(v))}`).join("\n");
|
|
143
|
+
return ["#!/bin/bash", "set -eux", exports,
|
|
144
|
+
`curl -fsSL ${DEFAULT_INSTALLER} | bash`,
|
|
145
|
+
"infernet register || true", "infernet start || true"].join("\n");
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async createNode(request = {}) {
|
|
149
|
+
const {
|
|
150
|
+
gpu, name, instanceType, region, sshKeyIds = [], image = "ubuntu-22.04-cuda-12.0",
|
|
151
|
+
env = {}, controlPlaneUrl = "", engine = "ollama", model = null,
|
|
152
|
+
hourlyPrice = 0, vramGb = 0, gpuCount = 1
|
|
153
|
+
} = request;
|
|
154
|
+
|
|
155
|
+
if (sshKeyIds.length === 0) {
|
|
156
|
+
throw new Error("datacrunch: createNode requires sshKeyIds (upload via POST /sshkeys first)");
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
let finalType = instanceType;
|
|
160
|
+
let finalLocation = region;
|
|
161
|
+
if (!finalType) {
|
|
162
|
+
const offers = await this.findOffers({ gpu, region });
|
|
163
|
+
if (offers.length === 0) throw new Error(`datacrunch: no instance type matched gpu="${gpu}"`);
|
|
164
|
+
offers.sort((a, b) => a.pricePerHour - b.pricePerHour);
|
|
165
|
+
finalType = offers[0].raw.instance_type;
|
|
166
|
+
finalLocation = finalLocation ?? offers[0].raw.location;
|
|
167
|
+
}
|
|
168
|
+
if (!finalLocation) throw new Error("datacrunch: createNode requires region");
|
|
169
|
+
|
|
170
|
+
const localId = state.generateNodeId();
|
|
171
|
+
const vmName = name ?? localId;
|
|
172
|
+
|
|
173
|
+
const userData = this._buildUserData({
|
|
174
|
+
INFERNET_NODE_NAME: vmName,
|
|
175
|
+
INFERNET_CONTROL_PLANE_URL: controlPlaneUrl,
|
|
176
|
+
INFERNET_ENGINE: engine,
|
|
177
|
+
...(model ? { INFERNET_MODEL: model } : {}),
|
|
178
|
+
...env
|
|
179
|
+
}, { engine, vllmConfig: { model, ...(request.vllm ?? {}) } });
|
|
180
|
+
|
|
181
|
+
const data = await this._request("POST", "/instances", {
|
|
182
|
+
instance_type: finalType,
|
|
183
|
+
location_code: finalLocation,
|
|
184
|
+
image,
|
|
185
|
+
ssh_key_ids: sshKeyIds,
|
|
186
|
+
hostname: vmName,
|
|
187
|
+
description: vmName,
|
|
188
|
+
user_data: userData
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const vmId = data?.id ?? data?.instance_id;
|
|
192
|
+
if (!vmId) throw new Error("datacrunch: create returned no instance id");
|
|
193
|
+
|
|
194
|
+
const record = {
|
|
195
|
+
id: localId,
|
|
196
|
+
provider: "datacrunch",
|
|
197
|
+
providerNodeId: vmId,
|
|
198
|
+
name: vmName,
|
|
199
|
+
gpu: gpu ?? finalType,
|
|
200
|
+
gpuCount,
|
|
201
|
+
vramGb,
|
|
202
|
+
region: finalLocation,
|
|
203
|
+
hourlyPrice,
|
|
204
|
+
engine,
|
|
205
|
+
model: model ?? undefined,
|
|
206
|
+
status: "creating",
|
|
207
|
+
createdAt: new Date().toISOString(),
|
|
208
|
+
controlPlaneUrl
|
|
209
|
+
};
|
|
210
|
+
await state.saveNode(record);
|
|
211
|
+
return record;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async waitUntilReady(node, timeoutMs = 5 * 60 * 1000) {
|
|
215
|
+
if (!node?.providerNodeId) throw new Error("datacrunch: waitUntilReady requires node.providerNodeId");
|
|
216
|
+
const deadline = Date.now() + timeoutMs;
|
|
217
|
+
while (Date.now() < deadline) {
|
|
218
|
+
const inst = await this._request("GET", `/instances/${node.providerNodeId}`);
|
|
219
|
+
const status = (inst?.status ?? "").toLowerCase();
|
|
220
|
+
const ip = inst?.ip ?? null;
|
|
221
|
+
if (status === "running" && ip) {
|
|
222
|
+
const endpointUrl = `http://${ip}:46337`;
|
|
223
|
+
return state.updateNode(node.id, { status: "running", endpointUrl, ip });
|
|
224
|
+
}
|
|
225
|
+
await new Promise((r) => setTimeout(r, 5000));
|
|
226
|
+
}
|
|
227
|
+
await state.updateNode(node.id, { status: "error", error_log: "instance did not reach RUNNING in time" });
|
|
228
|
+
throw new Error(`DataCrunch instance ${node.providerNodeId} did not reach RUNNING within ${Math.round(timeoutMs / 1000)}s`);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
async bootstrapNode(node, request = {}) {
|
|
232
|
+
if (!node?.endpointUrl && !node?.ip) return { ok: false, reason: "no endpointUrl/ip on node" };
|
|
233
|
+
if ((request.engine ?? node.engine) === "vllm") {
|
|
234
|
+
return pollVllmHealth(node.ip ?? node.endpointUrl, { port: request.vllm?.port ?? 8000 });
|
|
235
|
+
}
|
|
236
|
+
const healthEndpoint = `${node.endpointUrl}/health`;
|
|
237
|
+
const deadline = Date.now() + 5 * 60 * 1000;
|
|
238
|
+
let lastErr = null;
|
|
239
|
+
while (Date.now() < deadline) {
|
|
240
|
+
try {
|
|
241
|
+
const ctrl = new AbortController();
|
|
242
|
+
const t = setTimeout(() => ctrl.abort(), 5000);
|
|
243
|
+
const res = await fetch(healthEndpoint, { signal: ctrl.signal });
|
|
244
|
+
clearTimeout(t);
|
|
245
|
+
if (res.ok) return { ok: true, healthEndpoint };
|
|
246
|
+
lastErr = `HTTP ${res.status}`;
|
|
247
|
+
} catch (err) { lastErr = err?.message ?? String(err); }
|
|
248
|
+
await new Promise((r) => setTimeout(r, 10000));
|
|
249
|
+
}
|
|
250
|
+
return { ok: false, reason: lastErr ?? "bootstrap health-check timed out", healthEndpoint };
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
async getNode(nodeId) {
|
|
254
|
+
const local = await state.loadNode(nodeId);
|
|
255
|
+
if (!local || local.provider !== "datacrunch") throw new Error(`datacrunch: no local record for nodeId=${nodeId}`);
|
|
256
|
+
try {
|
|
257
|
+
const inst = await this._request("GET", `/instances/${local.providerNodeId}`);
|
|
258
|
+
if (inst?.status) local.liveStatus = inst.status;
|
|
259
|
+
} catch { /* best-effort */ }
|
|
260
|
+
return local;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
async listNodes() {
|
|
264
|
+
const all = await state.listNodes();
|
|
265
|
+
return all.filter((n) => n.provider === "datacrunch");
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async stopNode(nodeId) {
|
|
269
|
+
const local = await state.loadNode(nodeId);
|
|
270
|
+
if (!local || local.provider !== "datacrunch") throw new Error(`datacrunch: no local record for nodeId=${nodeId}`);
|
|
271
|
+
await this._request("PUT", "/instances", { id: local.providerNodeId, action: "shutdown" });
|
|
272
|
+
await state.updateNode(nodeId, { status: "stopped" });
|
|
273
|
+
return { ok: true };
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async startNode(nodeId) {
|
|
277
|
+
const local = await state.loadNode(nodeId);
|
|
278
|
+
if (!local || local.provider !== "datacrunch") throw new Error(`datacrunch: no local record for nodeId=${nodeId}`);
|
|
279
|
+
await this._request("PUT", "/instances", { id: local.providerNodeId, action: "start" });
|
|
280
|
+
await state.updateNode(nodeId, { status: "running" });
|
|
281
|
+
return { ok: true };
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async destroyNode(nodeId) {
|
|
285
|
+
const local = await state.loadNode(nodeId);
|
|
286
|
+
if (!local || local.provider !== "datacrunch") throw new Error(`datacrunch: no local record for nodeId=${nodeId}`);
|
|
287
|
+
await this._request("DELETE", `/instances/${local.providerNodeId}`);
|
|
288
|
+
await state.updateNode(nodeId, { status: "destroyed" });
|
|
289
|
+
return { ok: true };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
async logs(nodeId, _opts = {}) {
|
|
293
|
+
const local = await state.loadNode(nodeId).catch(() => null);
|
|
294
|
+
const err = new NotSupportedError("logs", "datacrunch");
|
|
295
|
+
const sshHint = local?.ip ? `\nSSH and tail the daemon log:\n ssh ubuntu@${local.ip} 'tail -200 /var/log/infernet/daemon.log'` : "";
|
|
296
|
+
err.message = `datacrunch: instance logs are not exposed via the API.\nView at: https://cloud.datacrunch.io/instances` + sshHint;
|
|
297
|
+
throw err;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export default DataCrunchProvider;
|