Skip to content

threefold.grid3.deployer #

deployer

To get started




import freeflowuniverse.herolib.clients. deployer

mut client:= deployer.get()!

client...

example heroscript

!!deployer.configure
    secret: '...'
    host: 'localhost'
    port: 8888

Constants #

const version = '1.0.0'

fn delete #

fn delete(args_ ArgsGet) !

fn delete_deployment #

fn delete_deployment(name string) !

fn exists #

fn exists(args_ ArgsGet) !bool

does the config exists?

fn filter_nodes #

fn filter_nodes(args FilterNodesArgs) ![]gridproxy_models.Node

fn get #

fn get(args_ ArgsGet) !&TFGridDeployer

fn get_deployment #

fn get_deployment(name string) !TFDeployment

fn get_mnemonics #

fn get_mnemonics() !string

fn heroscript_dumps #

fn heroscript_dumps(obj TFGridDeployer) !string

///////////NORMALLY NO NEED TO TOUCH

fn heroscript_loads #

fn heroscript_loads(heroscript string) !TFGridDeployer

fn new_deployer #

fn new_deployer(mnemonics string, chain_network ChainNetwork) !Deployer

fn new_deployment #

fn new_deployment(name string) !TFDeployment

fn play #

fn play(args_ PlayArgs) !

fn set #

fn set(o TFGridDeployer) !

register the config for the future

fn switch #

fn switch(name string)

switch instance to be used for deployer

enum ChainNetwork #

enum ChainNetwork {
	dev
	qa
	test
	main
}

enum Network #

enum Network {
	dev
	main
	test
	qa
}

THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED

struct ArgsGet #

@[params]
struct ArgsGet {
pub mut:
	name string
}

///////FACTORY

struct ContractGetArgs #

@[params]
struct ContractGetArgs {
pub mut:
	active  bool = true
	twin_id u64
}

struct DefaultConfigArgs #

@[params]
struct DefaultConfigArgs {
	instance string = 'default'
}

helpers

struct Deployer #

@[heap]
struct Deployer {
pub:
	mnemonics     string
	substrate_url string
	twin_id       u32
	relay_url     string
	chain_network ChainNetwork
	env           string
pub mut:
	client griddriver.Client
	logger log.Log
}

fn (Deployer) assign_wg_port #

fn (mut d Deployer) assign_wg_port(node_id u32) !u16

fn (Deployer) batch_deploy #

fn (mut d Deployer) batch_deploy(name_contracts []string, mut dls map[u32]&models.Deployment, solution_provider ?u64) !(map[string]u64, map[u32]&models.Deployment)

fn (Deployer) delete_deployment #

fn (mut d Deployer) delete_deployment(contract_id u64, node_id u32) !models.Deployment

fn (Deployer) deploy #

fn (mut d Deployer) deploy(node_id u32, mut dl models.Deployment, body string, solution_provider u64) !u64

fn (Deployer) deployment_changes #

fn (mut d Deployer) deployment_changes(node_id u32, contract_id u64) ![]models.Workload

fn (Deployer) get_deployment #

fn (mut d Deployer) get_deployment(contract_id u64, node_id u32) !models.Deployment

fn (Deployer) get_node_pub_config #

fn (mut d Deployer) get_node_pub_config(node_id u32) !models.PublicConfig

fn (Deployer) rmb_deployment_changes #

fn (mut d Deployer) rmb_deployment_changes(dst u32, contract_id u64) !string

Todo: decode/encode the params/result here

fn (Deployer) rmb_deployment_delete #

fn (mut d Deployer) rmb_deployment_delete(dst u32, data string) !string

fn (Deployer) rmb_deployment_deploy #

fn (mut d Deployer) rmb_deployment_deploy(dst u32, data string) !string

fn (Deployer) rmb_deployment_get #

fn (mut d Deployer) rmb_deployment_get(dst u32, data string) !string

fn (Deployer) rmb_deployment_update #

fn (mut d Deployer) rmb_deployment_update(dst u32, data string) !string

fn (Deployer) update_deployment #

fn (mut d Deployer) update_deployment(node_id u32, mut dl models.Deployment, body string) !

fn (Deployer) wait_deployment #

fn (mut d Deployer) wait_deployment(node_id u32, mut dl models.Deployment, workload_versions map[string]u32) !

struct FilterNodesArgs #

@[params]
struct FilterNodesArgs {
	gridproxy_models.NodeFilter
pub:
	on_hetzner bool
}

Todo: put all code in relation to filtering in file filter.v

struct KVStoreFS #

struct KVStoreFS {}

Will be changed when we support the logic of the TFChain one

struct Mycelium #

@[params]
struct Mycelium {
	hex_seed string = rand.hex(12)
}

struct NetworkRequirements #

@[params]
struct NetworkRequirements {
pub mut:
	name                  string = 'net' + rand.string(5)
	user_access_endpoints int
}

NetworkInfo struct to represent network details

struct NetworkSpecs #

@[params]
struct NetworkSpecs {
pub mut:
	requirements        NetworkRequirements
	ip_range            string = '10.10.0.0/16'
	mycelium            string = rand.hex(64)
	user_access_configs []UserAccessConfig
}

struct PlayArgs #

@[params]
struct PlayArgs {
pub mut:
	heroscript string // if filled in then plbook will be made out of it
	plbook     ?playbook.PlayBook
	reset      bool
}

struct TFDeployment #

@[heap]
struct TFDeployment {
pub mut:
	name        string
	description string
	vms         []VMachine
	zdbs        []ZDB
	webnames    []WebName
	network     NetworkSpecs
mut:
	// Set the deployed contracts on the deployment and save the full deployment to be able to delete the whole deployment when need.
	contracts GridContracts
	deployer  &Deployer @[skip; str: skip]
	kvstore   KVStoreFS @[skip; str: skip]
}

fn (TFDeployment) add_machine #

fn (mut self TFDeployment) add_machine(requirements VMRequirements)

Set a new machine on the deployment.

fn (TFDeployment) add_webname #

fn (mut self TFDeployment) add_webname(requirements WebNameRequirements)

Set a new webname on the deployment.

fn (TFDeployment) add_zdb #

fn (mut self TFDeployment) add_zdb(zdb ZDBRequirements)

Set a new zdb on the deployment.

fn (TFDeployment) configure_network #

fn (mut self TFDeployment) configure_network(req NetworkRequirements) !

fn (TFDeployment) deploy #

fn (mut self TFDeployment) deploy() !

fn (TFDeployment) get_user_access_configs #

fn (mut self TFDeployment) get_user_access_configs() []UserAccessConfig

fn (TFDeployment) list_deployments #

fn (mut self TFDeployment) list_deployments() !map[u32]grid_models.Deployment

lists deployments used with vms, zdbs, and webnames

fn (TFDeployment) load #

fn (mut self TFDeployment) load() !

fn (TFDeployment) remove_machine #

fn (mut self TFDeployment) remove_machine(name string) !

fn (TFDeployment) remove_webname #

fn (mut self TFDeployment) remove_webname(name string) !

fn (TFDeployment) remove_zdb #

fn (mut self TFDeployment) remove_zdb(name string) !

fn (TFDeployment) tfchain_contracts #

fn (mut self TFDeployment) tfchain_contracts(args ContractGetArgs) ![]proxy_models.Contract

Retrieves all contracts (active and inactive) on the selected grid network.

This function interacts with the Grid Proxy to retrieve all contracts associated with the twin ID of the current deployer (from GridClient).

Returns:- An array of gridproxy.Contract containing contract information.

Example

contracts := cn.get_my_contracts()!

fn (TFDeployment) vm_get #

fn (mut self TFDeployment) vm_get(vm_name string) !VMachine

fn (TFDeployment) webname_get #

fn (mut self TFDeployment) webname_get(wn_name string) !WebName

fn (TFDeployment) zdb_get #

fn (mut self TFDeployment) zdb_get(zdb_name string) !ZDB

struct TFGridDeployer #

@[heap]
struct TFGridDeployer {
pub mut:
	name     string = 'default'
	ssh_key  string
	mnemonic string
	network  Network
}

fn (TFGridDeployer) mycelium_address_create #

fn (mut deployer TFGridDeployer) mycelium_address_create() grid_models.Mycelium

Creates a new mycelium address with a randomly generated hex key

struct UserAccessConfig #

struct UserAccessConfig {
pub:
	ip         string
	secret_key string
	public_key string

	peer_public_key      string
	network_ip_range     string
	public_node_endpoint string
}

fn (UserAccessConfig) print_wg_config #

fn (c UserAccessConfig) print_wg_config() string

struct VMRequirements #

@[params]
struct VMRequirements {
pub mut:
	name        string
	description string
	cpu         int // vcores
	size        u64
	memory      int // gbyte
	public_ip4  bool
	public_ip6  bool
	planetary   bool
	mycelium    ?Mycelium
	flist       string = 'https://hub.grid.tf/tf-official-vms/ubuntu-24.04-latest.flist'
	entrypoint  string = '/sbin/zinit init'
	env         map[string]string
	// if set will chose a node from the list to deploy on
	nodes []u32
	// will deploy on one of hetzner nodes
	use_hetzner_node bool
}

MachineNetworkReq struct to represent network access configuration

struct VMachine #

struct VMachine {
pub mut:
	tfchain_id   string
	contract_id  u64
	requirements VMRequirements
	node_id      u32
	planetary_ip string
	mycelium_ip  string
	public_ip4   string
	wireguard_ip string
	public_ip6   string
}

MachineModel struct to represent a machine and its associat ed details

fn (VMachine) healthcheck #

fn (self VMachine) healthcheck() !bool

struct WebName #

struct WebName {
pub mut:
	fqdn             string
	name_contract_id u64
	node_contract_id u64
	requirements     WebNameRequirements
	node_id          u32
}

struct WebNameRequirements #

@[params]
struct WebNameRequirements {
pub mut:
	name                  string @[required]
	node_id               ?u32
	use_wireguard_network bool
	use_hetzner_node      bool
	// must be in the format ip:port if tls_passthrough is set, otherwise the format should be http://ip[:port]
	backend         string @[required]
	tls_passthrough bool
}

struct ZDB #

struct ZDB {
pub mut:
	ips          []string
	port         u32
	namespace    string
	contract_id  u64
	requirements ZDBRequirements
	node_id      u32
}

struct ZDBRequirements #

@[params]
struct ZDBRequirements {
pub mut:
	name             string @[required]
	password         string @[required]
	size             int    @[required]
	node_id          ?u32
	description      string
	mode             grid_models.ZdbMode = 'user'
	public           bool
	use_hetzner_node bool
}