Skip to content
Merged
21 changes: 21 additions & 0 deletions .github/workflows/grid_client_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,30 @@ jobs:
run: |
yarn run ts-node --project packages/grid_client/tsconfig-node.json packages/grid_client/scripts/dynamic_single_vm.ts

- name: Run test Zos 3 lite gateway
id: zos3lite_gateway_domain
if: always()
run: |
yarn run ts-node --project packages/grid_client/tsconfig-node.json packages/grid_client/scripts/zos3lite_gateway_domain.ts

- name: Run test single ZOS3 lite vm with mycelium
id: zos3lite
if: always()
run: |
yarn run ts-node --project packages/grid_client/tsconfig-node.json packages/grid_client/scripts/single_vm_zos3_lite.ts

- name: Run test multiple vms
id: multiple_vm
if: always()
run: |
yarn run ts-node --project packages/grid_client/tsconfig-node.json packages/grid_client/scripts/multiple_vms.ts

- name: Run test multiple zos3 lite vms
id: multiple_zos3_lite_vm
if: always()
run: |
yarn run ts-node --project packages/grid_client/tsconfig-node.json packages/grid_client/scripts/multiple_vms_zos_3_lite.ts

- name: Run test kubernetes
id: k8s
if: always()
Expand Down Expand Up @@ -145,7 +163,10 @@ jobs:
> **Details on failed run**: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}

- **Dynamic Single Vm**: ${{ steps.single_vm.outcome }}
- **ZOS3 Lite Mycelium**: ${{ steps.zos3lite.outcome }}
- **Multiple Vm**: ${{ steps.multiple_vm.outcome }}
- **Multiple Vm zos3 lite**: ${{ steps.multiple_zos3_lite_vm.outcome }}
- **zos3 lite gateway**: ${{ steps.zos3lite_gateway_domain.outcome }}
- **Kubernetes**: ${{ steps.k8s.outcome }}
- **Vmq QSFS**: skipped https://github.com/threefoldtech/tfgrid-sdk-ts/issues/3611
- **Kubernetes QSFS**: skipped https://github.com/threefoldtech/tfgrid-sdk-ts/issues/3611
Expand Down
22 changes: 14 additions & 8 deletions packages/grid_client/scripts/multiple_vms.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FilterOptions, GridClient, MachinesModel } from "../src";
import { FilterOptions, generateString, GridClient, MachinesModel } from "../src";
import { config, getClient } from "./client_loader";
import { log, pingNodes } from "./utils";

Expand Down Expand Up @@ -30,7 +30,13 @@ async function getNodeId(client: GridClient, options: FilterOptions) {
}

async function main() {
const name = "monVMS2";
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 = {
Expand All @@ -46,16 +52,16 @@ async function main() {
const vms: MachinesModel = {
name,
network: {
name: "monNetwork",
name: networkName,
ip_range: "10.238.0.0/16",
},
machines: [
{
name: "testvm1",
name: machine1Name,
node_id: nodeId!,
disks: [
{
name: "newDisk1",
name: disk1Name,
size: 5,
mountpoint: "/newDisk1",
},
Expand All @@ -74,11 +80,11 @@ async function main() {
},
},
{
name: "testvm2",
name: machine2Name,
node_id: nodeId!,
disks: [
{
name: "newDisk2",
name: disk2Name,
size: 5,
mountpoint: "/newDisk2",
},
Expand Down Expand Up @@ -107,7 +113,7 @@ async function main() {
//Get the deployment
await getDeployment(grid3, name);

// //Uncomment the line below to cancel the deployment
// Uncomment the line below to cancel the deployment
// await cancel(grid3, name);

await grid3.disconnect();
Expand Down
132 changes: 132 additions & 0 deletions packages/grid_client/scripts/multiple_vms_zos_3_lite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import {
Features,
FilterOptions,
generateRandomHexSeed,
generateString,
GridClient,
MachinesDeleteModel,
MachinesModel,
} from "../src";
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 =================");
}

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,
features: [Features.zmachinelight, Features.networklight, Features.mycelium],
nodeExclude: [259],
farmName: "LiriaFarm",
};

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: false,
mycelium: true,
cpu: 1,
memory: 1024,
rootfs_size: 0,
flist: "https://hub.grid.tf/tf-official-apps/base:latest.flist",
entrypoint: "/sbin/zinit init",
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: false,
mycelium: true,
cpu: 1,
memory: 1024,
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 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();
14 changes: 9 additions & 5 deletions packages/grid_client/scripts/single_vm.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GridClient, MachinesModel } from "../src";
import { generateString, GridClient, MachinesModel } from "../src";
import { type ZmachineData } from "../src/helpers/types";
import { config, getClient } from "./client_loader";
import { log } from "./utils";
Expand Down Expand Up @@ -26,22 +26,26 @@ async function cancel(client: GridClient, name: string) {
}

async function main() {
const name = "newVMS";
const name = "vm" + generateString(6);
const networkName = "nw" + generateString(6);
const machineName = "machine" + generateString(6);
const diskName = "disk" + generateString(6);

const grid3 = await getClient(`vm/${name}`);

const vms: MachinesModel = {
name,
network: {
name: "wedtest",
name: networkName,
ip_range: "10.249.0.0/16",
},
machines: [
{
name: "testvm",
name: machineName,
node_id: 11,
disks: [
{
name: "wedDisk",
name: diskName,
size: 8,
mountpoint: "/testdisk",
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Features, FilterOptions, generateRandomHexSeed, GridClient, MachinesDeleteModel, MachinesModel } from "../src";
import {
Features,
FilterOptions,
generateRandomHexSeed,
generateString,
GridClient,
MachinesDeleteModel,
MachinesModel,
} from "../src";
import { config, getClient } from "./client_loader";
import { log, pingNodes } from "./utils";

Expand All @@ -24,7 +32,8 @@ async function cancel(client, vms) {
}

async function main() {
const name = "vm";
const name = "vm" + generateString(6);
const networkName = "nw" + generateString(6);
const grid3 = await getClient(`vm/${name}`);
const instanceCapacity = { cru: 2, mru: 4, sru: 100 }; // Update the instance capacity values according to your requirements.

Expand All @@ -36,14 +45,15 @@ async function main() {
availableFor: grid3.twinId,
features: [Features.zmachinelight, Features.networklight, Features.mycelium],
nodeExclude: [259],
farmName: "LiriaFarm",
};
const nodes = await grid3.capacity.filterNodes(vmQueryOptions);
const vmNode = await pingNodes(grid3, nodes);

const vms: MachinesModel = {
name,
network: {
name: "vmNode",
name: networkName,
ip_range: "10.249.0.0/16",
myceliumSeeds: [
{
Expand Down
57 changes: 57 additions & 0 deletions packages/grid_client/scripts/zos3lite_gateway_domain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Features, FilterOptions, GatewayNameModel, generateString } from "../src";
import { getClient } from "./client_loader";
import { log } from "./utils";

async function deploy(client, gw) {
const res = await client.gateway.deploy_name(gw);
log("================= Deploying name gateway =================");
log(res);
log("================= Deploying name gateway =================");
}

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

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

// read more about the gateway types in this doc: https://github.com/threefoldtech/zos/tree/main/docs/internals/gateway
async function main() {
const grid3 = await getClient();
const gatewayName = "gw" + generateString(6);

const gatewayQueryOptions: FilterOptions = {
gateway: true,
features: [Features.mycelium, Features.zmachinelight, Features.networklight],
farmName: "LiriaFarm",
};

const gw: GatewayNameModel = {
name: gatewayName,
node_id: +(await grid3.capacity.filterNodes(gatewayQueryOptions))[0].nodeId,
tls_passthrough: false,
// the backends have to be in this format `http://ip:port` or `https://ip:port`, and the `ip` pingable from the node so using the ygg ip or public ip if available.
backends: ["http://185.206.122.35:8000"],
};

//Deploy gateway
await deploy(grid3, gw);

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

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

grid3.disconnect();
}

main();
Loading