Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mycelium on grid client deployments #2130

Merged
merged 34 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f6f4ad6
add mycelium in gridclient
AlaaElattar Feb 6, 2024
b619b48
remove TODOS and debugging logs
AlaaElattar Feb 6, 2024
8b6cb94
separate validation and validation of hexseed to be shared in helpers…
AlaaElattar Feb 6, 2024
e659d78
modify generation of mycelium seed to be from ip
AlaaElattar Feb 7, 2024
bf13369
fix scripts with adding mycelium field with false
AlaaElattar Feb 7, 2024
b9894bf
update generating seed && handle scenario when updating existing netw…
AlaaElattar Feb 8, 2024
a721411
second issue fixed and working on adding mycelium from all solutions
AlaaElattar Feb 8, 2024
5470c09
remove my ssh key && mnemonic from conf file of scripts
AlaaElattar Feb 8, 2024
f5ac57e
fix build
AlaaElattar Feb 8, 2024
60f116f
support mycelium in all solutions
AlaaElattar Feb 11, 2024
042c345
change myce;ium to false in scripts
AlaaElattar Feb 11, 2024
fcc4e2e
move splitting id inside mycelium condition && remove debug logs
AlaaElattar Feb 11, 2024
ee7324f
rename mycelium_network_seed to myceliumNetworkSeed
AlaaElattar Feb 11, 2024
f34cd8e
rename to myceliumNetworkSeed
AlaaElattar Feb 11, 2024
1b5ee8b
check hex_key not empty && remove each true
AlaaElattar Feb 11, 2024
461c89d
check length of myceliumSeed && myceliumNetwrokSeed
AlaaElattar Feb 11, 2024
af5603e
rename mycelium seed to netwekAddNodeModel
AlaaElattar Feb 11, 2024
384feb2
fix renaming in addNode
AlaaElattar Feb 12, 2024
e34e049
support providing multiple seeds for network with each nodeId
AlaaElattar Feb 12, 2024
0857c58
provide 2 scripts with mycelium && fix bug in validator function && f…
AlaaElattar Feb 12, 2024
4404e2e
Merge branch 'development' into development_add_mycelium
AlaaElattar Feb 12, 2024
3c09e2c
fix renaming && apply comments
AlaaElattar Feb 12, 2024
8880615
modify zeroPadding to take only one number with length not array
AlaaElattar Feb 12, 2024
c5b3bc5
update renaming to myceliumNetworkSeeds
AlaaElattar Feb 12, 2024
b541a66
remove else and initialize seed random
AlaaElattar Feb 12, 2024
520d4e6
update mycelium seed inside MyceliumNetworkModel to seed
AlaaElattar Feb 12, 2024
babf42f
make seeds commented in k8s.ts to make user feels they're optional
AlaaElattar Feb 13, 2024
6eb6fe2
check for myceliumSeeds length
AlaaElattar Feb 13, 2024
fe13722
move generateHexSeed && zeroPadding to utils file
AlaaElattar Feb 13, 2024
7a1d869
update scripts && comment HexSeeds
AlaaElattar Feb 13, 2024
e43c1a1
add docs file for mycelium && move myelium md file and wg file in net…
AlaaElattar Feb 13, 2024
60e96c1
fix explanation says its overlay ipv6 not replacing it
AlaaElattar Feb 13, 2024
d51b9c7
add example for updating existing network with mycelium
AlaaElattar Feb 13, 2024
cf48d4c
fix typos
AlaaElattar Feb 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/grid_client/scripts/add_node_to_network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ async function main() {
name: "wedtest",
ipRange: "10.249.0.0/16",
nodeId: 14,
mycelium: false,
};
// if the network is not created, it will create one and add this node to it.
await addNode(grid3, node);
Expand Down
1 change: 1 addition & 0 deletions packages/grid_client/scripts/add_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async function main() {
public_ip: false,
public_ip6: false,
planetary: true,
mycelium: false,
};

//Add Worker
Expand Down
1 change: 1 addition & 0 deletions packages/grid_client/scripts/caprover_leader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async function main() {
public_ip: true,
public_ip6: false,
planetary: false,
mycelium: false,
cpu: 4,
memory: 1024 * 4,
rootfs_size: 0,
Expand Down
1 change: 1 addition & 0 deletions packages/grid_client/scripts/caprover_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async function main() {
public_ip: true,
public_ip6: false,
planetary: false,
mycelium: false,
cpu: 4,
memory: 1024 * 4,
rootfs_size: 0,
Expand Down
1 change: 1 addition & 0 deletions packages/grid_client/scripts/dynamic_single_vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async function main() {
public_ip: false,
public_ip6: false,
planetary: true,
mycelium: false,
cpu: 1,
memory: 1024,
rootfs_size: 0,
Expand Down
2 changes: 2 additions & 0 deletions packages/grid_client/scripts/kubernetes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ async function main() {
public_ip: false,
public_ip6: false,
planetary: true,
mycelium: true,
},
],
workers: [
Expand All @@ -74,6 +75,7 @@ async function main() {
public_ip: false,
public_ip6: false,
planetary: true,
mycelium: true,
},
],
metadata: "",
Expand Down
111 changes: 111 additions & 0 deletions packages/grid_client/scripts/kubernetes_mycelium.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { FilterOptions, K8SModel } from "../src";
import { config, getClient } from "./client_loader";
import { log } from "./utils";

async function deploy(client, k8s) {
const res = await client.k8s.deploy(k8s);
log("================= Deploying K8s =================");
log(res);
log("================= Deploying K8s =================");
}

async function getDeployment(client, k8s) {
const res = await client.k8s.getObj(k8s);
log("================= Getting deployment information =================");
log(res);
log("================= Getting deployment information =================");
}

async function cancel(client, k8s) {
const res = await client.k8s.delete(k8s);
log("================= Canceling the deployment =================");
log(res);
log("================= Canceling the deployment =================");
}

async function main() {
const grid3 = await getClient();

const k: K8SModel = {
name: "testk8sMy",
secret: "secret",
network: {
name: "monNetwork",
ip_range: "10.238.0.0/16",
addAccess: true,
myceliumSeed: [
{
nodeId: 153,
myceliumSeed: "a5f0ea16a744af2c0c23fc878d727a6f355079f82d979ad4bc75dd8fb5ebc90e",
},
{
nodeId: 31,
myceliumSeed: "7edd9c250f834cb326c3cf116040cf2214f38c669bf27a72e2f5b9e44fc7b27e",
},
{
nodeId: 177,
myceliumSeed: "3162379d1d2530e2113ae2c7142370cc195628238fa1059f2f25ef51c113e892",
},
],
},
masters: [
{
name: "masterMy",
node_id: 153,
cpu: 1,
memory: 1024,
rootfs_size: 0,
disk_size: 1,
public_ip: false,
public_ip6: false,
planetary: true,
mycelium: true,
myceliumSeed: "1791fed39e0f",
AlaaElattar marked this conversation as resolved.
Show resolved Hide resolved
},
],
workers: [
{
name: "worker1",
node_id: 31,
cpu: 1,
memory: 1024,
rootfs_size: 0,
disk_size: 1,
public_ip: false,
public_ip6: false,
planetary: true,
mycelium: true,
myceliumSeed: "580bafd349f5",
},
{
name: "worker2",
node_id: 177,
cpu: 1,
memory: 1024,
rootfs_size: 0,
disk_size: 1,
public_ip: false,
public_ip6: false,
planetary: true,
mycelium: true,
myceliumSeed: "0378c83a7e1f",
},
],
metadata: "",
description: "test deploying k8s with mycelium via ts grid3 client",
ssh_key: config.ssh_key,
};

//Deploy K8s
await deploy(grid3, k);

//Get the deployment
await getDeployment(grid3, k.name);

//Uncomment the line below to cancel the deployment
// await cancel(grid3, { name: k.name });

await grid3.disconnect();
}

main();
2 changes: 2 additions & 0 deletions packages/grid_client/scripts/kubernetes_with_qsfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ async function main() {
public_ip: false,
public_ip6: false,
planetary: true,
mycelium: false,
qsfs_disks: [
{
qsfs_zdbs_name: qsfs_name,
Expand All @@ -127,6 +128,7 @@ async function main() {
public_ip: false,
public_ip6: false,
planetary: true,
mycelium: false,
},
],
metadata: "",
Expand Down
1 change: 1 addition & 0 deletions packages/grid_client/scripts/mass_deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ async function main() {
vm.disks = [];
vm.public_ip = publicIp;
vm.planetary = true;
vm.mycelium = false;
vm.cpu = cru;
vm.memory = mru;
vm.rootfs_size = rootFs;
Expand Down
2 changes: 2 additions & 0 deletions packages/grid_client/scripts/multiple_vms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async function main() {
public_ip: false,
public_ip6: false,
planetary: true,
mycelium: false,
cpu: 1,
memory: 1024,
rootfs_size: 0,
Expand All @@ -76,6 +77,7 @@ async function main() {
public_ip: false,
public_ip6: false,
planetary: true,
mycelium: false,
cpu: 1,
memory: 1024,
rootfs_size: 0,
Expand Down
3 changes: 2 additions & 1 deletion packages/grid_client/scripts/single_vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function main() {
machines: [
{
name: "testvm",
node_id: 17,
node_id: 11,
disks: [
{
name: "wedDisk",
Expand All @@ -46,6 +46,7 @@ async function main() {
public_ip: false,
public_ip6: false,
planetary: true,
mycelium: false,
cpu: 1,
memory: 1024 * 2,
rootfs_size: 0,
Expand Down
83 changes: 83 additions & 0 deletions packages/grid_client/scripts/single_vm_mycelium.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { MachinesModel } from "../src";
import { config, getClient } from "./client_loader";
import { log } from "./utils";

async function deploy(client, vms) {
const res = await client.machines.deploy(vms);
log("================= Deploying VM =================");
log(res);
log("================= Deploying VM =================");
}

async function getDeployment(client, vms) {
const res = await client.machines.getObj(vms);
log("================= Getting deployment information =================");
log(res);
log("================= Getting deployment information =================");
}

async function cancel(client, vms) {
const res = await client.machines.delete(vms);
log("================= Canceling the deployment =================");
log(res);
log("================= Canceling the deployment =================");
}

async function main() {
const grid3 = await getClient();

const vms: MachinesModel = {
name: "newMY",
network: {
name: "hellotest",
ip_range: "10.249.0.0/16",
myceliumSeed: [
{
nodeId: 168,
myceliumSeed: "050d109829d8492d48bfb33b711056080571c69e46bfde6b4294c4c5bf468a76",
},
],
},
machines: [
{
name: "testvmMY",
node_id: 168,
disks: [
{
name: "wedDisk",
size: 8,
mountpoint: "/testdisk",
},
],
public_ip: false,
public_ip6: false,
planetary: true,
mycelium: true,
myceliumSeed: "1e1404279b3d",
cpu: 1,
memory: 1024 * 2,
rootfs_size: 0,
flist: "https://hub.grid.tf/tf-official-apps/base:latest.flist",
entrypoint: "/sbin/zinit init",
env: {
SSH_KEY: config.ssh_key,
},
},
],
metadata: "",
description: "test deploying single VM with mycelium via ts grid3 client",
};

//Deploy VMs
await deploy(grid3, vms);

//Get the deployment
await getDeployment(grid3, vms.name);

//Uncomment the line below to cancel the deployment
// await cancel(grid3, { name: vms.name });

await grid3.disconnect();
}

main();
1 change: 1 addition & 0 deletions packages/grid_client/scripts/vm_with_gpu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ async function main() {
public_ip: false,
public_ip6: false,
planetary: true,
mycelium: false,
cpu: 8,
memory: 1024 * 16,
rootfs_size: 0,
Expand Down
1 change: 1 addition & 0 deletions packages/grid_client/scripts/vm_with_qsfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ async function main() {
public_ip: false,
public_ip6: false,
planetary: true,
mycelium: false,
cpu: 1,
memory: 1024,
rootfs_size: 0,
Expand Down
1 change: 1 addition & 0 deletions packages/grid_client/scripts/wireguard_vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function createMachineModel(node: number) {
node_id: node,
public_ip: false,
planetary: true,
mycelium: false,
cpu: 1,
memory: 1024 * 2,
rootfs_size: 0,
Expand Down
22 changes: 21 additions & 1 deletion packages/grid_client/src/helpers/validator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ValidationError } from "@threefold/types";
import { plainToInstance } from "class-transformer";
import { validate } from "class-validator";
import * as crypto from "crypto";

async function validateObject(obj) {
const errors = await validate(obj);
Expand All @@ -23,4 +24,23 @@ function validateInput(target, propertyKey: string, descriptor: PropertyDescript
};
}

export { validateObject, validateInput };
function generateRandomHexSeed(length: number) {
const bytes = crypto.randomBytes(length);
return bytes.toString("hex");
}

function generateHexSeed(length: number, numbers: number[]) {
AlaaElattar marked this conversation as resolved.
Show resolved Hide resolved
const hexSeed = numbers[0].toString(16).padStart(length, "0") + numbers[1].toString(16).padStart(length, "0");

return hexSeed;
AlaaElattar marked this conversation as resolved.
Show resolved Hide resolved
}

function validateHexSeed(seed: string, length: number): boolean {
const hexSeedRegex = new RegExp(`^[0-9A-Fa-f]{${length * 2}}$`);
if (!hexSeedRegex.test(seed)) {
throw new ValidationError(`Invalid seed. It should be a ${length}-character hexadecimal string.`);
}
return true;
}

export { validateObject, validateInput, generateRandomHexSeed, validateHexSeed, generateHexSeed };
Loading
Loading