import { DiskModel, FilterOptions, MachineModel, MachinesModel, NetworkModel } from "../src"; import { config, getClient } from "./client_loader"; import { log } from "./utils"; async function main() { const grid3 = await getClient(); // create network Object const n = new NetworkModel(); n.name = "dynamictest"; n.ip_range = "10.249.0.0/16"; // create disk Object const disk = new DiskModel(); disk.name = "dynamicDisk"; disk.size = 1; disk.mountpoint = "/testdisk"; const vmQueryOptions: FilterOptions = { cru: 1, mru: 1, // GB sru: 1, availableFor: grid3.twinId, country: "Belgium", }; // create vm node Object const vm = new MachineModel(); vm.name = "testvm"; vm.node_id = +(await grid3.capacity.filterNodes(vmQueryOptions))[0].nodeId; // TODO: allow random choice vm.disks = [disk]; vm.public_ip = false; vm.planetary = true; vm.cpu = 1; vm.memory = 1024; vm.rootfs_size = 0; vm.flist = "https://hub.grid.tf/tf-official-apps/base:latest.flist"; vm.entrypoint = "/sbin/zinit init"; vm.env = { SSH_KEY: config.ssh_key, }; // create VMs Object const vms = new MachinesModel(); vms.name = "dynamicVMS"; vms.network = n; vms.machines = [vm]; vms.metadata = ""; vms.description = "test deploying VMs via ts grid3 client"; // deploy vms const res = await grid3.machines.deploy(vms); log(res); // get the deployment const l = await grid3.machines.getObj(vms.name); log(l); // // delete // const d = await grid3.machines.delete({ name: vms.name }); // log(d); await grid3.disconnect(); } main();