From 54b9dadbdeb08eca2ce9f15f07320a5a5e621137 Mon Sep 17 00:00:00 2001 From: Ali Chaddad Date: Sun, 27 Aug 2023 16:19:53 +0300 Subject: [PATCH] fix missing zos calls --- web3gw/client/tfchain/model.v | 147 +++++++++++++++++++++ web3gw/client/tfchain/tfchain.v | 36 +++++ web3gw/client/tfgrid/model.v | 101 ++++++++++++++ web3gw/client/tfgrid/zos_calls.v | 76 +++++++++++ web3gw/examples/nostr/chat_consumer.v | 2 +- web3gw/examples/nostr/stalls.v | 4 +- web3gw/examples/stellar/balance.v | 2 +- web3gw/examples/stellar/swap.v | 4 +- web3gw/examples/tfgrid/k8s.v | 31 ++--- web3gw/examples/tfgrid/machine_with_qsfs.v | 114 +++++++--------- web3gw/examples/tfgrid/machines.v | 121 ++++++++--------- web3gw/examples/tfgrid/zdb.v | 16 +-- web3gw/examples/tfgrid/zos_calls.v | 9 +- 13 files changed, 495 insertions(+), 168 deletions(-) create mode 100644 web3gw/client/tfgrid/zos_calls.v diff --git a/web3gw/client/tfchain/model.v b/web3gw/client/tfchain/model.v index 80d0e1d47..48a023705 100644 --- a/web3gw/client/tfchain/model.v +++ b/web3gw/client/tfchain/model.v @@ -92,3 +92,150 @@ pub: timeout int // the timeout after which we abandon the search height int // at what blockheight to start looking for the transaction } + +pub struct TwinOptionRelay { +pub: + has_value bool + as_value string +} + +pub struct TwinEntityProof { +pub: + entity_id u32 + signature string + +} + +pub struct TwinData { +pub: + id u32 + account_id string + relay TwinOptionRelay + entities []TwinEntityProof + +} + +pub struct NodeResources { +pub: + hru u64 + sru u64 + cru u64 + mru u64 +} + +pub struct NodeLocation { +pub: + city string + country string + latitude string + longitude string +} + +pub struct NodeIP { +pub: + ip string + gw string +} + +pub struct NodeOptionIP { +pub: + has_value bool + as_value NodeIP +} + +pub struct NodeOptionDomain { +pub: + has_value bool + as_value string +} + +pub struct NodePublicConfig { +pub: + ip4 NodeIP + ip6 NodeOptionIP + domain NodeOptionDomain +} + +pub struct NodeOptionPublicConfig { +pub: + has_value bool + as_value NodePublicConfig +} + +pub struct NodeOptionBoardSerial { +pub: + has_value bool + as_value string +} + +pub struct NodeCertification { +pub: + is_diy bool + is_certified bool +} + +pub struct NodeData { +pub: + version u32 + id u32 + farm_id u32 + twin_id u32 + resources NodeResources + location NodeLocation + public_config NodeOptionPublicConfig + created u64 + farming_policy u32 + secure_boot bool + virtualized bool + board_serial NodeOptionBoardSerial + connection_price u32 +} + +pub struct ContractDeletedState { +pub: + is_canceled_by_user bool + is_out_of_funds bool +} + +pub struct ContractState { +pub: + is_created bool + is_deleted bool + is_grace_period bool + as_grace_period_block_number u64 + as_deleted ContractDeletedState +} + + +pub struct ContractData { +pub: + version u32 + contract_id u64 + twin_id u32 + solution_provider_id u64 +} + +pub struct FarmCertification { +pub: + is_not_certified bool + is_gold bool +} + +pub struct FarmPublicIP { +pub: + ip string + gateway string + contract_id u64 +} + +pub struct FarmData { +pub: + version u32 + id u32 + name string + twin_id u32 + pricing_policy_id u32 + certification_type FarmCertification + public_ips []FarmPublicIP + dedicated_farm bool +} \ No newline at end of file diff --git a/web3gw/client/tfchain/tfchain.v b/web3gw/client/tfchain/tfchain.v index a556b7e25..182755b2b 100644 --- a/web3gw/client/tfchain/tfchain.v +++ b/web3gw/client/tfchain/tfchain.v @@ -186,3 +186,39 @@ pub fn (mut t TfChainClient) get_twin_by_pubkey(address string) !u32 { return t.client.send_json_rpc[[]string, u32]('tfchain.GetTwinByPubKey', [address], tfchain.default_timeout)! } + +// returns twin info via id +pub fn (mut t TfChainClient) get_twin(id u32) !TwinData { + return t.client.send_json_rpc[[]u32, TwinData]('tfchain.GetTwin', [id], + tfchain.default_timeout)! +} + +pub fn (mut t TfChainClient) get_node(id u32) !NodeData { + return t.client.send_json_rpc[[]u32, NodeData]('tfchain.GetNode', [id], + tfchain.default_timeout)! +} + +pub fn (mut t TfChainClient) get_nodes(farm_id u32) ![]u32 { + return t.client.send_json_rpc[[]u32, []u32]('tfchain.GetNodes', [farm_id], + tfchain.default_timeout)! +} + +pub fn (mut t TfChainClient) get_node_contracts(id u32) ![]u64 { + return t.client.send_json_rpc[[]u32, []u64]('tfchain.GetNodeContracts', [id], + tfchain.default_timeout)! +} + +pub fn (mut t TfChainClient) get_contract(id u64) !ContractData { + return t.client.send_json_rpc[[]u64, ContractData]('tfchain.GetContract', [id], + tfchain.default_timeout)! +} + +pub fn (mut t TfChainClient) get_farm(id u32) !FarmData { + return t.client.send_json_rpc[[]u32, FarmData]('tfchain.GetFarm', [id], + tfchain.default_timeout)! +} + +pub fn (mut t TfChainClient) get_farm_by_name(name string) !u32 { + return t.client.send_json_rpc[[]string, u32]('tfchain.GetFarmByName', [name], + tfchain.default_timeout)! +} diff --git a/web3gw/client/tfgrid/model.v b/web3gw/client/tfgrid/model.v index 9f79f98b2..5f2536189 100644 --- a/web3gw/client/tfgrid/model.v +++ b/web3gw/client/tfgrid/model.v @@ -586,3 +586,104 @@ pub: ipv6 string // instance ipv6, if any fqdn string // fully qualified domain name pointing to the instance } + +pub struct ZOSNodeRequest { +pub: + node_id int + data u64 +} + +pub struct NodeStatistics { +pub: + total Capacity + used Capacity +} + +pub struct SystemTooling { +pub: + aggregator string + decoder string +} + +pub struct SystemPropertyData { +pub: + value string + items []string +} + +pub struct SystemSubsection { +pub: + title string + properties map[string]SystemPropertyData +} + +pub struct SystemSection { +pub: + handleline string + typestr string + section_type int [json: 'type'] + subsections []SystemSubsection +} + +pub struct SystemDMI { +pub: + tooling SystemTooling + sections []SystemSection +} + +pub struct ZOSVersion { +pub: + zos string + zinit string +} + +pub struct WorkloadResult { +pub: + created u32 + state string + message string + data u64 +} + +pub struct Workload { +pub: + version u32 + name string + workload_type string [json: 'type'] + data ZDBWorkload + metadata string + description string + result WorkloadResult +} + +pub struct SignatureRequest { + twin_id u32 + required bool + weight u32 +} + +pub struct SignatureRequirement { +pub: + weight_required int + requests []SignatureRequest +} + +pub struct Deployment { +pub: + version u32 + twin_id u32 + contract_id u64 + metadata string + description string + expiration u64 + signature_requirement SignatureRequirement + workloads []Workload +} + +pub struct ZDBWorkload { +pub: + password string + mode string + size u32 + public bool +} diff --git a/web3gw/client/tfgrid/zos_calls.v b/web3gw/client/tfgrid/zos_calls.v new file mode 100644 index 000000000..27d83026f --- /dev/null +++ b/web3gw/client/tfgrid/zos_calls.v @@ -0,0 +1,76 @@ +module tfgrid + +import freeflowuniverse.crystallib.rpcwebsocket { RpcWsClient } + + +pub fn (mut t TFGridClient) zos_node_statistics(request ZOSNodeRequest) !NodeStatistics { + return t.client.send_json_rpc[[]ZOSNodeRequest, NodeStatistics]('tfgrid.ZOSStatisticsGet', [ + request, + ], t.timeout)! +} + +pub fn (mut t TFGridClient) zos_network_list_wg_ports(request ZOSNodeRequest) ![]u16 { + return t.client.send_json_rpc[[]ZOSNodeRequest, []u16]('tfgrid.ZOSNetworkListWGPorts', [ + request, + ], t.timeout)! +} + +pub fn (mut t TFGridClient) zos_network_interfaces(request ZOSNodeRequest) !map[string][]u32 { + return t.client.send_json_rpc[[]ZOSNodeRequest, map[string][]u32]('tfgrid.ZOSNetworkInterfaces', [ + request, + ], t.timeout)! +} + +pub fn (mut t TFGridClient) zos_network_public_config(request ZOSNodeRequest) !PublicConfig { + return t.client.send_json_rpc[[]ZOSNodeRequest, PublicConfig]('tfgrid.ZOSNetworkPublicConfigGet', [ + request, + ], t.timeout)! +} + +pub fn (mut t TFGridClient) zos_system_dmi(request ZOSNodeRequest) !SystemDMI { + return t.client.send_json_rpc[[]ZOSNodeRequest, SystemDMI]('tfgrid.ZOSSystemDMI', [ + request, + ], t.timeout)! +} + +pub fn (mut t TFGridClient) zos_system_hypervisor(request ZOSNodeRequest) !string { + return t.client.send_json_rpc[[]ZOSNodeRequest, string]('tfgrid.ZOSSystemHypervisor', [ + request, + ], t.timeout)! +} + +pub fn (mut t TFGridClient) zos_system_version(request ZOSNodeRequest) !ZOSVersion { + return t.client.send_json_rpc[[]ZOSNodeRequest, ZOSVersion]('tfgrid.ZOSSystemVersion', [ + request, + ], t.timeout)! +} + +pub fn (mut t TFGridClient) zos_deployment_deploy(request ZOSNodeRequest) ! { + t.client.send_json_rpc[[]ZOSNodeRequest, string]('tfgrid.ZOSDeploymentDeploy', [ + request, + ], t.timeout)! +} + +pub fn (mut t TFGridClient) zos_deployment_update(request ZOSNodeRequest) ! { + t.client.send_json_rpc[[]ZOSNodeRequest, string]('tfgrid.ZOSDeploymentUpdate', [ + request, + ], t.timeout)! +} + +pub fn (mut t TFGridClient) zos_deployment_changes(request ZOSNodeRequest) !Workload { + return t.client.send_json_rpc[[]ZOSNodeRequest, Workload]('tfgrid.ZOSDeploymentChanges', [ + request, + ], t.timeout)! +} + +pub fn (mut t TFGridClient) zos_deployment_get(request ZOSNodeRequest) !Deployment { + return t.client.send_json_rpc[[]ZOSNodeRequest, Deployment]('tfgrid.ZOSDeploymentGet', [ + request, + ], t.timeout)! +} + +pub fn (mut t TFGridClient) zos_deployment_delete(request ZOSNodeRequest) ! { + t.client.send_json_rpc[[]ZOSNodeRequest, string]('tfgrid.ZOSDeploymentDelete', [ + request, + ], t.timeout)! +} diff --git a/web3gw/examples/nostr/chat_consumer.v b/web3gw/examples/nostr/chat_consumer.v index e02710e21..805cc23bf 100644 --- a/web3gw/examples/nostr/chat_consumer.v +++ b/web3gw/examples/nostr/chat_consumer.v @@ -31,7 +31,7 @@ fn subscribe_messages(mut client RpcWsClient, mut logger log.Logger, secret stri logger.info('Nostr: Public Key: ${public_key}') nostr_client.connect_to_relay('https://nostr01.grid.tf/')! - nostr_client.subscribe_to_direct_messages()! + nostr_client.subscribe_direct_messages()! for { time.sleep(5 * time.second) diff --git a/web3gw/examples/nostr/stalls.v b/web3gw/examples/nostr/stalls.v index dd598040f..c73c8a0e4 100644 --- a/web3gw/examples/nostr/stalls.v +++ b/web3gw/examples/nostr/stalls.v @@ -29,8 +29,8 @@ fn create_stall_and_product(mut client RpcWsClient, mut logger log.Logger, secre nostr_client.connect_to_relay('https://nostr01.grid.tf/')! - nostr_client.subscribe_to_stall_creation()! - nostr_client.subscribe_to_product_creation()! + nostr_client.subscribe_stall_creation()! + nostr_client.subscribe_product_creation()! stall := nostr.Stall{ id: 'stall1' diff --git a/web3gw/examples/stellar/balance.v b/web3gw/examples/stellar/balance.v index 2079006f1..5fb9a01e9 100644 --- a/web3gw/examples/stellar/balance.v +++ b/web3gw/examples/stellar/balance.v @@ -15,7 +15,7 @@ fn execute_rpcs(mut client RpcWsClient, mut logger log.Logger, secret string, ne stellar_client.load(secret: secret, network: network)! - balance := stellar_client.balance(account)! + balance := stellar_client.balance(address: account)! logger.info('Balance: ${balance}') } diff --git a/web3gw/examples/stellar/swap.v b/web3gw/examples/stellar/swap.v index 210eee5ad..aac4630d2 100644 --- a/web3gw/examples/stellar/swap.v +++ b/web3gw/examples/stellar/swap.v @@ -17,12 +17,12 @@ fn execute_rpcs(mut client RpcWsClient, mut logger log.Logger, secret string, ne account := stellar_client.address()! - mut balance := stellar_client.balance(account)! + mut balance := stellar_client.balance(address: account)! logger.info('Balance: ${balance}') stellar_client.swap(amount: amount, source_asset: source, destination_asset: destination)! - balance = stellar_client.balance(account)! + balance = stellar_client.balance(address: account)! logger.info('Balance: ${balance}') } diff --git a/web3gw/examples/tfgrid/k8s.v b/web3gw/examples/tfgrid/k8s.v index 98599c448..232d24ab2 100644 --- a/web3gw/examples/tfgrid/k8s.v +++ b/web3gw/examples/tfgrid/k8s.v @@ -1,6 +1,6 @@ module main -import threefoldtech.web3gw.tfgrid { AddK8sWorker, GetK8sParams, K8sCluster, K8sClusterResult, K8sNode, RemoveK8sWorker, TFGridClient } +import threefoldtech.web3gw.tfgrid {K8sCluster, K8sNode, TFGridClient } import log { Logger } import flag { FlagParser } import os @@ -11,7 +11,7 @@ const ( default_server_address = 'ws://127.0.0.1:8080' ) -fn deploy_k8s(mut fp FlagParser, mut t TFGridClient) !K8sClusterResult { +fn deploy_k8s(mut fp FlagParser, mut t TFGridClient) !K8sCluster { fp.usage_example('deploy [options]') name := fp.string_opt('name', `n`, 'Name of the cluster')! @@ -54,19 +54,16 @@ fn deploy_k8s(mut fp FlagParser, mut t TFGridClient) !K8sClusterResult { workers: workers } - return t.k8s_deploy(cluster)! + return t.deploy_k8s_cluster(cluster)! } -fn get_k8s(mut fp FlagParser, mut t TFGridClient) !K8sClusterResult { +fn get_k8s(mut fp FlagParser, mut t TFGridClient) !K8sCluster { fp.usage_example('get [options]') name := fp.string_opt('name', `n`, 'Name of the clusetr')! _ := fp.finalize()! - return t.k8s_get(GetK8sParams{ - cluster_name: name - master_name: 'master' - })! + return t.get_k8s_cluster(name)! } fn delete_k8s(mut fp FlagParser, mut t TFGridClient) ! { @@ -75,10 +72,10 @@ fn delete_k8s(mut fp FlagParser, mut t TFGridClient) ! { name := fp.string_opt('name', `n`, 'Name of the cluster')! _ := fp.finalize()! - return t.k8s_delete(name) + return t.cancel_k8s_cluster(name) } -fn add_k8s_worker(mut fp FlagParser, mut t TFGridClient) !K8sClusterResult { +fn add_k8s_worker(mut fp FlagParser, mut t TFGridClient) !K8sCluster { fp.usage_example('add [options]') name := fp.string_opt('name', `n`, 'Name of the cluster')! @@ -98,25 +95,23 @@ fn add_k8s_worker(mut fp FlagParser, mut t TFGridClient) !K8sClusterResult { public_ip: public_ip } - return t.k8s_add_worker(AddK8sWorker{ + return t.add_worker_to_k8s_cluster( cluster_name: name - master_name: 'master' worker: worker - })! + )! } -fn remove_k8s_worker(mut fp FlagParser, mut t TFGridClient) !K8sClusterResult { +fn remove_k8s_worker(mut fp FlagParser, mut t TFGridClient) !K8sCluster { fp.usage_example('remove [options]') name := fp.string_opt('name', `n`, 'Name of the clusetr')! worker_name := fp.string_opt('worker_name', `w`, 'Name of the worker to remove')! _ := fp.finalize()! - return t.k8s_remove_worker(RemoveK8sWorker{ + return t.remove_worker_from_k8s_cluster( cluster_name: name - master_name: 'master' worker_name: worker_name - })! + )! } fn main() { @@ -152,7 +147,7 @@ fn main() { mut tfgrid_client := tfgrid.new(mut myclient) - tfgrid_client.load(tfgrid.Credentials{ + tfgrid_client.load(tfgrid.Load{ mnemonic: mnemonic network: network })! diff --git a/web3gw/examples/tfgrid/machine_with_qsfs.v b/web3gw/examples/tfgrid/machine_with_qsfs.v index a0fa3eb9f..62bfb7fcb 100644 --- a/web3gw/examples/tfgrid/machine_with_qsfs.v +++ b/web3gw/examples/tfgrid/machine_with_qsfs.v @@ -37,9 +37,9 @@ pub: } fn deploy_machine_with_qsfs(mut client tfgrid.TFGridClient, machine_with_qsfs MachineWithQSFS) !MachineWithQSFSResult { - mut zdbs := []tfgrid.ZDBResult{} + mut zdbs := []tfgrid.ZDBDeployment{} for i in 0 .. machine_with_qsfs.expected_shards { - zdb_seq := client.zdb_deploy(tfgrid.ZDB{ + zdb_seq := client.deploy_zdb(tfgrid.ZDBDeployment{ name: generate_zdb_name(machine_with_qsfs.name, 'seq', i) password: machine_with_qsfs.zdb_password size: machine_with_qsfs.zdb_size @@ -50,7 +50,7 @@ fn deploy_machine_with_qsfs(mut client tfgrid.TFGridClient, machine_with_qsfs Ma } zdbs << zdb_seq - zdb_user := client.zdb_deploy(tfgrid.ZDB{ + zdb_user := client.deploy_zdb(tfgrid.ZDBDeployment{ name: generate_zdb_name(machine_with_qsfs.name, 'user', i) password: machine_with_qsfs.zdb_password size: machine_with_qsfs.zdb_size @@ -83,66 +83,54 @@ fn deploy_machine_with_qsfs(mut client tfgrid.TFGridClient, machine_with_qsfs Ma } } - machines_model := client.machines_deploy(tfgrid.MachinesModel{ + machines_model := client.deploy_vm(tfgrid.DeployVM{ name: machine_with_qsfs.name - network: tfgrid.Network{ - add_wireguard_access: false + add_wireguard_access: false + farm_id: machine_with_qsfs.farm_id + cpu: machine_with_qsfs.cpu + memory: machine_with_qsfs.memory + rootfs_size: machine_with_qsfs.rootfs_size + env_vars: { + 'SSH_KEY': machine_with_qsfs.ssh_key } - machines: [ - tfgrid.Machine{ - name: 'vm1' - farm_id: machine_with_qsfs.farm_id - cpu: machine_with_qsfs.cpu - memory: machine_with_qsfs.memory - rootfs_size: machine_with_qsfs.rootfs_size - env_vars: { - 'SSH_KEY': machine_with_qsfs.ssh_key + public_ip: machine_with_qsfs.public_ipv4 + planetary: true + qsfss: [ + tfgrid.QSFS{ + mountpoint: '/qsfs' + encryption_key: machine_with_qsfs.encryption_key + cache: machine_with_qsfs.cache + minimal_shards: machine_with_qsfs.minimal_shards + expected_shards: machine_with_qsfs.expected_shards + redundant_groups: machine_with_qsfs.redundant_groups + redundant_nodes: machine_with_qsfs.redundant_nodes + encryption_algorithm: machine_with_qsfs.encryption_algorithm + compression_algorithm: machine_with_qsfs.compression_algorithm + metadata: tfgrid.Metadata{ + type_: machine_with_qsfs.metadata_type + prefix: machine_with_qsfs.metadata_prefix + encryption_algorithm: machine_with_qsfs.metadata_encryption_algorithm + encryption_key: machine_with_qsfs.encryption_key + backends: metadata_backends } - public_ip: machine_with_qsfs.public_ipv4 - planetary: true - qsfss: [ - tfgrid.QSFS{ - mountpoint: '/qsfs' - encryption_key: machine_with_qsfs.encryption_key - cache: machine_with_qsfs.cache - minimal_shards: machine_with_qsfs.minimal_shards - expected_shards: machine_with_qsfs.expected_shards - redundant_groups: machine_with_qsfs.redundant_groups - redundant_nodes: machine_with_qsfs.redundant_nodes - encryption_algorithm: machine_with_qsfs.encryption_algorithm - compression_algorithm: machine_with_qsfs.compression_algorithm - metadata: tfgrid.Metadata{ - type_: machine_with_qsfs.metadata_type - prefix: machine_with_qsfs.metadata_prefix - encryption_algorithm: machine_with_qsfs.metadata_encryption_algorithm - encryption_key: machine_with_qsfs.encryption_key - backends: metadata_backends - } - description: machine_with_qsfs.description - max_zdb_data_dir_size: machine_with_qsfs.max_zdb_data_dir_size - groups: [tfgrid.Group{ - backends: groups_backends - }] - }, - ] + description: machine_with_qsfs.description + max_zdb_data_dir_size: machine_with_qsfs.max_zdb_data_dir_size + groups: [tfgrid.Group{ + backends: groups_backends + }] }, ] }) or { - client.machines_delete(machine_with_qsfs.name)! + client.cancel_vm_deployment(machine_with_qsfs.name)! return error('failed to deploy machine: ${err}') } - if machines_model.machines.len == 0 { - delete_machine_with_qsfs(mut client, machine_with_qsfs.name)! - return error('0 machines were found after deployment') - } - - if machines_model.machines[0].qsfss.len == 0 { + if machines_model.qsfss.len == 0 { delete_machine_with_qsfs(mut client, machine_with_qsfs.name)! return error('0 qsfss were found after deployment') } - machine := machines_model.machines[0] + machine := machines_model return MachineWithQSFSResult{ name: machine_with_qsfs.name ygg_ip: machine.ygg_ip @@ -153,40 +141,32 @@ fn deploy_machine_with_qsfs(mut client tfgrid.TFGridClient, machine_with_qsfs Ma fn delete_qsfs_zdbs(mut client tfgrid.TFGridClient, machine_with_qsfs_name string, count u32) ! { for i in 0 .. count { - client.zdb_delete(generate_zdb_name(machine_with_qsfs_name, 'seq', i))! - client.zdb_delete(generate_zdb_name(machine_with_qsfs_name, 'user', i))! + client.cancel_zdb_deployment(generate_zdb_name(machine_with_qsfs_name, 'seq', i))! + client.cancel_zdb_deployment(generate_zdb_name(machine_with_qsfs_name, 'user', i))! } } fn delete_machine_with_qsfs(mut client tfgrid.TFGridClient, machine_with_qsfs_name string) ! { // the zdbs must be deleted first - machines_model := client.machines_get(machine_with_qsfs_name)! + machines_model := client.get_vm_deployment(machine_with_qsfs_name)! - if machines_model.machines.len == 0 { - return error('no machine was found') - } - - if machines_model.machines[0].qsfss.len == 0 { + if machines_model.qsfss.len == 0 { return error('no qsfs was found') } - delete_qsfs_zdbs(mut client, machine_with_qsfs_name, machines_model.machines[0].qsfss[0].expected_shards)! + delete_qsfs_zdbs(mut client, machine_with_qsfs_name, machines_model.qsfss[0].expected_shards)! - client.machines_delete(machine_with_qsfs_name)! + client.cancel_vm_deployment(machine_with_qsfs_name)! } fn get_machine_with_qsfs(mut client tfgrid.TFGridClient, machine_with_qsfs_name string) !MachineWithQSFSResult { - machines_model := client.machines_get(machine_with_qsfs_name)! - - if machines_model.machines.len == 0 { - return error('no machine was found') - } + machines_model := client.get_vm_deployment(machine_with_qsfs_name)! - if machines_model.machines[0].qsfss.len == 0 { + if machines_model.qsfss.len == 0 { return error('no qsfs was found') } - machine := machines_model.machines[0] + machine := machines_model return MachineWithQSFSResult{ name: machine_with_qsfs_name ygg_ip: machine.ygg_ip diff --git a/web3gw/examples/tfgrid/machines.v b/web3gw/examples/tfgrid/machines.v index 1773bab20..138350f16 100644 --- a/web3gw/examples/tfgrid/machines.v +++ b/web3gw/examples/tfgrid/machines.v @@ -13,80 +13,73 @@ const ( fn run_machines_ops(mut client tfgrid.TFGridClient, mut logger log.Logger) ! { model_name := 'testMachinesOps' - res := client.machines_deploy(tfgrid.MachinesModel{ + res := client.deploy_vm(tfgrid.DeployVM{ name: model_name - network: tfgrid.Network{ - add_wireguard_access: false + add_wireguard_access: false + cpu: 2 + memory: 2048 + rootfs_size: 1024 + env_vars: { + 'SSH_KEY': 'ssh-rsa ...' } - machines: [ - tfgrid.Machine{ - name: 'vm1' - cpu: 2 - memory: 2048 - rootfs_size: 1024 - env_vars: { - 'SSH_KEY': 'ssh-rsa ...' - } - disks: [tfgrid.Disk{ - size: 10 - mountpoint: '/mnt/disk1' - }] - }, - ] - metadata: 'metadata1' + disks: [tfgrid.Disk{ + size: 10 + mountpoint: '/mnt/disk1' + }] description: 'description' })! logger.info('${res}') defer { - client.machines_delete(model_name) or { + client.cancel_vm_deployment(model_name) or { logger.error('failed while deleting machines: ${err}') } } - add_res := client.machines_add(tfgrid.AddMachine{ - model_name: model_name - machine: tfgrid.Machine{ - name: 'vm3' - cpu: 2 - memory: 2048 - rootfs_size: 1024 - env_vars: { - 'SSH_KEY': 'ssh-rsa ...' - } - disks: [tfgrid.Disk{ - size: 10 - mountpoint: '/mnt/disk1' - }] - } - })! - logger.info('${add_res}') - - add_res2 := client.machines_add(tfgrid.AddMachine{ - model_name: model_name - machine: tfgrid.Machine{ - name: 'vm10' - cpu: 2 - memory: 2048 - rootfs_size: 1024 - env_vars: { - 'SSH_KEY': 'ssh-rsa ...' - } - disks: [tfgrid.Disk{ - size: 10 - mountpoint: '/mnt/disk1' - }] - } - })! - logger.info('${add_res2}') - - remove_res := client.machines_remove(tfgrid.RemoveMachine{ - model_name: model_name - machine_name: 'vm3' - })! - logger.info('${remove_res}') - - res_3 := client.machines_get(model_name)! + //@TODO: is this operation still supported? + // add_res := client.machines_add(tfgrid.AddMachine{ + // model_name: model_name + // machine: tfgrid.Machine{ + // name: 'vm3' + // cpu: 2 + // memory: 2048 + // rootfs_size: 1024 + // env_vars: { + // 'SSH_KEY': 'ssh-rsa ...' + // } + // disks: [tfgrid.Disk{ + // size: 10 + // mountpoint: '/mnt/disk1' + // }] + // } + // })! + // logger.info('${add_res}') + + // add_res2 := client.machines_add(tfgrid.AddMachine{ + // model_name: model_name + // machine: tfgrid.Machine{ + // name: 'vm10' + // cpu: 2 + // memory: 2048 + // rootfs_size: 1024 + // env_vars: { + // 'SSH_KEY': 'ssh-rsa ...' + // } + // disks: [tfgrid.Disk{ + // size: 10 + // mountpoint: '/mnt/disk1' + // }] + // } + // })! + // logger.info('${add_res2}') + + // remove_res := client.machines_remove(tfgrid.RemoveMachine{ + // model_name: model_name + // machine_name: 'vm3' + // })! + // logger.info('${remove_res}') + + res_3 := client.get_vm_deployment(model_name)! logger.info('${res_3}') } @@ -121,7 +114,7 @@ fn main() { mut tfgrid_client := tfgrid.new(mut myclient) - tfgrid_client.load(tfgrid.Credentials{ + tfgrid_client.load(tfgrid.Load{ mnemonic: mnemonic network: network })! diff --git a/web3gw/examples/tfgrid/zdb.v b/web3gw/examples/tfgrid/zdb.v index 2a2d7351c..2746b1aa4 100644 --- a/web3gw/examples/tfgrid/zdb.v +++ b/web3gw/examples/tfgrid/zdb.v @@ -1,6 +1,6 @@ module main -import threefoldtech.web3gw.tfgrid { TFGridClient, ZDB, ZDBResult } +import threefoldtech.web3gw.tfgrid { TFGridClient, ZDBDeployment } import log { Logger } import flag { FlagParser } import os @@ -11,7 +11,7 @@ const ( default_server_address = 'ws://127.0.0.1:8080' ) -fn deploy_zdb(mut fp FlagParser, mut t TFGridClient) !ZDBResult { +fn deploy_zdb(mut fp FlagParser, mut t TFGridClient) !ZDBDeployment { fp.usage_example('deploy [options]') name := fp.string('name', `z`, rand.string(6), 'zdb name') @@ -22,7 +22,7 @@ fn deploy_zdb(mut fp FlagParser, mut t TFGridClient) !ZDBResult { mode := fp.string('mode', `d`, 'user', 'Mode of the ZDB') _ := fp.finalize()! - zdb := ZDB{ + zdb := ZDBDeployment{ node_id: u32(node_id) name: name password: password @@ -31,16 +31,16 @@ fn deploy_zdb(mut fp FlagParser, mut t TFGridClient) !ZDBResult { mode: mode } - return t.zdb_deploy(zdb)! + return t.deploy_zdb(zdb)! } -fn get_zdb(mut fp FlagParser, mut t TFGridClient) !ZDBResult { +fn get_zdb(mut fp FlagParser, mut t TFGridClient) !ZDBDeployment { fp.usage_example('get [options]') name := fp.string_opt('name', `z`, 'Name of the ZDB')! _ := fp.finalize()! - return t.zdb_get(name)! + return t.get_zdb_deployment(name)! } fn delete_zdb(mut fp FlagParser, mut t TFGridClient) ! { @@ -49,7 +49,7 @@ fn delete_zdb(mut fp FlagParser, mut t TFGridClient) ! { name := fp.string_opt('name', `v`, 'Name of the ZDB')! _ := fp.finalize()! - return t.zdb_delete(name) + return t.cancel_zdb_deployment(name) } fn main() { @@ -85,7 +85,7 @@ fn main() { mut tfgrid_client := tfgrid.new(mut myclient) - tfgrid_client.load(tfgrid.Credentials{ + tfgrid_client.load(tfgrid.Load{ mnemonic: mnemonic network: network })! diff --git a/web3gw/examples/tfgrid/zos_calls.v b/web3gw/examples/tfgrid/zos_calls.v index 894c20138..c3deca522 100644 --- a/web3gw/examples/tfgrid/zos_calls.v +++ b/web3gw/examples/tfgrid/zos_calls.v @@ -5,6 +5,7 @@ import threefoldtech.web3gw.tfgrid import flag import log import os +import json const ( default_server_address = 'ws://127.0.0.1:8080' @@ -60,7 +61,6 @@ fn run_zos_node_calls(mut client tfgrid.TFGridClient, mut logger log.Logger) ! { tfgrid.Workload{ version: 0 name: 'wl12' - workload_type: tfgrid.zdb_workload_type data: tfgrid.ZDBWorkload{ password: '' mode: 'seq' @@ -75,7 +75,7 @@ fn run_zos_node_calls(mut client tfgrid.TFGridClient, mut logger log.Logger) ! { request = tfgrid.ZOSNodeRequest{ node_id: 11 - data: deploy_deployment + data: json.encode(deploy_deployment).u64() } client.zos_deployment_deploy(request)! @@ -101,7 +101,6 @@ fn run_zos_node_calls(mut client tfgrid.TFGridClient, mut logger log.Logger) ! { tfgrid.Workload{ version: 2 name: 'wl1234' - workload_type: tfgrid.zdb_workload_type data: tfgrid.ZDBWorkload{ password: '' mode: 'seq' @@ -115,7 +114,7 @@ fn run_zos_node_calls(mut client tfgrid.TFGridClient, mut logger log.Logger) ! { } request = tfgrid.ZOSNodeRequest{ node_id: 28 - data: update_deployment + data: json.encode(update_deployment).u64() } client.zos_deployment_update(request)! @@ -177,7 +176,7 @@ fn main() { mut tfgrid_client := tfgrid.new(mut myclient) - tfgrid_client.load(tfgrid.Credentials{ + tfgrid_client.load(tfgrid.Load{ mnemonic: mnemonic network: network })!