-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' of github.com:threefoldtech/tfgrid-sdk-ts …
…into development_get_nodeid_for_rentContract
- Loading branch information
Showing
102 changed files
with
2,281 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# Deployment Flow | ||
|
||
This document outlines the process for determining whether to deploy on a zos3 or a zos4 node. | ||
|
||
## Machine Model Initialization | ||
|
||
The deployment process begins with initializing the machine model as follows: | ||
|
||
```ts | ||
const vms: MachinesModel = { | ||
name: "newMY", | ||
network: { | ||
name: "hellotest", | ||
ip_range: "10.249.0.0/16", | ||
myceliumSeeds: [ | ||
{ | ||
nodeId: 168, | ||
seed: "050d109829d8492d48bfb33b711056080571c69e46bfde6b4294c4c5bf468a76", //(HexSeed of length 32) | ||
}, | ||
], | ||
}, | ||
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", //(HexSeed of length 6) | ||
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", | ||
}; | ||
``` | ||
|
||
## Deployment Execution | ||
|
||
- The next step is invoking the `deploy` function: | ||
- Takes the `MachinesModel` object as a parameter | ||
- Checks if a machine with the same name already exists and if so throws an error | ||
- If not, then it calls the `_createDeployment` function along some othe functions | ||
- Finally, the function returns the created contracts. If the deployment is on a zos3 node, then the wireguard configuration is returned as well. | ||
|
||
```ts | ||
await client.machines.deploy(vms); | ||
``` | ||
|
||
- The `_createDeployment` function: | ||
- Takes the `MachinesModel` object as a parameter | ||
- Retrieves the features of the node using: `await this.rmb.request([nodeTwinId], "zos.system.node_features_get", "", 20, 3);` | ||
- Examines the retrieved features to determine the network's primitive type (`Network` or `ZNetworkLight`) and initializes it accordingly. | ||
- Sets the contractMetadata based on the network type. | ||
- Invokes the `create` function | ||
|
||
```ts | ||
await this._createDeployment(options); | ||
``` | ||
|
||
- The `create` function | ||
- Validates or assigns IP addresses based on the network type. | ||
- Determines network type (`network` or `network-light`) based on node features. | ||
- Adds access points and updates network configurations as necessary. | ||
- Initialize the VM primitive (`VMPrimitive` or `VMLightPrimitive`) based on the network type | ||
- Configures the VM with networking, storage, and environment variables. | ||
- Generates a Mycelium seed if not provided. | ||
- Generate the deployments | ||
- Finally, the function returns the created contracts. If the deployment is on a zos3 node, then the wireguard configuration is returned as well. | ||
|
||
```ts | ||
await this.vm.create( | ||
machine.name, | ||
machine.node_id, | ||
machine.flist, | ||
machine.cpu, | ||
machine.memory, | ||
machine.rootfs_size, | ||
machine.disks!, | ||
machine.public_ip, | ||
machine.public_ip6!, | ||
machine.planetary, | ||
machine.mycelium, | ||
machine.myceliumSeed!, | ||
network, | ||
options.network.myceliumSeeds!, | ||
machine.entrypoint, | ||
machine.env, | ||
contractMetadata, | ||
options.metadata, | ||
options.description, | ||
machine.qsfs_disks, | ||
this.config.projectName, | ||
options.network.addAccess, | ||
options.network.accessNodeId, | ||
machine.ip, | ||
machine.corex, | ||
machine.solutionProviderId!, | ||
machine.zlogsOutput, | ||
machine.gpus, | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { FilterOptions, GatewayNameModel, MachinesModel } from "../../src"; | ||
import { config, getClient } from "../client_loader"; | ||
import { log, pingNodes } from "../utils"; | ||
|
||
async function deploy(client, vms, subdomain, gatewayNode) { | ||
const resultVM = await client.machines.deploy(vms); | ||
log("================= Deploying VM ================="); | ||
log(resultVM); | ||
log("================= Deploying VM ================="); | ||
|
||
const vmPlanetary = (await client.machines.getObj(vms.name))[0].planetary; | ||
|
||
// Name Gateway Model | ||
const gw: GatewayNameModel = { | ||
name: subdomain, | ||
node_id: gatewayNode.nodeId, | ||
tls_passthrough: false, | ||
backends: [`http://[${vmPlanetary}]:3000`], | ||
}; | ||
|
||
const resultGateway = await client.gateway.deploy_name(gw); | ||
log("================= Deploying name gateway ================="); | ||
log(resultGateway); | ||
log("================= Deploying name gateway ================="); | ||
} | ||
|
||
async function getDeployment(client, vms, gw) { | ||
const resultVM = await client.machines.getObj(vms.name); | ||
const resultGateway = await client.gateway.getObj(gw); | ||
log("================= Getting deployment information ================="); | ||
log(resultVM); | ||
log(resultGateway); | ||
log("https://" + resultGateway[0].domain); | ||
log("================= Getting deployment information ================="); | ||
} | ||
|
||
async function cancel(client, vms, gw) { | ||
const resultVM = await client.machines.delete(vms); | ||
const resultGateway = await client.gateway.delete_name(gw); | ||
log("================= Canceling the deployment ================="); | ||
log(resultVM); | ||
log(resultGateway); | ||
log("================= Canceling the deployment ================="); | ||
} | ||
|
||
async function main() { | ||
const name = "giteainstance"; | ||
const networkName = "giteanetwork"; | ||
const grid3 = await getClient(`gitea/${name}`); | ||
const subdomain = "gt" + grid3.twinId + name; | ||
const instanceCapacity = { cru: 2, mru: 4, sru: 50 }; | ||
|
||
// VM Node Selection | ||
const vmQueryOptions: FilterOptions = { | ||
cru: instanceCapacity.cru, | ||
mru: instanceCapacity.mru, | ||
sru: instanceCapacity.sru, | ||
availableFor: grid3.twinId, | ||
farmId: 1, | ||
}; | ||
|
||
// Gateway Node Selection | ||
const gatewayQueryOptions: FilterOptions = { | ||
gateway: true, | ||
availableFor: grid3.twinId, | ||
}; | ||
const gatewayNode = (await grid3.capacity.filterNodes(gatewayQueryOptions))[0]; | ||
const nodes = await grid3.capacity.filterNodes(vmQueryOptions); | ||
const vmNode = await pingNodes(grid3, nodes); | ||
const domain = subdomain + "." + gatewayNode.publicConfig.domain; | ||
|
||
const vms: MachinesModel = { | ||
name, | ||
network: { | ||
name: networkName, | ||
ip_range: "10.249.0.0/16", | ||
}, | ||
machines: [ | ||
{ | ||
name: "giteavm", | ||
node_id: vmNode, | ||
disks: [ | ||
{ | ||
name: "giteadisk", | ||
size: instanceCapacity.sru, | ||
mountpoint: "/mnt/data", | ||
}, | ||
], | ||
planetary: true, | ||
public_ip: false, | ||
public_ip6: false, | ||
mycelium: true, | ||
cpu: instanceCapacity.cru, | ||
memory: 1024 * instanceCapacity.mru, | ||
rootfs_size: 0, | ||
flist: "https://hub.grid.tf/petep.3bot/threefolddev-gitea-latest.flist", | ||
entrypoint: "/sbin/zinit init", | ||
env: { | ||
SSH_KEY: config.ssh_key, | ||
GITEA__HOSTNAME: domain, | ||
//Uncomment incase of using smtp server | ||
// GITEA__mailer__PROTOCOL: "smtp", | ||
// GITEA__mailer__ENABLED: "true", | ||
// GITEA__mailer__HOST: "smtp.example.com", | ||
// GITEA__mailer__FROM: "[email protected]", | ||
// GITEA__mailer__PORT: "587", | ||
// GITEA__mailer__USER: "admin", | ||
// GITEA__mailer__PASSWD: "password123", | ||
}, | ||
}, | ||
], | ||
metadata: "", | ||
description: "Deploying Gitea via TS Grid3 client", | ||
}; | ||
|
||
// Deploy VMs | ||
await deploy(grid3, vms, subdomain, gatewayNode); | ||
|
||
// Get the deployment | ||
await getDeployment(grid3, vms, subdomain); | ||
|
||
// Uncomment the line below to cancel the deployment | ||
// await cancel(grid3, { name }, { name: subdomain }); | ||
|
||
await grid3.disconnect(); | ||
} | ||
|
||
main(); |
Oops, something went wrong.