Skip to content

Commit db2daf4

Browse files
Merge pull request #2929 from threefoldtech/development_2.6
Development 2.6
2 parents 11fa297 + eb39bcb commit db2daf4

File tree

122 files changed

+15544
-498
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+15544
-498
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: Full Clients Build
55

66
on:
77
push:
8-
branches: [development, development_314]
8+
branches: [development, development_2.6]
99
pull_request:
10-
branches: [development, development_314]
10+
branches: [development, development_2.6]
1111

1212
jobs:
1313
build:

.github/workflows/link_checker.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Link Checker
2+
3+
on:
4+
schedule:
5+
- cron: '0 8 * * *'
6+
7+
jobs:
8+
check-links:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- name: Link Checker
14+
id: checker
15+
uses: docker://ghcr.io/threefoldfoundation/website-link-checker:latest
16+
with:
17+
args: 'https://staging.dashboard.dev.grid.tf -e 404 501 503 504 -w all'

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ name: Full Clients Lint
55

66
on:
77
push:
8-
branches: [development, development_314]
8+
branches: [development, development_2.6]
99
pull_request:
10-
branches: [development, development_314]
10+
branches: [development, development_2.6]
1111

1212
jobs:
1313
lint:

.github/workflows/playground_build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ on:
66
push:
77
branches:
88
- development
9-
- development_314
9+
- development_2.6
1010
paths:
1111
- "packages/playground/**"
1212
pull_request:
1313
branches:
1414
- development
15-
- development_314
15+
- development_2.6
1616
paths:
1717
- "packages/playground/**"
1818

.github/workflows/stats_build.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ name: Stats Build
44

55
on:
66
push:
7-
branches: [development, development_314]
7+
branches: [development, development_2.6]
88
paths:
99
- "packages/stats/**"
1010
pull_request:
11-
branches: [development, development_314]
11+
branches: [development, development_2.6]
1212
paths:
1313
- "packages/stats/**"
1414

.github/workflows/yarn_audit.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# When the action is executed, it runs yarn audit command in all the paths that is mentioned in the input. The exit codes of the commands are compared and if it is greater than 7 (only high severity as of now), the action will try to fetch the open issues in the repo with the label provided in the input. The label is mandatory to prevent from creating duplicate issues. If there are no open issues with the given label in open state, the action will try to create a Github Issue with the details provided in the input.
2+
3+
name: Full Clients Audit
4+
5+
on:
6+
push:
7+
branches: [development, development_2.6]
8+
pull_request:
9+
branches: [development, development_2.6]
10+
11+
jobs:
12+
audit-and-open-issue:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Yarn Audit
17+
uses: pragatheeswarans/[email protected]
18+
with:
19+
token: ${{ github.token }}
20+
label: 'audit'
21+
title: "${{ github.workflow }}: Critical Security Vulnerability Identified"
22+
description: 'High severity issues are identified in the repo.'
23+
paths: |
24+
.

packages/grid_client/scripts/single_vm.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
import { MachinesModel } from "../src";
1+
import { GridClient, MachinesModel } from "../src";
2+
import { type ZmachineData } from "../src/helpers/types";
23
import { config, getClient } from "./client_loader";
34
import { log } from "./utils";
45

5-
async function deploy(client, vms) {
6+
async function deploy(client: GridClient, vms: MachinesModel) {
67
const res = await client.machines.deploy(vms);
78
log("================= Deploying VM =================");
89
log(res);
910
log("================= Deploying VM =================");
1011
}
1112

12-
async function getDeployment(client, vms) {
13-
const res = await client.machines.getObj(vms);
13+
async function getDeployment(client: GridClient, name: string): Promise<ZmachineData[]> {
14+
const res = await client.machines.getObj(name);
1415
log("================= Getting deployment information =================");
1516
log(res);
1617
log("================= Getting deployment information =================");
18+
return res;
1719
}
1820

19-
async function cancel(client, vms) {
20-
const res = await client.machines.delete(vms);
21+
async function cancel(client: GridClient, name: string) {
22+
const res = await client.machines.delete({ name: name });
2123
log("================= Canceling the deployment =================");
2224
log(res);
2325
log("================= Canceling the deployment =================");
@@ -69,7 +71,7 @@ async function main() {
6971
await getDeployment(grid3, name);
7072

7173
//Uncomment the line below to cancel the deployment
72-
// await cancel(grid3, { name });
74+
// await cancel(grid3, name);
7375

7476
await grid3.disconnect();
7577
}

packages/grid_client/src/helpers/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ export * from "./events";
44
export * from "./validator";
55
export * from "./expose";
66
export * from "./migration";
7+
export * from "./root_fs";
8+
export * from "./types";
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Decimal } from "decimal.js";
2+
3+
const GB = 1024;
4+
5+
interface RootFSOptions {
6+
/** The machine CPU, should be in cores e.g. 5 cores*/
7+
CPUCores: number;
8+
/** The machine memory, should be in megabytes e.g. 1024 or 2048 MG*/
9+
RAMInMegaBytes: number;
10+
}
11+
12+
/**
13+
* Calculate the root filesystem size (CU - Compute Units) based on provided options.
14+
*
15+
* This function calculates the compute units (CU) required based on the CPU cores and RAM in megabytes.
16+
* If both CPU cores and RAM are provided in the `options` parameter, it calculates CU by multiplying
17+
* the CPU cores with RAM and dividing by 8 * GB, then converting the result to an integer. If the
18+
* calculated CU is zero, it returns 500 / GB; otherwise, it returns 2.
19+
*
20+
* @param {RootFSOptions} [options] - Optional configuration object.
21+
* @param {number} [options.CPUCores] - The number of CPU cores.
22+
* @param {number} [options.RAMInMegaBytes] - The RAM size in megabytes.
23+
*
24+
* @returns {number} - The calculated compute units (CU) based on the provided options.
25+
*/
26+
function calculateRootFileSystem(options?: RootFSOptions): number {
27+
let cu = 0;
28+
29+
if (options && options.CPUCores && options.RAMInMegaBytes) {
30+
cu = new Decimal(options.CPUCores)
31+
.mul(options.RAMInMegaBytes)
32+
.divToInt(8 * GB)
33+
.toNumber();
34+
}
35+
36+
return cu === 0 ? 500 / GB : 2;
37+
}
38+
39+
export { calculateRootFileSystem, RootFSOptions };
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { PublicIPResult, ResultStates } from "../zos";
2+
3+
interface NetworkInterface {
4+
/** The network identifier */
5+
network: string;
6+
/** The IP address of the interface */
7+
ip: string;
8+
}
9+
10+
interface ComputeCapacity {
11+
/** Number of CPU cores allocated */
12+
cpu: number;
13+
/** Amount of memory allocated in MB */
14+
memory: number;
15+
}
16+
17+
interface BaseMountData {
18+
/** The name of the mount */
19+
name: string;
20+
/** The mount point in the filesystem */
21+
mountPoint: string;
22+
}
23+
24+
interface ExtendedMountData extends BaseMountData {
25+
/** The size of the mount (optional) */
26+
size?: number;
27+
/** The state of the mount result (optional) */
28+
state?: ResultStates;
29+
/** Message providing additional information about the mount result (optional) */
30+
message?: string;
31+
/** Cache information (optional) */
32+
cache?: any;
33+
/** Prefix information (optional) */
34+
prefix?: any;
35+
/** Minimal shards (optional) */
36+
minimal_shards?: number;
37+
/** Expected shards (optional) */
38+
expected_shards?: number;
39+
/** QSFS ZDBs name (optional) */
40+
qsfs_zdbs_name?: string;
41+
/** Metrics endpoint (optional) */
42+
metricsEndpoint?: string;
43+
}
44+
45+
// Union type for the mount data
46+
type MountData = BaseMountData | ExtendedMountData;
47+
48+
interface ZmachineData {
49+
/** The version of the workload */
50+
version: number;
51+
/** The contract ID associated with the workload */
52+
contractId: number;
53+
/** The node ID where the workload is deployed */
54+
nodeId: string;
55+
/** The name of the workload */
56+
name: string;
57+
/** The creation timestamp of the workload result */
58+
created: number;
59+
/** The current state of the workload */
60+
status: string;
61+
/** Message providing additional information about the workload state */
62+
message: string;
63+
/** The flist (file list) used by the workload */
64+
flist: string;
65+
/** The public IP address obtained by the machine */
66+
publicIP: PublicIPResult;
67+
/** The planetary IP address of the machine */
68+
planetary: string;
69+
/** The Mycelium IP address of the machine, if applicable */
70+
myceliumIP: string;
71+
/** List of network interfaces */
72+
interfaces: NetworkInterface[];
73+
/** The compute capacity (CPU and memory) allocated to the machine */
74+
capacity: ComputeCapacity;
75+
/** List of mounts associated with the machine */
76+
mounts: MountData[];
77+
/** Environment variables set for the workload */
78+
env: Record<string, unknown>;
79+
/** The entrypoint command for the workload */
80+
entrypoint: string;
81+
/** Metadata associated with the workload */
82+
metadata: string;
83+
/** Description of the workload */
84+
description: string;
85+
/** Size of the root filesystem */
86+
rootfs_size: number;
87+
/** Indicates if corex is enabled */
88+
corex: boolean;
89+
/** The list of the GPUs */
90+
gpu: string[] | undefined;
91+
}
92+
93+
interface VM extends ZmachineData {
94+
customDomain?: string;
95+
deploymentName: string;
96+
projectName: string;
97+
wireguard: string;
98+
}
99+
100+
export { ZmachineData, VM };

packages/grid_client/src/high_level/machine.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { GridClientErrors, ValidationError } from "@threefold/types";
22
import { Addr } from "netaddr";
33

44
import { events } from "../helpers/events";
5+
import { calculateRootFileSystem } from "../helpers/root_fs";
56
import { randomChoice, zeroPadding } from "../helpers/utils";
67
import { validateHexSeed } from "../helpers/validator";
78
import { DiskModel, MyceliumNetworkModel, QSFSDiskModel } from "../modules/models";
@@ -53,6 +54,12 @@ class VMHL extends HighLevelBase {
5354
zlogsOutput?: string,
5455
gpus: string[] = [],
5556
): Promise<[TwinDeployment[], string]> {
57+
if (!rootfs_size) {
58+
rootfs_size = calculateRootFileSystem({
59+
CPUCores: cpu,
60+
RAMInMegaBytes: memory,
61+
});
62+
}
5663
const deployments: TwinDeployment[] = [];
5764
const workloads: Workload[] = [];
5865
let totalDisksSize = rootfs_size;

packages/grid_client/src/modules/base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { GqlNodeContract, RMB } from "../clients";
66
import { TFClient } from "../clients/tf-grid/client";
77
import { GridClientConfig } from "../config";
88
import { formatErrorMessage } from "../helpers";
9+
import { type ZmachineData } from "../helpers/types";
910
import { HighLevelBase } from "../high_level/base";
1011
import { KubernetesHL } from "../high_level/kubernetes";
1112
import { VMHL } from "../high_level/machine";
@@ -306,7 +307,7 @@ class BaseModule {
306307
return null;
307308
}
308309

309-
async _getZmachineData(deploymentName: string, deployments, workload: Workload): Promise<Record<string, unknown>> {
310+
async _getZmachineData(deploymentName: string, deployments, workload: Workload): Promise<ZmachineData> {
310311
const data = workload.data as Zmachine;
311312
const resultData = workload.result.data as ZmachineResult;
312313
return {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { ComputeCapacity, Mount, Zmachine, ZmachineNetwork } from "../../src";
2+
3+
const zmachine = new Zmachine();
4+
5+
beforeAll(() => {
6+
const computeCapacity = new ComputeCapacity();
7+
computeCapacity.cpu = 1;
8+
computeCapacity.memory = 5;
9+
10+
const network = new ZmachineNetwork();
11+
network.planetary = true;
12+
network.public_ip = "10.249.0.0/16";
13+
network.interfaces = [
14+
{
15+
network: "znetwork",
16+
ip: "10.20.2.2",
17+
},
18+
];
19+
20+
const rootfs_size = 2;
21+
22+
const disks = new Mount();
23+
disks.name = "zdisk";
24+
disks.mountpoint = "/mnt/data";
25+
26+
zmachine.flist = "https://hub.grid.tf/tf-official-vms/ubuntu-22.04.flist";
27+
zmachine.network = network;
28+
zmachine.size = rootfs_size * 1024 ** 3;
29+
zmachine.mounts = [disks];
30+
zmachine.entrypoint = "/sbin/zinit init";
31+
zmachine.compute_capacity = computeCapacity;
32+
zmachine.env = {};
33+
zmachine.corex = false;
34+
zmachine.gpu = [];
35+
});
36+
37+
describe("Zmachine Class Tests", () => {
38+
it("should create a valid Zmachine instance", () => {
39+
expect(zmachine).toBeInstanceOf(Zmachine);
40+
});
41+
42+
it("should correctly compute the challenge string", () => {
43+
const expectedChallenge =
44+
"https://hub.grid.tf/tf-official-vms/ubuntu-22.04.flist" +
45+
"10.249.0.0/16" +
46+
"true" +
47+
"znetwork" +
48+
"10.20.2.22" +
49+
"14748364815" +
50+
"zdisk" +
51+
"/mnt/data" +
52+
"/sbin/zinit init";
53+
54+
expect(zmachine.challenge()).toBe(expectedChallenge);
55+
});
56+
57+
it("should fail validation for missing required fields", () => {
58+
const result = () => {
59+
zmachine.flist = "";
60+
zmachine.entrypoint = "";
61+
};
62+
expect(result).toThrow();
63+
});
64+
});

0 commit comments

Comments
 (0)