cleanup client for grid

This commit is contained in:
2025-02-28 07:50:13 -07:00
parent 834f612bfe
commit 6bbaa0d1f7
117 changed files with 34 additions and 1816 deletions

View File

@@ -1,6 +1,6 @@
!!hero_code.generate_client
name:'tfgrid3deployer'
name:'deployer'
classname:'TFGridDeployer'
singleton:0
default:1

View File

@@ -1,4 +1,4 @@
module tfgrid3deployer
module deployer
import freeflowuniverse.herolib.threefold.gridproxy
import freeflowuniverse.herolib.threefold.gridproxy.model as proxy_models

View File

@@ -1,4 +1,4 @@
module tfgrid3deployer
module deployer
import freeflowuniverse.herolib.threefold.grid.models as grid_models
import freeflowuniverse.herolib.threefold.grid

View File

@@ -1,5 +1,5 @@
// This file should only contains any functions, helpers that related to the deployment setup.
module tfgrid3deployer
module deployer
import freeflowuniverse.herolib.threefold.grid.models as grid_models
import freeflowuniverse.herolib.threefold.grid

View File

@@ -1,4 +1,4 @@
module tfgrid3deployer
module deployer
import freeflowuniverse.herolib.threefold.gridproxy
import freeflowuniverse.herolib.threefold.gridproxy.model as gridproxy_models

View File

@@ -1,4 +1,4 @@
module tfgrid3deployer
module deployer
import freeflowuniverse.herolib.core.base as context

View File

@@ -1,4 +1,4 @@
module tfgrid3deployer
module deployer
import freeflowuniverse.herolib.threefold.grid.models as grid_models
import freeflowuniverse.herolib.threefold.grid

View File

@@ -1,4 +1,4 @@
# tfgrid3deployer
# deployer
To get started
@@ -6,9 +6,9 @@ To get started
import freeflowuniverse.herolib.clients. tfgrid3deployer
import freeflowuniverse.herolib.clients. deployer
mut client:= tfgrid3deployer.get()!
mut client:= deployer.get()!
client...
@@ -20,7 +20,7 @@ client...
## example heroscript
```hero
!!tfgrid3deployer.configure
!!deployer.configure
secret: '...'
host: 'localhost'
port: 8888

View File

@@ -1,4 +1,4 @@
module tfgrid3deployer
module deployer
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook
@@ -39,7 +39,7 @@ pub fn get(args_ ArgsGet) !&TFGridDeployer {
if !exists(args)! {
set(obj)!
} else {
heroscript := context.hero_config_get('tfgrid3deployer', args.name)!
heroscript := context.hero_config_get('deployer', args.name)!
mut obj_ := heroscript_loads(heroscript)!
set_in_mem(obj_)!
}
@@ -47,7 +47,7 @@ pub fn get(args_ ArgsGet) !&TFGridDeployer {
return tfgrid3deployer_global[args.name] or {
println(tfgrid3deployer_global)
// bug if we get here because should be in globals
panic('could not get config for tfgrid3deployer with name, is bug:${args.name}')
panic('could not get config for deployer with name, is bug:${args.name}')
}
}
@@ -56,20 +56,20 @@ pub fn set(o TFGridDeployer) ! {
set_in_mem(o)!
mut context := base.context()!
heroscript := heroscript_dumps(o)!
context.hero_config_set('tfgrid3deployer', o.name, heroscript)!
context.hero_config_set('deployer', o.name, heroscript)!
}
// does the config exists?
pub fn exists(args_ ArgsGet) !bool {
mut context := base.context()!
mut args := args_get(args_)
return context.hero_config_exists('tfgrid3deployer', args.name)
return context.hero_config_exists('deployer', args.name)
}
pub fn delete(args_ ArgsGet) ! {
mut args := args_get(args_)
mut context := base.context()!
context.hero_config_delete('tfgrid3deployer', args.name)!
context.hero_config_delete('deployer', args.name)!
if args.name in tfgrid3deployer_global {
// del tfgrid3deployer_global[args.name]
}
@@ -95,7 +95,7 @@ pub fn play(args_ PlayArgs) ! {
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
mut install_actions := plbook.find(filter: 'tfgrid3deployer.configure')!
mut install_actions := plbook.find(filter: 'deployer.configure')!
if install_actions.len > 0 {
for install_action in install_actions {
heroscript := install_action.heroscript()
@@ -105,7 +105,7 @@ pub fn play(args_ PlayArgs) ! {
}
}
// switch instance to be used for tfgrid3deployer
// switch instance to be used for deployer
pub fn switch(name string) {
tfgrid3deployer_default = name
}

View File

@@ -1,4 +1,4 @@
module tfgrid3deployer
module deployer
import freeflowuniverse.herolib.data.paramsparser
import freeflowuniverse.herolib.data.encoderhero

View File

@@ -1,4 +1,4 @@
module tfgrid3deployer
module deployer
import freeflowuniverse.herolib.threefold.gridproxy
import freeflowuniverse.herolib.threefold.grid

View File

@@ -1,4 +1,4 @@
module tfgrid3deployer
module deployer
import freeflowuniverse.herolib.ui.console
import json

View File

@@ -1,4 +1,4 @@
module tfgrid3deployer
module deployer
import json

View File

@@ -1,4 +1,4 @@
module tfgrid3deployer
module deployer
import freeflowuniverse.herolib.threefold.grid.models as grid_models
// import freeflowuniverse.herolib.ui.console

View File

@@ -3,3 +3,5 @@
Create workloads in native low level format, and then use a gridriver go binary to post it to TFChain as well as send it to ZOS.
//TODO: not sure how to use this one

View File

@@ -1,4 +1,4 @@
module grid
module deployer2
import os
import json

View File

@@ -1,4 +1,4 @@
module grid
module deployer2
import freeflowuniverse.herolib.core.redisclient

View File

@@ -1,4 +1,4 @@
module grid
module deployer2
import freeflowuniverse.herolib.core.base
import freeflowuniverse.herolib.core.playbook

View File

@@ -1,4 +1,4 @@
module grid
module deployer2
import net.http
import json

View File

@@ -1,4 +1,4 @@
module grid
module deployer2
import json
import freeflowuniverse.herolib.threefold.grid.models

View File

@@ -1,4 +1,4 @@
module grid
module deployer2
import json
import log

View File

@@ -1,4 +1,4 @@
module grid
module deployer2
import freeflowuniverse.herolib.installers.threefold.griddriver
import os

View File

@@ -1,4 +1,4 @@
module grid
module deployer2
import freeflowuniverse.herolib.core.redisclient

View File

@@ -1,6 +0,0 @@
module main
import freeflowuniverse.herolib.threefold.deploy
fn main() {
}

View File

@@ -1,108 +0,0 @@
module nodepilot
import freeflowuniverse.herolib.builder
struct NodePilot {
noderoot string
repository string
mut:
node builder.Node
}
pub fn nodepilot_new(name string, ipaddr string) ?NodePilot {
node := builder.node_new(name: name, ipaddr: ipaddr)?
return NodePilot{
node: node
noderoot: '/root/node-pilot-light'
repository: 'https://github.com/threefoldtech/node-pilot-light'
}
}
pub fn (mut n NodePilot) prepare() ? {
// not how its supposed to be used, todo is the right way
prepared := n.node.cache.get('nodepilot-prepare') or { '' }
if prepared != '' {
return
}
if !n.node.cmd_exists('git') {
n.node.package_install(name: 'git')?
}
if !n.node.cmd_exists('docker') {
n.node.package_install(name: 'ca-certificates curl gnupg lsb-release')?
n.node.executor.exec('curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --batch --yes --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg')?
arch := n.node.executor.exec('dpkg --print-architecture')?.trim_space()
release := n.node.executor.exec('lsb_release -cs')?.trim_space()
n.node.executor.exec('echo "deb [arch=${arch} signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu ${release} stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null')?
n.node.package_refresh()?
n.node.package_install(name: 'docker-ce docker-ce-cli containerd.io')?
n.node.executor.exec('service docker start')?
}
n.node.executor.exec('docker ps -a')?
if !n.node.executor.dir_exists(n.noderoot) {
// FIXME: repository is private
n.node.executor.exec('git clone ${n.repository} ${n.noderoot}')?
}
n.node.cache.set('nodepilot-prepare', 'ready', 600)?
}
fn (mut n NodePilot) is_running(s string) bool {
test := n.node.executor.exec('docker ps | grep ${s}') or { return false }
return true
}
pub fn (mut n NodePilot) fuse_running() bool {
return n.is_running('fuse-000')
}
pub fn (mut n NodePilot) fuse() ? {
rootdir := '/mnt/bc-fuse'
n.node.executor.exec('root=${rootdir} bash -x ${n.noderoot}/fuse/fuse.sh')?
}
pub fn (mut n NodePilot) harmony_running() bool {
return n.is_running('harmony')
}
pub fn (mut n NodePilot) harmony() ? {
rootdir := '/mnt/bc-harmony'
n.node.executor.exec('root=${rootdir} bash -x ${n.noderoot}/harmony/harmony.sh')?
}
pub fn (mut n NodePilot) pokt_running() bool {
return n.is_running('pokt-000')
}
pub fn (mut n NodePilot) pokt() ? {
test := n.node.executor.exec('docker ps | grep pokt-000') or { '' }
if test != '' {
return error('Pokt instance already running')
}
rootdir := '/mnt/bc-pokt'
n.node.executor.exec('root=${rootdir} bash -x ${n.noderoot}/pokt/pokt.sh')?
}
fn (mut n NodePilot) overlayfs(ropath string, rwpath string, tmp string, target string) ? {
n.node.executor.exec('mount -t overlay overlay -o lowerdir=${ropath},upperdir=${rwpath},workdir=${tmp} ${target}')?
}
// make it easy by using the same password everywhere and the same host
// only namespace names needs to be different
fn (mut n NodePilot) zdbfs(host string, meta string, data string, temp string, password string, mountpoint string) ? {
mut zdbcmd := 'zdbfs ${mountpoint} -o ro '
zdbcmd += '-o mh=${host} -o mn=${meta} -o ms=${password} '
zdbcmd += '-o dh=${host} -o dn=${data} -o ds=${password} '
zdbcmd += '-o th=${host} -o tn=${temp} -o ts=${password}'
n.node.executor.exec(zdbcmd)?
}
// TODO: pokt chains

View File

@@ -1,6 +0,0 @@
# Pokt.Network installer
A set of tools to install your own pokt.network node in an easy way.
> TODO: not sure if finished

View File

@@ -1,22 +0,0 @@
# heroscript actions handlers
takes input in heroscript language and can then call v clients to talk to e.g. web3gw, web3gw is proxy in golang to tfgrid functionality.
## Usage
- For documentation on how to use heroscript, refer to this document [here](../../manual/src/threelang/parser.md)
> todo: update doc
## Development
- To add new books to the parser, follow these instructions:
- Create a new module inside the threelang folder
- Inside the new module, create a new handler for this book.
- While creating a new Runner, the new handler should be initialized, then saved to the Runner's state.
- The new handler should have its actions exposed in the Runner.run() method
- The new handler must implement a handle_action method.
- The handle_action method receives an playbook.Action, and executes the action however it sees fit.
- Handlers are responsible for logging their output, if any.
- To add documentation on how to use the new book, create a new folder [here](../../manual/src/threelang/) with the book's name, and add all needed documentation files in this folder.

View File

@@ -1,15 +0,0 @@
module blockchain
import freeflowuniverse.herolib.core.playbook { Actions }
import freeflowuniverse.herolib.core.texttools
import freeflowuniverse.herolib.data.paramsparser
// TODO: not implemented,
fn (mut c Controller) actions(actions_ Actions) ! {
mut actions2 := actions_.filtersort(actor: '???')!
for action in actions2 {
if action.name == '???' {
}
}
}

View File

@@ -1,11 +0,0 @@
module blockchain
// import freeflowuniverse.herolib.core.playbook
pub struct Controller {
}
pub fn new() !Controller {
mut c := Controller{}
return c
}

View File

@@ -1,16 +0,0 @@
module clients
import freeflowuniverse.herolib.threefold.web3gw.tfgrid { TFGridClient }
import freeflowuniverse.herolib.threefold.web3gw.tfchain { TfChainClient }
import freeflowuniverse.herolib.threefold.web3gw.stellar { StellarClient }
import freeflowuniverse.herolib.threefold.web3gw.eth { EthClient }
import freeflowuniverse.herolib.threefold.web3gw.btc { BtcClient }
pub struct Clients {
pub mut:
tfg_client TFGridClient
tfc_client TfChainClient
str_client StellarClient
eth_client EthClient
btc_client BtcClient
}

View File

@@ -1,94 +0,0 @@
module tfgrid_actions
import log
import freeflowuniverse.herolib.core.playbook
import freeflowuniverse.herolib.data.rpcwebsocket { RpcWsClient }
import freeflowuniverse.herolib.threefold.web3gw.tfgrid as tfgrid_client
import freeflowuniverse.herolib.threefold.web3gw.tfchain as tfchain_client
import freeflowuniverse.herolib.threefold.web3gw.stellar as stellar_client
import freeflowuniverse.herolib.threefold.web3gw.eth as eth_client
import freeflowuniverse.herolib.threefold.web3gw.btc as btc_client
import freeflowuniverse.herolib.threefold.tfgrid_actions.tfgrid { TFGridHandler }
import freeflowuniverse.herolib.threefold.tfgrid_actions.web3gw { Web3GWHandler }
import freeflowuniverse.herolib.threefold.tfgrid_actions.clients { Clients }
import freeflowuniverse.herolib.threefold.tfgrid_actions.stellar { StellarHandler }
const tfgrid_book = 'tfgrid'
const web3gw_book = 'web3gw'
const stellar_book = 'stellar'
pub struct Runner {
pub mut:
path string
clients Clients
tfgrid_handler TFGridHandler
web3gw_handler Web3GWHandler
stellar_handler StellarHandler
}
@[params]
pub struct RunnerArgs {
pub mut:
name string
path string
address string
}
pub fn new(args RunnerArgs, debug_log bool) !Runner {
mut ap := playbook.new(path: args.path)!
mut logger := log.Logger(&log.Log{
level: if debug_log { .debug } else { .info }
})
mut rpc_client := rpcwebsocket.new_rpcwsclient(args.address, &logger) or {
return error('Failed creating rpc websocket client: ${err}')
}
_ := spawn rpc_client.run()
mut gw_clients := get_clients(mut rpc_client)!
tfgrid_handler := tfgrid.new(mut rpc_client, logger, mut gw_clients.tfg_client)
web3gw_handler := web3gw.new(mut rpc_client, &logger, mut gw_clients)
stellar_handler := stellar.new(mut rpc_client, &logger, mut gw_clients.str_client)
mut runner := Runner{
path: args.path
tfgrid_handler: tfgrid_handler
web3gw_handler: web3gw_handler
clients: gw_clients
stellar_handler: stellar_handler
}
runner.run(mut ap)!
return runner
}
pub fn (mut r Runner) run(mut acs playbook.Actions) ! {
for action in acs.actions {
match action.book {
threelang.tfgrid_book {
r.tfgrid_handler.handle_action(action)!
}
threelang.web3gw_book {
r.web3gw_handler.handle_action(action)!
}
threelang.stellar_book {
r.stellar_handler.handle_action(action)!
}
else {
return error('module ${action.book} is invalid')
}
}
}
}
pub fn get_clients(mut rpc_client RpcWsClient) !Clients {
return Clients{
tfg_client: tfgrid_client.new(mut rpc_client)
tfc_client: tfchain_client.new(mut rpc_client)
btc_client: btc_client.new(mut rpc_client)
eth_client: eth_client.new(mut rpc_client)
str_client: stellar_client.new(mut rpc_client)
}
}

View File

@@ -1,59 +0,0 @@
module nostr
import freeflowuniverse.herolib.core.playbook { Action }
fn (mut n NostrHandler) channel(action Action) ! {
match action.name {
'create' {
// create a new channel
name := action.params.get('name')!
about := action.params.get_default('description', '')!
pic_url := action.params.get_default('picture', '')!
channel_id := n.client.create_channel(name: name, about: about, picture: pic_url)!
n.logger.info('Channel ID ${channel_id}')
}
'send' {
// send message to channel
channel_id := action.params.get('channel')!
content := action.params.get('content')!
message_id := action.params.get_default('reply_to', '')!
public_key := action.params.get_default('public_key_author', '')!
n.client.create_channel_message(
channel_id: channel_id
content: content
message_id: message_id
public_key: public_key
)!
}
'read_sub' {
// read subscription messages
channel_id := action.params.get('channel')!
mut id := action.params.get_default('id', '')!
if id == '' {
id = n.client.subscribe_channel_message(id: channel_id)!
n.logger.info('Subscription ID: ${id}')
}
count := action.params.get_u32_default('count', 10)!
messages := n.client.get_subscription_events(id: id, count: count)!
n.logger.info('Channel Messages: ${messages}')
}
'read' {
// read all channel messages
channel_id := action.params.get('channel')!
messages := n.client.get_channel_message(channel_id: channel_id)!
n.logger.info('Channel Messages: ${messages}')
}
'list' {
// list all channels on relay
channels := n.client.list_channels()!
n.logger.info('Channels: ${channels}')
}
else {
return error('operation ${action.name} is not supported on nostr groups')
}
}
}

View File

@@ -1,34 +0,0 @@
module nostr
import freeflowuniverse.herolib.core.playbook { Action }
fn (mut n NostrHandler) direct(action Action) ! {
match action.name {
'send' {
// send direct message
receiver := action.params.get('receiver')!
content := action.params.get('content')!
n.client.publish_direct_message(
receiver: receiver
content: content
)!
}
'read' {
// reads and subscribes to direct messages
mut id := action.params.get_default('subscription_id', '')!
if id == '' {
id = n.client.subscribe_to_direct_messages()!
n.logger.info('subscription id: ${id}')
}
count := action.params.get_u32_default('count', 10)!
events := n.client.get_subscription_events(id: id, count: count)!
n.logger.info('Direct Message Events: ${events}')
}
else {
return error('operation ${action.name} is not supported on nostr direct messages')
}
}
}

View File

@@ -1,35 +0,0 @@
module nostr
import threefoldtech.threebot.nostr as nostr_client { NostrClient }
import freeflowuniverse.herolib.core.playbook { Action }
import freeflowuniverse.herolib.data.rpcwebsocket { RpcWsClient }
import log { Logger }
pub struct NostrHandler {
pub mut:
client NostrClient
logger Logger
}
pub fn new(mut rpc_client RpcWsClient, logger Logger) NostrHandler {
mut cl := nostr_client.new(mut rpc_client)
return NostrHandler{
client: cl
logger: logger
}
}
pub fn (mut n NostrHandler) handle_action(action Action) ! {
match action.actor {
'channel' {
n.channel(action)!
}
'direct' {
n.direct(action)!
}
else {
return error('actor ${action.actor} is not supported')
}
}
}

View File

@@ -1,47 +0,0 @@
module stellar
import freeflowuniverse.herolib.core.playbook { Action }
fn (mut h StellarHandler) account(action Action) ! {
match action.name {
'address' {
res := h.client.address()!
h.logger.info(res)
}
'create' {
network := action.params.get_default('network', 'public')!
res := h.client.create_account(network)!
h.logger.info(res)
}
'transactions' {
account := action.params.get_default('account', '')!
limit := action.params.get_u32_default('limit', 10)!
include_failed := action.params.get_default_false('include_failed')
cursor := action.params.get_default('cursor', '')!
ascending := action.params.get_default_false('ascending')
res := h.client.transactions(
account: account
limit: limit
include_failed: include_failed
cursor: cursor
ascending: ascending
)!
h.logger.info('Transactions: ${res}')
}
'data' {
account := action.params.get('account')!
res := h.client.account_data(account)!
h.logger.info('${res}')
}
else {
return error('account action ${action.name} is invalid')
}
}
}

View File

@@ -1,30 +0,0 @@
module stellar
import freeflowuniverse.herolib.threefold.web3gw.stellar as stellar_client { StellarClient }
import freeflowuniverse.herolib.core.playbook { Action }
import freeflowuniverse.herolib.data.rpcwebsocket { RpcWsClient }
import log { Logger }
pub struct StellarHandler {
pub mut:
client StellarClient
logger Logger
}
pub fn new(mut rpc_client RpcWsClient, logger Logger, mut client StellarClient) StellarHandler {
return StellarHandler{
client: client
logger: logger
}
}
pub fn (mut h StellarHandler) handle_action(action Action) ! {
match action.actor {
'account' {
h.account(action)!
}
else {
return error('action actor ${action.actor} is invalid')
}
}
}

View File

@@ -1,64 +0,0 @@
module tfgrid
import freeflowuniverse.herolib.core.playbook { Action }
import freeflowuniverse.herolib.threefold.web3gw.tfgrid as tfgrid_client { ContractFilter, FindContracts, Limit }
pub fn (mut h TFGridHandler) contracts(action Action) ! {
match action.name {
'get' {
mnemonics := action.params.get_default('mnemonics', '')!
network := action.params.get_default('network', 'main')!
h.tfgrid.load(
mnemonic: mnemonics
network: network
)!
mut filter := ContractFilter{}
if action.params.exists('contract_id') {
filter.contract_id = action.params.get_u64('contract_id')!
}
if action.params.exists('twin_id') {
filter.twin_id = action.params.get_u64('twin_id')!
}
if action.params.exists('node_id') {
filter.node_id = action.params.get_u64('node_id')!
}
if action.params.exists('type') {
filter.type_ = action.params.get('type')!
}
if action.params.exists('state') {
filter.state = action.params.get('state')!
}
if action.params.exists('name') {
filter.name = action.params.get('name')!
}
if action.params.exists('number_of_public_ips') {
filter.number_of_public_ips = action.params.get_u64('number_of_public_ips')!
}
if action.params.exists('deployment_data') {
filter.deployment_data = action.params.get('deployment_data')!
}
if action.params.exists('deployment_hash') {
filter.deployment_hash = action.params.get('deployment_hash')!
}
page := action.params.get_u64_default('page', 1)!
size := action.params.get_u64_default('size', 50)!
randomize := action.params.get_default_false('randomize')
req := FindContracts{
filters: filter
pagination: Limit{
page: page
size: size
randomize: randomize
}
}
res := h.tfgrid.find_contracts(req)!
h.logger.info('contracts: ${res}')
}
else {
return error('explorer does not support operation: ${action.name}')
}
}
}

View File

@@ -1,17 +0,0 @@
module tfgrid
import freeflowuniverse.herolib.core.playbook { Action }
fn (mut t TFGridHandler) core(action Action) ! {
match action.name {
'login' {
mnemonic := action.params.get_default('mnemonic', '')!
netstring := action.params.get_default('network', 'main')!
t.tfgrid.load(mnemonic: mnemonic, network: netstring)!
}
else {
return error('core action ${action.name} is invalid')
}
}
}

View File

@@ -1,54 +0,0 @@
module tfgrid
import freeflowuniverse.herolib.core.playbook { Action }
import rand
fn (mut t TFGridHandler) discourse(action Action) ! {
match action.name {
'create' {
name := action.params.get_default('name', rand.string(10).to_lower())!
farm_id := action.params.get_int_default('farm_id', 0)!
capacity := action.params.get_default('capacity', 'medium')!
ssh_key_name := action.params.get_default('ssh_key', 'default')!
ssh_key := t.get_ssh_key(ssh_key_name)!
developer_email := action.params.get_default('developer_email', '')!
smtp_address := action.params.get_default('smtp_address', 'smtp.gmail.com')!
smtp_port := action.params.get_int_default('smtp_port', 587)!
smtp_username := action.params.get_default('smtp_username', '')!
smtp_password := action.params.get_default('smtp_password', '')!
smtp_tls := action.params.get_default_false('smtp_tls')
deploy_res := t.tfgrid.deploy_discourse(
name: name
farm_id: u64(farm_id)
capacity: capacity
ssh_key: ssh_key
developer_email: developer_email
smtp_address: smtp_address
smtp_port: u32(smtp_port)
smtp_username: smtp_username
smtp_password: smtp_password
smtp_enable_tls: smtp_tls
)!
t.logger.info('${deploy_res}')
}
'get' {
name := action.params.get('name')!
get_res := t.tfgrid.get_discourse_deployment(name)!
t.logger.info('${get_res}')
}
'delete' {
name := action.params.get('name')!
t.tfgrid.cancel_discourse_deployment(name) or {
return error('failed to delete discourse instance: ${err}')
}
}
else {
return error('operation ${action.name} is not supported on discourse')
}
}
}

View File

@@ -1,61 +0,0 @@
module tfgrid
import freeflowuniverse.herolib.core.playbook { Action }
import freeflowuniverse.herolib.threefold.web3gw.tfgrid { FarmFilter, FindFarms, Limit }
pub fn (mut h TFGridHandler) farms(action Action) ! {
match action.name {
'get' {
mut filter := FarmFilter{}
if action.params.exists('free_ips') {
filter.free_ips = action.params.get_u64('free_ips')!
}
if action.params.exists('total_ips') {
filter.total_ips = action.params.get_u64('total_ips')!
}
if action.params.exists('stellar_address') {
filter.stellar_address = action.params.get('stellar_address')!
}
if action.params.exists('pricing_policy_id') {
filter.pricing_policy_id = action.params.get_u64('pricing_policy_id')!
}
if action.params.exists('farm_id') {
filter.farm_id = action.params.get_u64('farm_id')!
}
if action.params.exists('twin_id') {
filter.twin_id = action.params.get_u64('twin_id')!
}
if action.params.exists('name') {
filter.name = action.params.get('name')!
}
if action.params.exists('name_contains') {
filter.name_contains = action.params.get('name_contains')!
}
if action.params.exists('certification_type') {
filter.certification_type = action.params.get('certification_type')!
}
if action.params.exists('dedicated') {
filter.dedicated = action.params.get_default_false('dedicated')
}
page := action.params.get_u64_default('page', 1)!
size := action.params.get_u64_default('size', 50)!
randomize := action.params.get_default_false('randomize')
req := FindFarms{
filters: filter
pagination: Limit{
page: page
size: size
randomize: randomize
}
}
res := h.tfgrid.find_farms(req)!
h.logger.info('farms: ${res}')
}
else {
return error('explorer does not support operation: ${action.name}')
}
}
}

View File

@@ -1,48 +0,0 @@
module tfgrid
import freeflowuniverse.herolib.core.playbook { Action }
import rand
fn (mut t TFGridHandler) funkwhale(action Action) ! {
match action.name {
'create' {
name := action.params.get_default('name', rand.string(10).to_lower())!
farm_id := action.params.get_int_default('farm_id', 0)!
capacity := action.params.get_default('capacity', 'meduim')!
ssh_key_name := action.params.get_default('ssh_key', 'default')!
ssh_key := t.get_ssh_key(ssh_key_name)!
admin_email := action.params.get('admin_email')!
admin_username := action.params.get_default('admin_username', '')!
admin_password := action.params.get_default('admin_password', '')!
deploy_res := t.tfgrid.deploy_funkwhale(
name: name
farm_id: u64(farm_id)
capacity: capacity
ssh_key: ssh_key
admin_email: admin_email
admin_username: admin_username
admin_password: admin_password
)!
t.logger.info('${deploy_res}')
}
'get' {
name := action.params.get('name')!
get_res := t.tfgrid.get_funkwhale_deployment(name)!
t.logger.info('${get_res}')
}
'delete' {
name := action.params.get('name')!
t.tfgrid.cancel_funkwhale_deployment(name) or {
return error('failed to delete funkwhale instance: ${err}')
}
}
else {
return error('operation ${action.name} is not supported on funkwhale')
}
}
}

Some files were not shown because too many files have changed in this diff Show More