diff --git a/lib/threelang/nostr/channel.v b/lib/threelang/nostr/channel.v index 39370f47f..c0a6edacb 100644 --- a/lib/threelang/nostr/channel.v +++ b/lib/threelang/nostr/channel.v @@ -1,6 +1,6 @@ module nostr -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } fn (mut n NostrHandler) channel(action Action) ! { match action.name { diff --git a/lib/threelang/nostr/direct.v b/lib/threelang/nostr/direct.v index ecb9d977a..7ea31076c 100644 --- a/lib/threelang/nostr/direct.v +++ b/lib/threelang/nostr/direct.v @@ -1,6 +1,6 @@ module nostr -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } fn (mut n NostrHandler) direct(action Action) ! { match action.name { diff --git a/lib/threelang/nostr/handler.v b/lib/threelang/nostr/handler.v index 914959cc9..3147da8dd 100644 --- a/lib/threelang/nostr/handler.v +++ b/lib/threelang/nostr/handler.v @@ -1,7 +1,7 @@ module nostr import threefoldtech.threebot.nostr as nostr_client { NostrClient } -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } import freeflowuniverse.crystallib.rpcwebsocket { RpcWsClient } import log { Logger } diff --git a/lib/threelang/stellar/account.v b/lib/threelang/stellar/account.v index 7cdcc5647..f410a006a 100644 --- a/lib/threelang/stellar/account.v +++ b/lib/threelang/stellar/account.v @@ -1,6 +1,6 @@ module stellar -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } fn (mut h StellarHandler) account(action Action) ! { match action.name { diff --git a/lib/threelang/stellar/handler.v b/lib/threelang/stellar/handler.v index 097049270..7975ec7b2 100644 --- a/lib/threelang/stellar/handler.v +++ b/lib/threelang/stellar/handler.v @@ -1,7 +1,7 @@ module stellar import threefoldtech.threebot.stellar as stellar_client { StellarClient } -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } import freeflowuniverse.crystallib.rpcwebsocket { RpcWsClient } import log { Logger } diff --git a/manual/src/threelang/examples/tfgrid/network.md b/manual/src/threelang/examples/tfgrid/network.md new file mode 100644 index 000000000..2c27c6545 --- /dev/null +++ b/manual/src/threelang/examples/tfgrid/network.md @@ -0,0 +1,35 @@ +# Machines Example + +- This example deployes, gets, udpates, and deletes a network of machines on the tfgrid. + +```md +!!tfgrid.core.login +mnemonic: '' +network: dev + +!!tfgrid.sshkeys.new +name: SSH_KEY +ssh_key: '' + +!!tfgrid.network.create +network: skynet +capacity: small +times: 2 +gateway: yes +add_wireguard_access: yes +disk_size: 10GB + +!!tfgrid.network.create +network: skynet +capacity: medium + +!!tfgrid.network.remove +network: skynet +machine: ewbjpuqe + +!!tfgrid.network.get +network: skynet + +!!tfgrid.network.delete +network: skynet +``` diff --git a/web3gw/client/threelang/README.md b/web3gw/client/threelang/README.md index 4c6dd0652..6b97c0a5c 100644 --- a/web3gw/client/threelang/README.md +++ b/web3gw/client/threelang/README.md @@ -7,7 +7,7 @@ ## 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. @@ -15,4 +15,4 @@ - The new handler must implement a handle_action method. - The handle_action method receives an actionparser.Action, and executes the action however it sees fit. - Handlers are responsible for logging their output, if any. - - To add docuemntation 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. + - 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. diff --git a/web3gw/client/threelang/factory.v b/web3gw/client/threelang/factory.v index cb5c82096..79ca7d13e 100644 --- a/web3gw/client/threelang/factory.v +++ b/web3gw/client/threelang/factory.v @@ -1,21 +1,21 @@ module threelang import log -import freeflowuniverse.crystallib.actionsparser +import freeflowuniverse.crystallib.baobab.actions import freeflowuniverse.crystallib.rpcwebsocket { RpcWsClient } -import threefoldtech.threebot.tfgrid as tfgrid_client -import threefoldtech.threebot.tfchain as tfchain_client -import threefoldtech.threebot.stellar as stellar_client -import threefoldtech.threebot.eth as eth_client -import threefoldtech.threebot.btc as btc_client -import threefoldtech.threebot.threelang.tfgrid { TFGridHandler } -import threefoldtech.threebot.threelang.web3gw { Web3GWHandler } -import threefoldtech.threebot.threelang.clients { Clients } -import threefoldtech.threebot.threelang.stellar { StellarHandler } +import threefoldtech.web3gw.tfgrid as tfgrid_client +import threefoldtech.web3gw.tfchain as tfchain_client +import threefoldtech.web3gw.stellar as stellar_client +import threefoldtech.web3gw.eth as eth_client +import threefoldtech.web3gw.btc as btc_client +import threefoldtech.web3gw.threelang.tfgrid { TFGridHandler } +import threefoldtech.web3gw.threelang.web3gw { Web3GWHandler } +import threefoldtech.web3gw.threelang.clients { Clients } +import threefoldtech.web3gw.threelang.stellar { StellarHandler } const ( - tfgrid_book = 'tfgrid' - web3gw_book = 'web3gw' + tfgrid_book = 'tfgrid' + web3gw_book = 'web3gw' stellar_book = 'stellar' ) @@ -37,7 +37,7 @@ pub mut: } pub fn new(args RunnerArgs, debug_log bool) !Runner { - mut ap := actionsparser.new(path: args.path, defaultbook: 'aaa')! + mut ap := actions.new(path: args.path)! mut logger := log.Logger(&log.Log{ level: if debug_log { .debug } else { .info } @@ -66,8 +66,8 @@ pub fn new(args RunnerArgs, debug_log bool) !Runner { return runner } -pub fn (mut r Runner) run(mut action_parser actionsparser.ActionsParser) ! { - for action in action_parser.actions { +pub fn (mut r Runner) run(mut acs actions.Actions) ! { + for action in acs.actions { match action.book { threelang.tfgrid_book { r.tfgrid_handler.handle_action(action)! diff --git a/web3gw/client/threelang/stellar/account.v b/web3gw/client/threelang/stellar/account.v index 7cdcc5647..f410a006a 100644 --- a/web3gw/client/threelang/stellar/account.v +++ b/web3gw/client/threelang/stellar/account.v @@ -1,6 +1,6 @@ module stellar -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } fn (mut h StellarHandler) account(action Action) ! { match action.name { diff --git a/web3gw/client/threelang/stellar/handler.v b/web3gw/client/threelang/stellar/handler.v index b79afb631..987847cfd 100644 --- a/web3gw/client/threelang/stellar/handler.v +++ b/web3gw/client/threelang/stellar/handler.v @@ -1,7 +1,7 @@ module stellar import threefoldtech.web3gw.stellar as stellar_client { StellarClient } -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } import freeflowuniverse.crystallib.rpcwebsocket { RpcWsClient } import log { Logger } diff --git a/web3gw/client/threelang/tfgrid/contracts.v b/web3gw/client/threelang/tfgrid/contracts.v index 03fe9d274..6bce8685c 100644 --- a/web3gw/client/threelang/tfgrid/contracts.v +++ b/web3gw/client/threelang/tfgrid/contracts.v @@ -1,14 +1,17 @@ module tfgrid -import freeflowuniverse.crystallib.actionsparser { Action } -import threefoldtech.web3gw.explorer { ContractFilter, ContractsRequestParams, Limit } +import freeflowuniverse.crystallib.baobab.actions { Action } +import threefoldtech.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.explorer.load(network)! - + 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')! @@ -41,19 +44,17 @@ pub fn (mut h TFGridHandler) contracts(action Action) ! { page := action.params.get_u64_default('page', 1)! size := action.params.get_u64_default('size', 50)! randomize := action.params.get_default_false('randomize') - count := action.params.get_default_false('count') - req := ContractsRequestParams{ + req := FindContracts{ filters: filter pagination: Limit{ page: page size: size randomize: randomize - ret_count: count } } - res := h.explorer.contracts(req)! + res := h.tfgrid.find_contracts(req)! h.logger.info('contracts: ${res}') } else { diff --git a/web3gw/client/threelang/tfgrid/core.v b/web3gw/client/threelang/tfgrid/core.v index 355b70f1b..f46b70b2f 100644 --- a/web3gw/client/threelang/tfgrid/core.v +++ b/web3gw/client/threelang/tfgrid/core.v @@ -1,6 +1,6 @@ module tfgrid -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } fn (mut t TFGridHandler) core(action Action) ! { match action.name { diff --git a/web3gw/client/threelang/tfgrid/discourse.v b/web3gw/client/threelang/tfgrid/discourse.v index e8aa2f3ec..16e37b9ce 100644 --- a/web3gw/client/threelang/tfgrid/discourse.v +++ b/web3gw/client/threelang/tfgrid/discourse.v @@ -1,10 +1,9 @@ module tfgrid -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } import rand fn (mut t TFGridHandler) discourse(action Action) ! { - mut discourse_client := t.tfgrid.applications().discourse() match action.name { 'create' { name := action.params.get_default('name', rand.string(10).to_lower())! @@ -19,7 +18,7 @@ fn (mut t TFGridHandler) discourse(action Action) ! { smtp_password := action.params.get_default('smtp_password', '')! smtp_tls := action.params.get_default_false('smtp_tls') - deploy_res := discourse_client.deploy( + deploy_res := t.tfgrid.deploy_discourse( name: name farm_id: u64(farm_id) capacity: capacity @@ -37,14 +36,14 @@ fn (mut t TFGridHandler) discourse(action Action) ! { 'get' { name := action.params.get('name')! - get_res := discourse_client.get(name)! + get_res := t.tfgrid.get_discourse_deployment(name)! t.logger.info('${get_res}') } 'delete' { name := action.params.get('name')! - discourse_client.delete(name) or { + t.tfgrid.cancel_discourse_deployment(name) or { return error('failed to delete discourse instance: ${err}') } } diff --git a/web3gw/client/threelang/tfgrid/farms.v b/web3gw/client/threelang/tfgrid/farms.v index 043dd2a7e..255ea4399 100644 --- a/web3gw/client/threelang/tfgrid/farms.v +++ b/web3gw/client/threelang/tfgrid/farms.v @@ -1,14 +1,11 @@ module tfgrid -import freeflowuniverse.crystallib.actionsparser { Action } -import threefoldtech.web3gw.explorer { FarmFilter, FarmsRequestParams, Limit } +import freeflowuniverse.crystallib.baobab.actions { Action } +import threefoldtech.web3gw.tfgrid { FarmFilter, FindFarms, Limit } pub fn (mut h TFGridHandler) farms(action Action) ! { match action.name { 'get' { - network := action.params.get_default('network', 'main')! - h.explorer.load(network)! - mut filter := FarmFilter{} if action.params.exists('free_ips') { filter.free_ips = action.params.get_u64('free_ips')! @@ -44,19 +41,17 @@ pub fn (mut h TFGridHandler) farms(action Action) ! { page := action.params.get_u64_default('page', 1)! size := action.params.get_u64_default('size', 50)! randomize := action.params.get_default_false('randomize') - count := action.params.get_default_false('count') - req := FarmsRequestParams{ + req := FindFarms{ filters: filter pagination: Limit{ page: page size: size randomize: randomize - ret_count: count } } - res := h.explorer.farms(req)! + res := h.tfgrid.find_farms(req)! h.logger.info('farms: ${res}') } else { diff --git a/web3gw/client/threelang/tfgrid/funkwhale.v b/web3gw/client/threelang/tfgrid/funkwhale.v index 9b008d656..8a1b18645 100644 --- a/web3gw/client/threelang/tfgrid/funkwhale.v +++ b/web3gw/client/threelang/tfgrid/funkwhale.v @@ -1,10 +1,9 @@ module tfgrid -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } import rand fn (mut t TFGridHandler) funkwhale(action Action) ! { - mut funkwhale_client := t.tfgrid.applications().funkwhale() match action.name { 'create' { name := action.params.get_default('name', rand.string(10).to_lower())! @@ -16,7 +15,7 @@ fn (mut t TFGridHandler) funkwhale(action Action) ! { admin_username := action.params.get_default('admin_username', '')! admin_password := action.params.get_default('admin_password', '')! - deploy_res := funkwhale_client.deploy( + deploy_res := t.tfgrid.deploy_funkwhale( name: name farm_id: u64(farm_id) capacity: capacity @@ -31,14 +30,14 @@ fn (mut t TFGridHandler) funkwhale(action Action) ! { 'get' { name := action.params.get('name')! - get_res := funkwhale_client.get(name)! + get_res :=t.tfgrid.get_funkwhale_deployment(name)! t.logger.info('${get_res}') } 'delete' { name := action.params.get('name')! - funkwhale_client.delete(name) or { + t.tfgrid.cancel_funkwhale_deployment(name) or { return error('failed to delete funkwhale instance: ${err}') } } diff --git a/web3gw/client/threelang/tfgrid/gateway_fqdn.v b/web3gw/client/threelang/tfgrid/gateway_fqdn.v index 2b1be7701..6b581f68b 100644 --- a/web3gw/client/threelang/tfgrid/gateway_fqdn.v +++ b/web3gw/client/threelang/tfgrid/gateway_fqdn.v @@ -1,6 +1,6 @@ module tfgrid -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } import threefoldtech.web3gw.tfgrid as tfgrid_client { GatewayFQDN } import rand @@ -13,7 +13,7 @@ fn (mut t TFGridHandler) gateway_fqdn(action Action) ! { backend := action.params.get('backend')! fqdn := action.params.get('fqdn')! - gw_deploy := t.tfgrid.gateways_deploy_fqdn(GatewayFQDN{ + gw_deploy := t.tfgrid.deploy_gateway_fqdn(GatewayFQDN{ name: name node_id: u32(node_id) tls_passthrough: tls_passthrough @@ -25,11 +25,11 @@ fn (mut t TFGridHandler) gateway_fqdn(action Action) ! { } 'delete' { name := action.params.get('name')! - t.tfgrid.gateways_delete_fqdn(name)! + t.tfgrid.cancel_gateway_fqdn(name)! } 'get' { name := action.params.get('name')! - gw_get := t.tfgrid.gateways_get_fqdn(name)! + gw_get := t.tfgrid.get_gateway_fqdn(name)! t.logger.info('${gw_get}') } diff --git a/web3gw/client/threelang/tfgrid/gateway_name.v b/web3gw/client/threelang/tfgrid/gateway_name.v index 89e249d55..e078fe760 100644 --- a/web3gw/client/threelang/tfgrid/gateway_name.v +++ b/web3gw/client/threelang/tfgrid/gateway_name.v @@ -1,6 +1,6 @@ module tfgrid -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } import threefoldtech.web3gw.tfgrid as tfgrid_client { GatewayName } import rand @@ -12,7 +12,7 @@ fn (mut t TFGridHandler) gateway_name(action Action) ! { tls_passthrough := action.params.get_default_false('tls_passthrough') backend := action.params.get('backend')! - gw_deploy := t.tfgrid.gateways_deploy_name(GatewayName{ + gw_deploy := t.tfgrid.deploy_gateway_name(GatewayName{ name: name node_id: u32(node_id) tls_passthrough: tls_passthrough @@ -23,11 +23,11 @@ fn (mut t TFGridHandler) gateway_name(action Action) ! { } 'delete' { name := action.params.get('name')! - t.tfgrid.gateways_delete_name(name)! + t.tfgrid.cancel_gateway_name(name)! } 'get' { name := action.params.get('name')! - gw_get := t.tfgrid.gateways_get_name(name)! + gw_get := t.tfgrid.get_gateway_name(name)! t.logger.info('${gw_get}') } diff --git a/web3gw/client/threelang/tfgrid/handler.v b/web3gw/client/threelang/tfgrid/handler.v index 01a50fc44..55540685f 100644 --- a/web3gw/client/threelang/tfgrid/handler.v +++ b/web3gw/client/threelang/tfgrid/handler.v @@ -1,8 +1,7 @@ module tfgrid import threefoldtech.web3gw.tfgrid as tfgrid_client { TFGridClient } -import threefoldtech.web3gw.explorer { ExplorerClient } -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } import freeflowuniverse.crystallib.rpcwebsocket { RpcWsClient } import log { Logger } @@ -10,18 +9,14 @@ import log { Logger } pub struct TFGridHandler { pub mut: tfgrid TFGridClient - explorer ExplorerClient ssh_keys map[string]string logger Logger handlers map[string]fn (action Action) ! } pub fn new(mut rpc_client RpcWsClient, logger Logger, mut grid_client TFGridClient) TFGridHandler { - mut explorer_client := explorer.new(mut rpc_client) - mut t := TFGridHandler{ tfgrid: grid_client - explorer: explorer_client logger: logger } diff --git a/web3gw/client/threelang/tfgrid/helpers.v b/web3gw/client/threelang/tfgrid/helpers.v index 7c47e62b8..cb3fa5967 100644 --- a/web3gw/client/threelang/tfgrid/helpers.v +++ b/web3gw/client/threelang/tfgrid/helpers.v @@ -1,6 +1,6 @@ module tfgrid -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } pub fn (mut t TFGridHandler) helper(action Action) ! { match action.actor { diff --git a/web3gw/client/threelang/tfgrid/k8s.v b/web3gw/client/threelang/tfgrid/k8s.v index 6d9692aec..67bce3fa4 100644 --- a/web3gw/client/threelang/tfgrid/k8s.v +++ b/web3gw/client/threelang/tfgrid/k8s.v @@ -1,7 +1,7 @@ module tfgrid -import freeflowuniverse.crystallib.actionsparser { Action } -import threefoldtech.web3gw.tfgrid as tfgrid_client { AddK8sWorker, GetK8sParams, K8sCluster, K8sNode, RemoveK8sWorker } +import freeflowuniverse.crystallib.baobab.actions { Action } +import threefoldtech.web3gw.tfgrid as tfgrid_client { AddWorkerToK8sCluster, K8sCluster, K8sNode, RemoveWorkerFromK8sCluster } import rand fn (mut t TFGridHandler) k8s(action Action) ! { @@ -51,17 +51,14 @@ fn (mut t TFGridHandler) k8s(action Action) ! { add_wg_access: add_wg_access } - deploy_res := t.tfgrid.k8s_deploy(cluster)! + deploy_res := t.tfgrid.deploy_k8s_cluster(cluster)! t.logger.info('${deploy_res}') } 'get' { name := action.params.get('name')! - get_res := t.tfgrid.k8s_get(GetK8sParams{ - cluster_name: name - master_name: 'master' - })! + get_res := t.tfgrid.get_k8s_cluster(name)! t.logger.info('${get_res}') } @@ -82,9 +79,8 @@ fn (mut t TFGridHandler) k8s(action Action) ! { public_ip: add_public_ip } - add_res := t.tfgrid.k8s_add_worker(AddK8sWorker{ + add_res := t.tfgrid.add_worker_to_k8s_cluster(AddWorkerToK8sCluster{ cluster_name: name - master_name: 'master' worker: worker })! @@ -94,9 +90,8 @@ fn (mut t TFGridHandler) k8s(action Action) ! { name := action.params.get('name')! worker_name := action.params.get('worker_name')! - remove_res := t.tfgrid.k8s_remove_worker(RemoveK8sWorker{ + remove_res := t.tfgrid.remove_worker_from_k8s_cluster(RemoveWorkerFromK8sCluster{ cluster_name: name - master_name: 'master' worker_name: worker_name })! t.logger.info('${remove_res}') @@ -104,7 +99,7 @@ fn (mut t TFGridHandler) k8s(action Action) ! { 'delete' { name := action.params.get('name')! - t.tfgrid.k8s_delete(name) or { return error('failed to delete k8s cluster: ${err}') } + t.tfgrid.cancel_k8s_cluster(name) or { return error('failed to delete k8s cluster: ${err}') } } else { return error('operation ${action.name} is not supported on k8s') diff --git a/web3gw/client/threelang/tfgrid/network.v b/web3gw/client/threelang/tfgrid/network.v new file mode 100644 index 000000000..f4c257ec2 --- /dev/null +++ b/web3gw/client/threelang/tfgrid/network.v @@ -0,0 +1,88 @@ +module tfgrid + +import freeflowuniverse.crystallib.baobab.actions { Action } +import threefoldtech.web3gw.tfgrid { NetworkConfiguration, VMConfiguration } +import rand + +fn (mut t TFGridHandler) network(action Action) ! { + match action.name { + 'create' { + name := action.params.get_default('name', rand.string(6).to_lower())! + description := action.params.get_default('description', '')! + farm_id := action.params.get_int_default('farm_id', 0)! + flist := action.params.get_default('flist', '')! + entrypoint := action.params.get_default('entrypoint', '')! + public_ip := action.params.get_default_false('public_ip') + public_ip6 := action.params.get_default_false('public_ip6') + planetary := action.params.get_default_false('planetary') + cpu := action.params.get_u32_default('cpu', 1)! + memory := action.params.get_u64_default('memory', 1024)! + disk_size := action.params.get_storagecapacity_in_gigabytes('disk_size') or { 0 } + times := action.params.get_int_default('times', 1)! + wg := action.params.get_default_false('add_wireguard_access') + ssh_key_name := action.params.get_default('sshkey', 'default')! + ssh_key := t.get_ssh_key(ssh_key_name)! + + env_vars := { + ssh_key_name: ssh_key + } + // construct vms from the provided data + mut vm_configs := []VMConfiguration{} + for i := 0; i < times; i++ { + vm_config := VMConfiguration{ + name: name + farm_id: u32(farm_id) + flist: flist + entrypoint: entrypoint + public_ip: public_ip + public_ip6: public_ip6 + planetary: planetary + cpu: cpu + memory: memory + rootfs_size: u32(disk_size) + env_vars: env_vars + } + vm_configs << vm_config + } + mut net_config := NetworkConfiguration{ + name: name + add_wireguard_access: wg + } + deploy_res := t.tfgrid.deploy_network( + name: name + description: description + network: net_config + vms: vm_configs + )! + + t.logger.info('${deploy_res}') + } + 'get' { + network := action.params.get('network')! + + get_res := t.tfgrid.get_network_deployment(network)! + + t.logger.info('${get_res}') + } + 'remove' { + network := action.params.get('network')! + machine := action.params.get('machine')! + + remove_res := t.tfgrid.remove_vm_from_network_deployment( + network: network + vm: machine + )! + t.logger.info('${remove_res}') + } + 'delete' { + network := action.params.get('network')! + + t.tfgrid.cancel_network_deployment(network) or { + return error('failed to delete vm network: ${err}') + } + } + else { + return error('operation ${action.name} is not supported on vms') + } + } +} diff --git a/web3gw/client/threelang/tfgrid/nodes.v b/web3gw/client/threelang/tfgrid/nodes.v index 20db7330f..6e2dbb8ad 100644 --- a/web3gw/client/threelang/tfgrid/nodes.v +++ b/web3gw/client/threelang/tfgrid/nodes.v @@ -1,13 +1,13 @@ module tfgrid -import freeflowuniverse.crystallib.actionsparser { Action } -import threefoldtech.web3gw.explorer { Limit, NodeFilter, NodesRequestParams } +import freeflowuniverse.crystallib.baobab.actions { Action } +import threefoldtech.web3gw.tfgrid { FindNodes, Limit, NodeFilter } pub fn (mut h TFGridHandler) nodes(action Action) ! { match action.name { 'get' { - network := action.params.get_default('network', 'main')! - h.explorer.load(network)! + // network := action.params.get_default('network', 'main')! + // h.tfgrid.load(network)! mut filter := NodeFilter{} if action.params.exists('status') { @@ -92,19 +92,17 @@ pub fn (mut h TFGridHandler) nodes(action Action) ! { page := action.params.get_u64_default('page', 1)! size := action.params.get_u64_default('size', 50)! randomize := action.params.get_default_false('randomize') - count := action.params.get_default_false('count') - req := NodesRequestParams{ + req := FindNodes{ filters: filter pagination: Limit{ page: page size: size randomize: randomize - ret_count: count } } - res := h.explorer.nodes(req)! + res := h.tfgrid.find_nodes(req)! h.logger.info('nodes: ${res}') } else { diff --git a/web3gw/client/threelang/tfgrid/peertube.v b/web3gw/client/threelang/tfgrid/peertube.v index 046c62cb3..5925e2579 100644 --- a/web3gw/client/threelang/tfgrid/peertube.v +++ b/web3gw/client/threelang/tfgrid/peertube.v @@ -1,10 +1,9 @@ module tfgrid -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } import rand fn (mut t TFGridHandler) peertube(action Action) ! { - mut peertube_client := t.tfgrid.applications().peertube() match action.name { 'create' { name := action.params.get_default('name', rand.string(8).to_lower())! @@ -16,7 +15,7 @@ fn (mut t TFGridHandler) peertube(action Action) ! { db_username := action.params.get_default('db_username', rand.string(8).to_lower())! db_password := action.params.get_default('db_password', rand.string(8).to_lower())! - deploy_res := peertube_client.deploy( + deploy_res := t.tfgrid.deploy_peertube( name: name farm_id: u64(farm_id) capacity: capacity @@ -31,14 +30,14 @@ fn (mut t TFGridHandler) peertube(action Action) ! { 'get' { name := action.params.get('name')! - get_res := peertube_client.get(name)! + get_res := t.tfgrid.get_peertube_deployment(name)! t.logger.info('${get_res}') } 'delete' { name := action.params.get('name')! - peertube_client.delete(name) or { + t.tfgrid.cancel_peertube_deployment(name) or { return error('failed to delete peertube instance: ${err}') } } diff --git a/web3gw/client/threelang/tfgrid/presearch.v b/web3gw/client/threelang/tfgrid/presearch.v index 9529ba6f9..71eff76c6 100644 --- a/web3gw/client/threelang/tfgrid/presearch.v +++ b/web3gw/client/threelang/tfgrid/presearch.v @@ -1,10 +1,9 @@ module tfgrid -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } import rand fn (mut t TFGridHandler) presearch(action Action) ! { - mut presearch_client := t.tfgrid.applications().presearch() match action.name { 'create' { name := action.params.get_default('name', rand.string(10).to_lower())! @@ -17,7 +16,7 @@ fn (mut t TFGridHandler) presearch(action Action) ! { public_restore_key := action.params.get_default('public_restore_key', '')! private_restore_key := action.params.get_default('private_restore_key', '')! - deploy_res := presearch_client.deploy( + deploy_res := t.tfgrid.deploy_presearch( name: name farm_id: u64(farm_id) ssh_key: ssh_key @@ -33,14 +32,14 @@ fn (mut t TFGridHandler) presearch(action Action) ! { 'get' { name := action.params.get('name')! - get_res := presearch_client.get(name)! + get_res := t.tfgrid.get_presearch_deployment(name)! t.logger.info('${get_res}') } 'delete' { name := action.params.get('name')! - presearch_client.delete(name) or { + t.tfgrid.cancel_presearch_deployment(name) or { return error('failed to delete presearch instance: ${err}') } } diff --git a/web3gw/client/threelang/tfgrid/stats.v b/web3gw/client/threelang/tfgrid/stats.v index 760fa8429..f003cd260 100644 --- a/web3gw/client/threelang/tfgrid/stats.v +++ b/web3gw/client/threelang/tfgrid/stats.v @@ -1,20 +1,20 @@ module tfgrid -import freeflowuniverse.crystallib.actionsparser { Action } -import threefoldtech.web3gw.explorer { StatsFilter } +import freeflowuniverse.crystallib.baobab.actions { Action } +import threefoldtech.web3gw.tfgrid { GetStatistics } pub fn (mut h TFGridHandler) stats(action Action) ! { match action.name { 'get' { - network := action.params.get_default('network', 'main')! - h.explorer.load(network)! + // network := action.params.get_default('network', 'main')! + // h.explorer.load(network)! - mut filter := StatsFilter{} + mut filter := GetStatistics{} if action.params.exists('status') { filter.status = action.params.get('status')! } - res := h.explorer.counters(filter)! + res := h.tfgrid.statistics(filter)! h.logger.info('stats: ${res}') } else { diff --git a/web3gw/client/threelang/tfgrid/taiga.v b/web3gw/client/threelang/tfgrid/taiga.v index 5d4d7b436..4d3728bfe 100644 --- a/web3gw/client/threelang/tfgrid/taiga.v +++ b/web3gw/client/threelang/tfgrid/taiga.v @@ -1,10 +1,9 @@ module tfgrid -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } import rand fn (mut t TFGridHandler) taiga(action Action) ! { - mut taiga_client := t.tfgrid.applications().taiga() match action.name { 'create' { name := action.params.get_default('name', rand.string(8).to_lower())! @@ -17,7 +16,7 @@ fn (mut t TFGridHandler) taiga(action Action) ! { admin_email := action.params.get('admin_email')! disk_size := action.params.get_storagecapacity_in_gigabytes('disk_size') or { 50 } - deploy_res := taiga_client.deploy( + deploy_res := t.tfgrid.deploy_taiga( name: name farm_id: u64(farm_id) capacity: capacity @@ -33,14 +32,14 @@ fn (mut t TFGridHandler) taiga(action Action) ! { 'get' { name := action.params.get('name')! - get_res := taiga_client.get(name)! + get_res := t.tfgrid.get_taiga_deployment(name)! t.logger.info('${get_res}') } 'delete' { name := action.params.get('name')! - taiga_client.delete(name) or { return error('failed to delete taiga instance: ${err}') } + t.tfgrid.cancel_taiga_deployment(name) or { return error('failed to delete taiga instance: ${err}') } } else { return error('operation ${action.name} is not supported on taiga') diff --git a/web3gw/client/threelang/tfgrid/twins.v b/web3gw/client/threelang/tfgrid/twins.v index 441fe4d38..3b1c6f538 100644 --- a/web3gw/client/threelang/tfgrid/twins.v +++ b/web3gw/client/threelang/tfgrid/twins.v @@ -1,7 +1,7 @@ module tfgrid -import freeflowuniverse.crystallib.actionsparser { Action } -import threefoldtech.web3gw.explorer { Limit, TwinFilter, TwinsRequestParams } +import freeflowuniverse.crystallib.baobab.actions { Action } +import threefoldtech.web3gw.tfgrid { Limit, TwinFilter, FindTwins } pub fn (mut h TFGridHandler) twins(action Action) ! { match action.name { @@ -26,19 +26,17 @@ pub fn (mut h TFGridHandler) twins(action Action) ! { page := action.params.get_u64_default('page', 1)! size := action.params.get_u64_default('size', 50)! randomize := action.params.get_default_false('randomize') - count := action.params.get_default_false('count') - req := TwinsRequestParams{ + req := FindTwins{ filters: filter pagination: Limit{ page: page size: size randomize: randomize - ret_count: count } } - res := h.explorer.twins(req)! + res := h.tfgrid.find_twins(req)! h.logger.info('twins: ${res}') } else { diff --git a/web3gw/client/threelang/tfgrid/vm.v b/web3gw/client/threelang/tfgrid/vm.v index 163dc5f75..06e8e6157 100644 --- a/web3gw/client/threelang/tfgrid/vm.v +++ b/web3gw/client/threelang/tfgrid/vm.v @@ -1,6 +1,6 @@ module tfgrid -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } import threefoldtech.web3gw.tfgrid as tfgrid_client { RemoveVM, VM } import rand diff --git a/web3gw/client/threelang/tfgrid/zdb.v b/web3gw/client/threelang/tfgrid/zdb.v index d2bc793bc..94a5ffa5d 100644 --- a/web3gw/client/threelang/tfgrid/zdb.v +++ b/web3gw/client/threelang/tfgrid/zdb.v @@ -1,7 +1,7 @@ module tfgrid -import freeflowuniverse.crystallib.actionsparser { Action } -import threefoldtech.web3gw.tfgrid as tfgrid_client { ZDB } +import freeflowuniverse.crystallib.baobab.actions { Action } +import threefoldtech.web3gw.tfgrid as tfgrid_client { ZDBDeployment } import rand fn (mut t TFGridHandler) zdb(action Action) ! { @@ -14,7 +14,7 @@ fn (mut t TFGridHandler) zdb(action Action) ! { size := action.params.get_storagecapacity_in_gigabytes('size') or { 10 } mode := action.params.get_default('mode', 'user')! - zdb_deploy := t.tfgrid.zdb_deploy(ZDB{ + zdb_deploy := t.tfgrid.deploy_zdb(ZDBDeployment{ node_id: u32(node_id) name: name password: password @@ -27,11 +27,11 @@ fn (mut t TFGridHandler) zdb(action Action) ! { } 'delete' { name := action.params.get('name')! - t.tfgrid.zdb_delete(name)! + t.tfgrid.cancel_zdb_deployment(name)! } 'get' { name := action.params.get('name')! - zdb_get := t.tfgrid.zdb_get(name)! + zdb_get := t.tfgrid.get_zdb_deployment(name)! t.logger.info('${zdb_get}') } diff --git a/web3gw/client/threelang/web3gw/handler.v b/web3gw/client/threelang/web3gw/handler.v index a5793956d..06a1daf6e 100644 --- a/web3gw/client/threelang/web3gw/handler.v +++ b/web3gw/client/threelang/web3gw/handler.v @@ -1,7 +1,7 @@ module web3gw import log { Logger } -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } import freeflowuniverse.crystallib.rpcwebsocket { RpcWsClient } import threefoldtech.web3gw.threelang.clients { Clients } diff --git a/web3gw/client/threelang/web3gw/keys.v b/web3gw/client/threelang/web3gw/keys.v index c498d9edd..581f3e03a 100644 --- a/web3gw/client/threelang/web3gw/keys.v +++ b/web3gw/client/threelang/web3gw/keys.v @@ -1,6 +1,6 @@ module web3gw -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } pub fn (mut h Web3GWHandler) keys_define(action Action) ! { tfc_mnemonic := action.params.get_default('mnemonic', '')! diff --git a/web3gw/client/threelang/web3gw/money.v b/web3gw/client/threelang/web3gw/money.v index 91fb6214f..e2ac809e1 100644 --- a/web3gw/client/threelang/web3gw/money.v +++ b/web3gw/client/threelang/web3gw/money.v @@ -1,6 +1,6 @@ module web3gw -import freeflowuniverse.crystallib.actionsparser { Action } +import freeflowuniverse.crystallib.baobab.actions { Action } import strconv const ( diff --git a/web3gw/examples/template.v b/web3gw/examples/template.v index 5cc5eb692..216e62de0 100644 --- a/web3gw/examples/template.v +++ b/web3gw/examples/template.v @@ -1,15 +1,12 @@ module main import freeflowuniverse.crystallib.rpcwebsocket { RpcWsClient } - import threefoldtech.web3gw.eth -import threefoldtech.web3gw.explorer +import threefoldtech.web3gw.tfgrid import threefoldtech.web3gw.stellar import threefoldtech.web3gw.tfchain -import threefoldtech.web3gw.tfgrid import threefoldtech.web3gw.nostr -//ADD NEW CLIENTS HERE - +// ADD NEW CLIENTS HERE import flag import log import os @@ -19,14 +16,12 @@ const ( default_server_address = 'ws://127.0.0.1:8080' ) - fn execute_rpcs(mut client RpcWsClient, mut logger log.Logger, mnemonic string) ! { // ADD YOUR CALLS HERE } - fn main() { - // This is some code that allows us to quickly create a commmand line tool with arguments. + // This is some code that allows us to quickly create a commmand line tool with arguments. mut fp := flag.new_flag_parser(os.args) fp.application('Welcome to the web3_proxy client. The web3_proxy client allows you to execute all remote procedure calls that the web3_proxy server can handle.') fp.limit_free_args(0, 0)! @@ -51,7 +46,7 @@ fn main() { } _ := spawn myclient.run() execute_rpcs(mut myclient, mut logger, mnemonic) or { - logger.error("Failed executing calls: $err") + logger.error('Failed executing calls: ${err}') exit(1) } }