-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathvpn.ts
56 lines (53 loc) · 1.62 KB
/
vpn.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { MarketOrderSpec, GolemNetwork } from "@golem-sdk/golem-js";
import { pinoPrettyLogger } from "@golem-sdk/pino-logger";
(async () => {
const glm = new GolemNetwork({
logger: pinoPrettyLogger({
level: "info",
}),
});
try {
await glm.connect();
const network = await glm.createNetwork({ ip: "192.168.7.0/24" });
const order: MarketOrderSpec = {
demand: {
workload: {
imageTag: "golem/alpine:latest",
capabilities: ["vpn"],
},
},
market: {
rentHours: 0.5,
pricing: {
model: "linear",
maxStartPrice: 0.5,
maxCpuPerHourPrice: 1.0,
maxEnvPerHourPrice: 0.5,
},
},
network,
};
// create a pool that can grow up to 2 rentals at the same time
const pool = await glm.manyOf({
poolSize: 2,
order,
});
const rental1 = await pool.acquire();
const rental2 = await pool.acquire();
const exe1 = await rental1.getExeUnit();
const exe2 = await rental2.getExeUnit();
await exe1
.run(`ping ${exe2.getIp()} -c 4`)
.then((res) => console.log(`Response from provider: ${exe1.provider.name} (ip: ${exe1.getIp()})`, res.stdout));
await exe2
.run(`ping ${exe1.getIp()} -c 4`)
.then((res) => console.log(`Response from provider: ${exe2.provider.name} (ip: ${exe2.getIp()})`, res.stdout));
await pool.destroy(rental1);
await pool.destroy(rental2);
await glm.destroyNetwork(network);
} catch (err) {
console.error("Failed to run the example", err);
} finally {
await glm.disconnect();
}
})().catch(console.error);