Skip to content

Commit

Permalink
fix tfgrid vm clients and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Chaddad committed Aug 17, 2023
1 parent 269e748 commit e046037
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 47 deletions.
12 changes: 6 additions & 6 deletions web3gw/client/tfgrid/tfgrid.v
Original file line number Diff line number Diff line change
Expand Up @@ -136,44 +136,44 @@ pub fn (mut t TFGridClient) cancel_zdb_deployment(name string) ! {

// Deploys a gateway name given the name, the id of the node and the backends where the gateway should point to
pub fn (mut t TFGridClient) deploy_gateway_name(args GatewayName) !GatewayName {
return t.client.send_json_rpc[[]GatewayName, GatewayName]('tfgrid.DeployGatewayName',
return t.client.send_json_rpc[[]GatewayName, GatewayName]('tfgrid.GatewayNameDeploy',
[
args,
], t.timeout)!
}

// Retrieves information about the gateway name (backends, node, etc)
pub fn (mut t TFGridClient) get_gateway_name(name string) !GatewayName {
return t.client.send_json_rpc[[]string, GatewayName]('tfgrid.GetGatewayName', [
return t.client.send_json_rpc[[]string, GatewayName]('tfgrid.GatewayNameGet', [
name,
], t.timeout)!
}

// Cancels the gateway name
pub fn (mut t TFGridClient) cancel_gateway_name(name string) ! {
_ := t.client.send_json_rpc[[]string, string]('tfgrid.CancelGatewayName', [
_ := t.client.send_json_rpc[[]string, string]('tfgrid.GatewayNameDelete', [
name,
], t.timeout)!
}

// Adds a fully qualified domain name to the specified node and returns some computed information
pub fn (mut t TFGridClient) deploy_gateway_fqdn(args GatewayFQDN) !GatewayFQDN {
return t.client.send_json_rpc[[]GatewayFQDN, GatewayFQDN]('tfgrid.DeployGatewayFQDN',
return t.client.send_json_rpc[[]GatewayFQDN, GatewayFQDN]('tfgrid.GatewayFQDNDeploy',
[
args,
], t.timeout)!
}

// Retrieves information about the fully qualified domain name
pub fn (mut t TFGridClient) get_gateway_fqdn(name string) !GatewayFQDN {
return t.client.send_json_rpc[[]string, GatewayFQDN]('tfgrid.GetGatewayFQDN', [
return t.client.send_json_rpc[[]string, GatewayFQDN]('tfgrid.GatewayFQDNGet', [
name,
], t.timeout)!
}

// Cancels the fully qualified domain name specified in the arguments
pub fn (mut t TFGridClient) cancel_gateway_fqdn(name string) ! {
_ := t.client.send_json_rpc[[]string, string]('tfgrid.CancelGatewayFQDN', [
_ := t.client.send_json_rpc[[]string, string]('tfgrid.GatewayFQDNDelete', [
name,
], t.timeout)!
}
Expand Down
14 changes: 7 additions & 7 deletions web3gw/examples/tfgrid/gateway_fqdn.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module main

import threefoldtech.web3gw.tfgrid { GatewayFQDN, GatewayFQDNResult, TFGridClient }
import threefoldtech.web3gw.tfgrid { GatewayFQDN, TFGridClient }
import log { Logger }
import flag { FlagParser }
import os
Expand All @@ -10,7 +10,7 @@ const (
default_server_address = 'ws://127.0.0.1:8080'
)

fn deploy_gateway_fqdn(mut fp FlagParser, mut t TFGridClient) !GatewayFQDNResult {
fn deploy_gateway_fqdn(mut fp FlagParser, mut t TFGridClient) !GatewayFQDN {
fp.usage_example('deploy [options]')

name := fp.string_opt('name', `n`, 'Name of the gateway instance')!
Expand All @@ -20,7 +20,7 @@ fn deploy_gateway_fqdn(mut fp FlagParser, mut t TFGridClient) !GatewayFQDNResult
fqdn := fp.string_opt('fqdn', `f`, 'FQDN of the gateway')!
_ := fp.finalize()!

return t.gateways_deploy_fqdn(GatewayFQDN{
return t.deploy_gateway_fqdn(GatewayFQDN{
name: name
node_id: u32(node_id)
tls_passthrough: tls_passthrough
Expand All @@ -29,13 +29,13 @@ fn deploy_gateway_fqdn(mut fp FlagParser, mut t TFGridClient) !GatewayFQDNResult
})!
}

fn get_gateway_fqdn(mut fp FlagParser, mut t TFGridClient) !GatewayFQDNResult {
fn get_gateway_fqdn(mut fp FlagParser, mut t TFGridClient) !GatewayFQDN {
fp.usage_example('get [options]')

name := fp.string_opt('name', `n`, 'Name of the gateway instance')!
_ := fp.finalize()!

return t.gateways_get_fqdn(name)!
return t.get_gateway_fqdn(name)!
}

fn delete_gateway_fqdn(mut fp FlagParser, mut t TFGridClient) ! {
Expand All @@ -44,7 +44,7 @@ fn delete_gateway_fqdn(mut fp FlagParser, mut t TFGridClient) ! {
name := fp.string_opt('name', `n`, 'Name of the gateway instance')!
_ := fp.finalize()!

return t.gateways_delete_fqdn(name)
return t.cancel_gateway_fqdn(name)
}

fn main() {
Expand Down Expand Up @@ -83,7 +83,7 @@ fn main() {

mut tfgrid_client := tfgrid.new(mut myclient)

tfgrid_client.load(tfgrid.Credentials{
tfgrid_client.load(tfgrid.Load{
mnemonic: mnemonic
network: network
})!
Expand Down
14 changes: 7 additions & 7 deletions web3gw/examples/tfgrid/gateway_name.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module main

import threefoldtech.web3gw.tfgrid { GatewayName, GatewayNameResult, TFGridClient }
import threefoldtech.web3gw.tfgrid { GatewayName, TFGridClient }
import log { Logger }
import flag { FlagParser }
import os
Expand All @@ -10,7 +10,7 @@ const (
default_server_address = 'ws://127.0.0.1:8080'
)

fn deploy_gateway_name(mut fp FlagParser, mut t TFGridClient) !GatewayNameResult {
fn deploy_gateway_name(mut fp FlagParser, mut t TFGridClient) !GatewayName {
fp.usage_example('deploy [options]')

name := fp.string_opt('name', `n`, 'Name of the gateway instance')!
Expand All @@ -19,21 +19,21 @@ fn deploy_gateway_name(mut fp FlagParser, mut t TFGridClient) !GatewayNameResult
backend := fp.string_opt('backend', `b`, 'Backend of the gateway')!
_ := fp.finalize()!

return t.gateways_deploy_name(GatewayName{
return t.deploy_gateway_name(GatewayName{
name: name
node_id: u32(node_id)
tls_passthrough: tls_passthrough
backends: [backend]
})!
}

fn get_gateway_name(mut fp FlagParser, mut t TFGridClient) !GatewayNameResult {
fn get_gateway_name(mut fp FlagParser, mut t TFGridClient) !GatewayName {
fp.usage_example('get [options]')

name := fp.string_opt('name', `n`, 'Name of the gateway instance')!
_ := fp.finalize()!

return t.gateways_get_name(name)!
return t.get_gateway_name(name)!
}

fn delete_gateway_name(mut fp FlagParser, mut t TFGridClient) ! {
Expand All @@ -42,7 +42,7 @@ fn delete_gateway_name(mut fp FlagParser, mut t TFGridClient) ! {
name := fp.string_opt('name', `n`, 'Name of the gateway instance')!
_ := fp.finalize()!

return t.gateways_delete_name(name)
return t.cancel_gateway_name(name)
}

fn main() {
Expand Down Expand Up @@ -78,7 +78,7 @@ fn main() {

mut tfgrid_client := tfgrid.new(mut myclient)

tfgrid_client.load(tfgrid.Credentials{
tfgrid_client.load(tfgrid.Load{
mnemonic: mnemonic
network: network
})!
Expand Down
44 changes: 17 additions & 27 deletions web3gw/examples/tfgrid/vm.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module main

import threefoldtech.web3gw.tfgrid { RemoveVM, TFGridClient, VM, VMResult }
import threefoldtech.web3gw.tfgrid { NetworkDeployment, TFGridClient, DeployVM, VMDeployment }
import log { Logger }
import flag { FlagParser }
import os
Expand All @@ -11,68 +11,58 @@ const (
default_server_address = 'ws://127.0.0.1:8080'
)

fn deploy_vm(mut fp FlagParser, mut t TFGridClient) !VMResult {
fn deploy_vm(mut fp FlagParser, mut t TFGridClient) !VMDeployment {
fp.usage_example('deploy [options]')

name := fp.string('vm_name', `m`, rand.string(6), 'VM name')
network := fp.string_opt('vm_network', `v`, 'Name of the VM network')!
farm_id := fp.int('farm_id', `f`, 0, 'Farm ID to deploy on')
capacity := fp.string('capacity', `c`, 'medium', 'Capacity of the instance')
times := fp.int('times', `t`, 1, 'The number of vms to deploy')
disk_size := fp.int('disk_size', `d`, 0, 'Size of disk the will be mounted on each vm')
gateway := fp.bool('gateway', `g`, false, 'True to add a gateway for each vm')
wg := fp.bool('wg', `w`, false, 'True to add a wireguard access point to the network')
add_public_ipv4 := fp.bool('add_public_ipv4', `4`, false, 'True to add a public ipv4 to each vm')
add_public_ipv6 := fp.bool('add_public_ipv6', `6`, false, 'True to add a public ipv6 to each vm')
ssh_key := fp.string('ssh', `s`, '', 'Public SSH Key to access the instance')
_ := fp.finalize()!

vm := VM{
vm := DeployVM{
name: name
network: network
farm_id: u32(farm_id)
capacity: capacity
ssh_key: ssh_key
times: u32(times)
disk_size: u32(disk_size)
rootfs_size: u64(disk_size)
gateway: gateway
add_wireguard_access: wg
add_public_ipv4: add_public_ipv4
add_public_ipv6: add_public_ipv6
}

return t.deploy_vm(vm)!
}

fn get_vm(mut fp FlagParser, mut t TFGridClient) !VMResult {
fn get_vm(mut fp FlagParser, mut t TFGridClient) !VMDeployment {
fp.usage_example('get [options]')

network := fp.string_opt('vm_network', `v`, 'Name of the VM network')!
vm := fp.string_opt('vm_name', `v`, 'Name of the VM')!
_ := fp.finalize()!

return t.get_vm(network)!
return t.get_vm_deployment(vm)!
}

fn delete_vm(mut fp FlagParser, mut t TFGridClient) ! {
fp.usage_example('delete [options]')

network := fp.string_opt('vm_network', `v`, 'Name of the VM network')!
vm_name := fp.string_opt('vm_name', `v`, 'Name of the VM to be deleted')!

_ := fp.finalize()!

return t.delete_vm(network)
t.cancel_vm_deployment(vm_name)!
}

fn remove_vm(mut fp FlagParser, mut t TFGridClient) !VMResult {
fn remove_vm(mut fp FlagParser, mut t TFGridClient)!NetworkDeployment {
fp.usage_example('remove [options]')

vm_name := fp.string_opt('vm_name', `v`, 'Name of the VM to be removed')!
network := fp.string_opt('vm_network', `v`, 'Name of the VM network')!
vm_name := fp.string_opt('vm', `v`, 'Name of the VM to be removed')!

_ := fp.finalize()!

return t.remove_vm(RemoveVM{
return t.remove_vm_from_network_deployment(
network: network
vm_name: vm_name
})!
vm: vm_name
)!
}

fn main() {
Expand Down Expand Up @@ -108,7 +98,7 @@ fn main() {

mut tfgrid_client := tfgrid.new(mut myclient)

tfgrid_client.load(tfgrid.Credentials{
tfgrid_client.load(tfgrid.Load{
mnemonic: mnemonic
network: network
})!
Expand Down

0 comments on commit e046037

Please sign in to comment.