-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmultiple_vms.ts
More file actions
124 lines (110 loc) · 3.31 KB
/
Copy pathmultiple_vms.ts
File metadata and controls
124 lines (110 loc) · 3.31 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { FilterOptions, generateString, GridClient, MachinesModel } from "../src";
import { FLISTS } from "../src/helpers/flists";
import { config, getClient } from "./client_loader";
import { log, pingNodes } from "./utils";
async function deploy(client: GridClient, vms: MachinesModel) {
const res = await client.machines.deploy(vms);
log("================= Deploying VM =================");
log(res);
log("================= Deploying VM =================");
}
async function getDeployment(client: GridClient, name: string) {
const res = await client.machines.getObj(name);
log("================= Getting deployment information =================");
log(res);
log("================= Getting deployment information =================");
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async function cancel(client: GridClient, name: string) {
const res = await client.machines.delete({ name });
log("================= Canceling the deployment =================");
log(res);
log("================= Canceling the deployment =================");
}
async function getNodeId(client: GridClient, options: FilterOptions) {
const nodes = await client.capacity.filterNodes(options);
const nodeId = await pingNodes(client, nodes);
return nodeId;
}
async function main() {
const name = "vm" + generateString(6);
const networkName = "nw" + generateString(6);
const machine1Name = "machine" + generateString(6);
const machine2Name = "machine" + generateString(6);
const disk1Name = "disk" + generateString(6);
const disk2Name = "disk" + generateString(6);
const grid3 = await getClient(`vm/${name}`);
const vmQueryOptions: FilterOptions = {
cru: 1,
mru: 1, // GB
sru: 14,
availableFor: grid3.twinId,
farmId: 1,
};
const nodeId = await getNodeId(grid3, vmQueryOptions);
const vms: MachinesModel = {
name,
network: {
name: networkName,
ip_range: "10.238.0.0/16",
},
machines: [
{
name: machine1Name,
node_id: nodeId!,
disks: [
{
name: disk1Name,
size: 5,
mountpoint: "/newDisk1",
},
],
public_ip: false,
public_ip6: false,
planetary: true,
mycelium: true,
cpu: 1,
memory: 1024,
rootfs_size: 0,
flist: FLISTS.MICROVMS_UBUNTU_24.flist,
entrypoint: FLISTS.MICROVMS_UBUNTU_24.entryPoint,
env: {
SSH_KEY: config.ssh_key,
},
},
{
name: machine2Name,
node_id: nodeId!,
disks: [
{
name: disk2Name,
size: 5,
mountpoint: "/newDisk2",
},
],
public_ip: false,
public_ip6: false,
planetary: true,
mycelium: true,
cpu: 1,
memory: 1024,
rootfs_size: 0,
flist: FLISTS.MICROVMS_UBUNTU_24.flist,
entrypoint: FLISTS.MICROVMS_UBUNTU_24.entryPoint,
env: {
SSH_KEY: config.ssh_key,
},
},
],
metadata: "",
description: "test deploying VMs via ts grid3 client",
};
//Deploy VMs
await deploy(grid3, vms);
//Get the deployment
await getDeployment(grid3, name);
// Uncomment the line below to cancel the deployment
// await cancel(grid3, name);
await grid3.disconnect();
}
main();