-
Notifications
You must be signed in to change notification settings - Fork 7
/
vm.ts
66 lines (63 loc) · 2.21 KB
/
vm.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
57
58
59
60
61
62
63
64
65
66
import { ComputeCapacity } from "../zos/computecapacity";
import { Workload, WorkloadTypes } from "../zos/workload";
import { Mount, Zmachine, ZmachineNetwork, ZNetworkInterface } from "../zos/zmachine";
class VMPrimitive {
_createComputeCapacity(cpu: number, memory: number): ComputeCapacity {
const compute_capacity = new ComputeCapacity();
compute_capacity.cpu = cpu;
compute_capacity.memory = memory * 1024 ** 2;
return compute_capacity;
}
_createNetworkInterface(networkName: string, ip: string): ZNetworkInterface {
const znetwork_interface = new ZNetworkInterface();
znetwork_interface.network = networkName;
znetwork_interface.ip = ip;
return znetwork_interface;
}
_createMachineNetwork(networkName: string, ip: string, planetary: boolean, public_ip = ""): ZmachineNetwork {
const zmachine_network = new ZmachineNetwork();
zmachine_network.planetary = planetary;
zmachine_network.interfaces = [this._createNetworkInterface(networkName, ip)];
zmachine_network.public_ip = public_ip;
return zmachine_network;
}
create(
name: string,
flist: string,
cpu: number,
memory: number,
rootfs_size: number,
disks: Mount[],
networkName: string,
ip: string,
planetary: boolean,
public_ip: string,
entrypoint: string,
env: Record<string, unknown>,
metadata = "",
description = "",
version = 0,
corex = false,
gpus: string[] = [],
): Workload {
const zmachine = new Zmachine();
zmachine.flist = flist;
zmachine.network = this._createMachineNetwork(networkName, ip, planetary, public_ip);
zmachine.size = rootfs_size * 1024 ** 3;
zmachine.mounts = disks;
zmachine.entrypoint = entrypoint;
zmachine.compute_capacity = this._createComputeCapacity(cpu, memory);
zmachine.env = env;
zmachine.corex = corex;
zmachine.gpu = gpus;
const zmachine_workload = new Workload();
zmachine_workload.version = version || 0;
zmachine_workload.name = name;
zmachine_workload.type = WorkloadTypes.zmachine;
zmachine_workload.data = zmachine;
zmachine_workload.metadata = metadata;
zmachine_workload.description = description;
return zmachine_workload;
}
}
export { VMPrimitive };