Skip to content

weynandkuijpers/grid3_client_ts

 
 

Repository files navigation

grid3_client_ts

npm version Build tests code coverage

Github repo: grid3_client_ts

grid3_client is a client used for deploying workloads (VMs, ZDBs, k8s, etc.) on grid3.

Prerequisites

  • node 16.13.1 or higher
  • npm 8.2.0 or higher
  • may need to install libtool apt-get install libtool

Installation

⚠️ For Qanet: Please use @1.4.2 version

⚠️ For Testnet: Please use @1.4.2 version

⚠️ For Mainnet: Please use @v1.4.2 version

External package

npm install grid3_client

or

yarn add grid3_client

Local usage

  • Clone the repository
git clone https://github.com/threefoldtech/grid3_client_ts.git
  • Install it
npm install

or

yarn install

Getting started

Client configuration

  • Network environment: should select dev environment, qa, test or main.

  • Mnemonic: 12 words for your account. create one

  • Store secret: it's any word that will be used for encrypting/decrypting the keys on threefold key-value store.

  • project name: it's a name to isolate the deployments into a namespace.

    Note: only network can't be isolated, all project can see the same network.

Create client instance

  • Here's a simple example of creating a client instance with the default configurations.

  • or you can check more advanced configuration here.

    async function getClient(): Promise<GridClient> {
        const gridClient = new GridClient(
            "dev",  // dev, qa, test, or main
            "mnemonics",
            "secret",
            rmb,
            "projectName",
            BackendStorageType.auto,
            KeypairType.sr25519,
            config.backendStorage,
            config.seed,
        );
    
        await gridClient.connect();
    }
  • If you don't want to set your configurations directly in the client instance you can either do it through environment variables or JSON config file as seen here.

    Important Note: grid client should be disconnected after finishing its usage.

    gridClient.disconnect();

Using the client

This section assumes that you are using the client configuration from client_loader.ts

  • After creating a client instance you can call it in any of your scripts using getClient().

    const grid3 = getClient();
  • And then you can use this client instance with any of the client modules.

  • For example to deploy a VM you will need to use the machines module with the client and it can be used as follows. you can find the full example script here.

    • To deploy a VM
      await grid3.machines.deploy(vms);
    • To delete a VM
      await grid3.machines.delete({ name: vms.name });
  • More example scripts can be found here

Running the scripts

  • Before Running the scripts make sure you have a tsconfig.json file. here is an example file.

    {
        "compilerOptions": {
            "noImplicitAny": false,
            "module": "commonjs",
            "target": "esnext",
            "lib": [
                "ESNext",
                "DOM"
            ],
            "types": [
                "node",
                "jest"
            ],
            "declaration": true,
            "declarationMap": true,
            "outDir": "./dist/node",
            "esModuleInterop": true,
            "emitDecoratorMetadata": true,
            "experimentalDecorators": true,
            "allowJs": true,
            "baseUrl": "."
        },
        "include": [
            "src/**/*"
        ]
    }
  • After following the previous examples to create a client instance and using it in a script, you can then execute this script using ts-node.

    npx ts-node --project tsconfig-node.json filename.ts

    or

    yarn run ts-node --project tsconfig-node.json filename.ts

Usage examples

see scripts

see rmb_server

see http_server

API Docs

https://threefoldtech.github.io/grid3_client_ts/api/

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 98.1%
  • JavaScript 1.9%