-
Notifications
You must be signed in to change notification settings - Fork 7
/
zmachine.ts
93 lines (83 loc) · 2.58 KB
/
zmachine.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
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
import { Expose, Transform, Type } from "class-transformer";
import {
IsBoolean,
IsDefined,
IsInt,
IsIP,
IsNotEmpty,
IsOptional,
IsString,
Max,
Min,
ValidateNested,
} from "class-validator";
import { ComputeCapacity } from "./computecapacity";
import { WorkloadData, WorkloadDataResult } from "./workload_base";
class ZNetworkInterface {
@Expose() @IsString() @IsNotEmpty() network: string;
@Expose() @IsIP() @IsNotEmpty() ip: string;
}
class ZmachineNetwork {
@Expose() @IsString() @IsDefined() public_ip: string;
@Expose() @Type(() => ZNetworkInterface) @ValidateNested({ each: true }) interfaces: ZNetworkInterface[];
@Expose() @IsBoolean() planetary: boolean;
challenge(): string {
let out = "";
out += this.public_ip;
out += this.planetary.toString();
for (let i = 0; i < this.interfaces.length; i++) {
out += this.interfaces[i].network;
out += this.interfaces[i].ip;
}
return out;
}
}
class Mount {
@Expose() @IsString() @IsNotEmpty() name: string;
@Expose() @IsString() @IsNotEmpty() mountpoint: string;
challenge(): string {
let out = "";
out += this.name;
out += this.mountpoint;
return out;
}
}
class Zmachine extends WorkloadData {
@Expose() @IsString() @IsNotEmpty() flist: string;
@Expose() @Type(() => ZmachineNetwork) @ValidateNested() network: ZmachineNetwork;
@Expose() @IsInt() @Max(10 * 1024 ** 4) size: number; // in bytes
@Expose() @Type(() => ComputeCapacity) @ValidateNested() compute_capacity: ComputeCapacity;
@Expose() @Type(() => Mount) @ValidateNested({ each: true }) mounts: Mount[];
@Expose() @IsString() @IsNotEmpty() entrypoint: string;
@Expose() env: Record<string, unknown>;
@Expose() @Transform(({ value }) => (value ? true : false)) @IsBoolean() corex: boolean;
@Expose() @IsString({ each: true }) @IsOptional() gpu?: string[];
challenge(): string {
let out = "";
out += this.flist;
out += this.network.challenge();
out += this.size || "0";
out += this.compute_capacity.challenge();
for (let i = 0; i < this.mounts.length; i++) {
out += this.mounts[i].challenge();
}
out += this.entrypoint;
for (const key of Object.keys(this.env).sort()) {
out += key;
out += "=";
out += this.env[key];
if (this.gpu) {
for (const g of this.gpu) {
out += g;
}
}
}
return out;
}
}
class ZmachineResult extends WorkloadDataResult {
@Expose() id: string;
@Expose() ip: string;
@Expose() ygg_ip: string;
}
export { Zmachine, ZmachineNetwork, ZNetworkInterface, Mount, ZmachineResult };