diff --git a/3bot/vgrid/examples/get_nodes_by_capacity.v b/3bot/vgrid/examples/get_nodes_by_capacity.v index 47305e2be..51f636138 100644 --- a/3bot/vgrid/examples/get_nodes_by_capacity.v +++ b/3bot/vgrid/examples/get_nodes_by_capacity.v @@ -1,86 +1,87 @@ -import threefoldtech.vgrid.gridproxy {TFGridNet} -import threefoldtech.vgrid.gridproxy.model {ResourceFilter, Node} +import threefoldtech.vgrid.gridproxy { TFGridNet } +import threefoldtech.vgrid.gridproxy.model { Node, ResourceFilter } import os +fn main() { + // Default value used in intializing the resources + mut resources_filter := ResourceFilter{} -fn main(){ - //Default value used in intializing the resources - mut resources_filter := ResourceFilter {} - - if "--help" in os.args { - println("This script to get nodes by available resources \n + if '--help' in os.args { + println('This script to get nodes by available resources \n --sru nodes selected should have a minumum value of free sru in GB (ssd resource unit) equal to this (optional) \n --hru nodes selected should have a minumum value of free hru in GB (hd resource unit) equal to this (optional) \n --mru nodes selected should have a minumum value of free mru in GB (memory resource unit) equal to this (optional) \n --ips nodes selected should have a minumum value of ips (ips in the farm of the node) equal to this (optional)\n --network one of (dev, test, qa, main) (optional)(default to `test`) \n --max-count maximum number of nodes to be selected (optional)(default to 0 which means no limit) \n - --cache enable cache (optional)(default to false") + --cache enable cache (optional)(default to false') return } - if "--sru" in os.args { - index_val := os.args.index("--sru") - resources_filter.free_sru_gb = os.args[index_val+1].u64() + if '--sru' in os.args { + index_val := os.args.index('--sru') + resources_filter.free_sru_gb = os.args[index_val + 1].u64() } - if "--ips" in os.args { - index_val := os.args.index("--ips") - resources_filter.free_ips = os.args[index_val+1].u64() + if '--ips' in os.args { + index_val := os.args.index('--ips') + resources_filter.free_ips = os.args[index_val + 1].u64() } - if "--hru" in os.args { - index_val := os.args.index("--hru") - resources_filter.free_hru_gb = os.args[index_val+1].u64() + if '--hru' in os.args { + index_val := os.args.index('--hru') + resources_filter.free_hru_gb = os.args[index_val + 1].u64() } - if "--mru" in os.args { - index_val := os.args.index("--mru") - resources_filter.free_mru_gb = os.args[index_val+1].u64() + if '--mru' in os.args { + index_val := os.args.index('--mru') + resources_filter.free_mru_gb = os.args[index_val + 1].u64() } - mut net := "test" - if "--net" in os.args { - index_val := os.args.index("--net") - net = os.args[index_val+1] + mut net := 'test' + if '--net' in os.args { + index_val := os.args.index('--net') + net = os.args[index_val + 1] } mut max_count := 0 - if "--max-count" in os.args { - index_val := os.args.index("--max-count") - max_count = os.args[index_val+1].int() + if '--max-count' in os.args { + index_val := os.args.index('--max-count') + max_count = os.args[index_val + 1].int() } mut cache := false - if "--cache" in os.args { + if '--cache' in os.args { cache = true } network := match net { - "dev" { + 'dev' { TFGridNet.dev } - "test" { + 'test' { TFGridNet.test } - "qa" { + 'qa' { TFGridNet.qa } - "main" { + 'main' { TFGridNet.main } else { - panic("network $net not supported") + panic('network ${net} not supported') } } - mut gp_client := gridproxy.get(network, cache) - nodes_iter := gp_client.get_nodes_has_resources(resources_filter) /* or { + mut gp_client := gridproxy.get(network, cache)! + nodes_iter := gp_client.get_nodes_has_resources(resources_filter) /* + or { println("got an error while getting nodes") println("error message : ${err.msg()}") println("error code : ${err.code()}") return - } */ - mut nodes_with_min_resources := []Node {} + }*/ + + mut nodes_with_min_resources := []Node{} // itereate over all availble pages on the server and get array of nodes for each page outer: for nodes in nodes_iter { // flatten the array of nodes into a single array @@ -91,10 +92,10 @@ fn main(){ } } } - println("found $nodes_with_min_resources.len nodes on ${net.to_upper()} network with following min resources:\n$resources_filter") + println('found ${nodes_with_min_resources.len} nodes on ${net.to_upper()} network with following min resources:\n${resources_filter}') if max_count > 0 { - println("Note: a limit of getting at most $max_count nodes was set") + println('Note: a limit of getting at most ${max_count} nodes was set') } - println("---------------------------------------") + println('---------------------------------------') println(nodes_with_min_resources) } diff --git a/3bot/vgrid/examples/get_nodes_by_city_country.v b/3bot/vgrid/examples/get_nodes_by_city_country.v index e840a8fb6..09a386bba 100644 --- a/3bot/vgrid/examples/get_nodes_by_city_country.v +++ b/3bot/vgrid/examples/get_nodes_by_city_country.v @@ -1,76 +1,75 @@ -import threefoldtech.vgrid.gridproxy {TFGridNet} -import threefoldtech.vgrid.gridproxy.model {NodeFilter, Node} +import threefoldtech.vgrid.gridproxy { TFGridNet } +import threefoldtech.vgrid.gridproxy.model { Node, NodeFilter } import os +fn main() { + // Default value used in intializing the resources + mut nodes_filter := NodeFilter{} -fn main(){ - //Default value used in intializing the resources - mut nodes_filter := NodeFilter {} - - if "--help" in os.args { - println("This script to get nodes by city or country or both \n + if '--help' in os.args { + println('This script to get nodes by city or country or both \n --city name of the city (optional) \n --country name of the country (optional) \n --network one of (dev, test, qa, main) (optional)(default to `test`) \n --max-count maximum number of nodes to be selected (optional)(default to 0 which means no limit) \n - --cache enable cache (optional)(default to false") + --cache enable cache (optional)(default to false') return } - if "--city" in os.args { - index_val:=os.args.index("--city") - nodes_filter.city = os.args[index_val+1].to_lower().title() // ensure that the city is in title case, which is the case in the database. - + if '--city' in os.args { + index_val := os.args.index('--city') + nodes_filter.city = os.args[index_val + 1].to_lower().title() // ensure that the city is in title case, which is the case in the database. } - if "--country" in os.args { - mut index_val:=os.args.index("--country") - nodes_filter.country = os.args[index_val+1].to_lower().title() // ensure that the country is in title case, which is the case in the database. - + if '--country' in os.args { + mut index_val := os.args.index('--country') + nodes_filter.country = os.args[index_val + 1].to_lower().title() // ensure that the country is in title case, which is the case in the database. } - mut net := "test" - if "--net" in os.args { - index_val := os.args.index("--net") - net = os.args[index_val+1] + mut net := 'test' + if '--net' in os.args { + index_val := os.args.index('--net') + net = os.args[index_val + 1] } mut max_count := 0 - if "--max-count" in os.args { - index_val := os.args.index("--max-count") - max_count = os.args[index_val+1].int() + if '--max-count' in os.args { + index_val := os.args.index('--max-count') + max_count = os.args[index_val + 1].int() } mut cache := false - if "--cache" in os.args { + if '--cache' in os.args { cache = true } network := match net { - "dev" { + 'dev' { TFGridNet.dev } - "test" { + 'test' { TFGridNet.test } - "qa" { + 'qa' { TFGridNet.qa } - "main" { + 'main' { TFGridNet.main } else { - panic("network $net not supported") + panic('network ${net} not supported') } } - mut gp_client := gridproxy.get(network, cache) - nodes_iter := gp_client.get_nodes_iterator(nodes_filter) /* or { + mut gp_client := gridproxy.get(network, cache)! + nodes_iter := gp_client.get_nodes_iterator(nodes_filter) /* + or { println("got an error while getting nodes") println("error message : ${err.msg()}") println("error code : ${err.code()}") return - } */ - mut nodes_by_city_country := []Node {} + }*/ + + mut nodes_by_city_country := []Node{} outer: for nodes in nodes_iter { for node in nodes { nodes_by_city_country << node @@ -79,7 +78,7 @@ fn main(){ } } } - println("found $nodes_by_city_country.len nodes on ${net.to_upper()} in country: $nodes_filter.country and city: $nodes_filter.city") - println("---------------------------------------") + println('found ${nodes_by_city_country.len} nodes on ${net.to_upper()} in country: ${nodes_filter.country} and city: ${nodes_filter.city}') + println('---------------------------------------') println(nodes_by_city_country) } diff --git a/3bot/vgrid/gridproxy/gridproxy_core.v b/3bot/vgrid/gridproxy/gridproxy_core.v index cd73fb087..e24142354 100644 --- a/3bot/vgrid/gridproxy/gridproxy_core.v +++ b/3bot/vgrid/gridproxy/gridproxy_core.v @@ -2,7 +2,7 @@ module gridproxy // client library for threefold gridproxy API. import json -import model {Contract, ContractFilter, Farm, FarmFilter, GridStat, Node, Node_, NodeFilter, ResourceFilter, StatFilter, Twin, TwinFilter, NodeIterator, FarmIterator, TwinIterator, ContractIterator } +import model { Contract, ContractFilter, ContractIterator, Farm, FarmFilter, FarmIterator, GridStat, Node, NodeFilter, NodeIterator, Node_, StatFilter, Twin, TwinFilter, TwinIterator } /* all errors returned by the gridproxy API or the client are wrapped in a standard `Error` object with two fields. @@ -34,12 +34,12 @@ const ( // * `node_id` (u64): node id. // // returns: `Node` or `Error`. -pub fn (mut c GridProxyClient) get_node_by_id(node_id u64) ?Node { +pub fn (mut c GridProxyClient) get_node_by_id(node_id u64) !Node { // needed to allow to use threads - mut http_client := c.http_client.clone() + mut http_client := c.http_client.clone()! - res := http_client.send(prefix: 'nodes/', id: '$node_id') or { - return error_with_code('http client error: $err.msg()', gridproxy.err_http_client) + res := http_client.send(prefix: 'nodes/', id: '${node_id}') or { + return error_with_code('http client error: ${err.msg()}', gridproxy.err_http_client) } if !res.is_ok() { @@ -51,7 +51,7 @@ pub fn (mut c GridProxyClient) get_node_by_id(node_id u64) ?Node { } node := json.decode(Node, res.data) or { - return error_with_code('error to get jsonstr for node data, json decode: node id: $node_id, data: $res.data', + return error_with_code('error to get jsonstr for node data, json decode: node id: ${node_id}, data: ${res.data}', gridproxy.err_json_parse) } return node @@ -62,12 +62,12 @@ pub fn (mut c GridProxyClient) get_node_by_id(node_id u64) ?Node { // * `node_id` (u64): node id. // // returns: `Node` or `Error`. -pub fn (mut c GridProxyClient) get_gateway_by_id(node_id u64) ?Node { +pub fn (mut c GridProxyClient) get_gateway_by_id(node_id u64) !Node { // needed to allow to use threads - mut http_client := c.http_client.clone() + mut http_client := c.http_client.clone()! - res := http_client.send(prefix: 'gateways/', id: '$node_id') or { - return error_with_code('http client error: $err.msg()', gridproxy.err_http_client) + res := http_client.send(prefix: 'gateways/', id: '${node_id}') or { + return error_with_code('http client error: ${err.msg()}', gridproxy.err_http_client) } if !res.is_ok() { @@ -79,7 +79,7 @@ pub fn (mut c GridProxyClient) get_gateway_by_id(node_id u64) ?Node { } node := json.decode(Node, res.data) or { - return error_with_code('error to get jsonstr for gateway data, json decode: gateway id: $node_id, data: $res.data', + return error_with_code('error to get jsonstr for gateway data, json decode: gateway id: ${node_id}, data: ${res.data}', gridproxy.err_json_parse) } return node @@ -108,12 +108,12 @@ pub fn (mut c GridProxyClient) get_gateway_by_id(node_id u64) ?Node { // * `farm_ids` ([]u64): List of farm ids. [optional]. // // returns: `[]Node` or `Error`. -pub fn (mut c GridProxyClient) get_nodes(params NodeFilter) ?[]Node { +pub fn (mut c GridProxyClient) get_nodes(params NodeFilter) ![]Node { // needed to allow to use threads - mut http_client := c.http_client.clone() + mut http_client := c.http_client.clone()! params_map := params.to_map() res := http_client.send(prefix: 'nodes/', params: params_map) or { - return error_with_code('http client error: $err.msg()', gridproxy.err_http_client) + return error_with_code('http client error: ${err.msg()}', gridproxy.err_http_client) } if !res.is_ok() { @@ -125,7 +125,7 @@ pub fn (mut c GridProxyClient) get_nodes(params NodeFilter) ?[]Node { } nodes_ := json.decode([]Node_, res.data) or { - return error_with_code('error to get jsonstr for node list data, json decode: node filter: $params_map, data: $res.data', + return error_with_code('error to get jsonstr for node list data, json decode: node filter: ${params_map}, data: ${res.data}', gridproxy.err_json_parse) } nodes := nodes_.map(it.with_nested_capacity()) @@ -155,12 +155,12 @@ pub fn (mut c GridProxyClient) get_nodes(params NodeFilter) ?[]Node { // * `farm_ids` ([]u64): List of farm ids. [optional]. // // returns: `[]Node` or `Error`. -pub fn (mut c GridProxyClient) get_gateways(params NodeFilter) ?[]Node { +pub fn (mut c GridProxyClient) get_gateways(params NodeFilter) ![]Node { // needed to allow to use threads - mut http_client := c.http_client.clone() + mut http_client := c.http_client.clone()! params_map := params.to_map() res := http_client.send(prefix: 'gateways/', params: params_map) or { - return error_with_code('http client error: $err.msg()', gridproxy.err_http_client) + return error_with_code('http client error: ${err.msg()}', gridproxy.err_http_client) } if !res.is_ok() { @@ -172,7 +172,7 @@ pub fn (mut c GridProxyClient) get_gateways(params NodeFilter) ?[]Node { } nodes_ := json.decode([]Node_, res.data) or { - return error_with_code('error to get jsonstr for gateways list data, json decode: gateway filter: $params_map, data: $res.data', + return error_with_code('error to get jsonstr for gateways list data, json decode: gateway filter: ${params_map}, data: ${res.data}', gridproxy.err_json_parse) } nodes := nodes_.map(it.with_nested_capacity()) @@ -184,9 +184,9 @@ pub fn (mut c GridProxyClient) get_gateways(params NodeFilter) ?[]Node { // * `status` (string): Node status filter, set to 'up' to get online nodes only.. [optional]. // // returns: `GridStat` or `Error`. -pub fn (mut c GridProxyClient) get_stats(filter StatFilter) ?GridStat { +pub fn (mut c GridProxyClient) get_stats(filter StatFilter) !GridStat { // needed to allow to use threads - mut http_client := c.http_client.clone() + mut http_client := c.http_client.clone()! mut params_map := map[string]string{} params_map['status'] = match filter.status { .all { '' } @@ -194,7 +194,7 @@ pub fn (mut c GridProxyClient) get_stats(filter StatFilter) ?GridStat { } res := http_client.send(prefix: 'stats/', params: params_map) or { - return error_with_code('http client error: $err.msg()', gridproxy.err_http_client) + return error_with_code('http client error: ${err.msg()}', gridproxy.err_http_client) } if !res.is_ok() { @@ -206,7 +206,7 @@ pub fn (mut c GridProxyClient) get_stats(filter StatFilter) ?GridStat { } stats := json.decode(GridStat, res.data) or { - return error_with_code('error to get jsonstr for grid stats data, json decode: stats filter: $params_map, data: $res.data', + return error_with_code('error to get jsonstr for grid stats data, json decode: stats filter: ${params_map}, data: ${res.data}', gridproxy.err_json_parse) } return stats @@ -221,12 +221,12 @@ pub fn (mut c GridProxyClient) get_stats(filter StatFilter) ?GridStat { // * `account_id` (string): account address. [optional]. // // returns: `[]Twin` or `Error`. -pub fn (mut c GridProxyClient) get_twins(params TwinFilter) ?[]Twin { +pub fn (mut c GridProxyClient) get_twins(params TwinFilter) ![]Twin { // needed to allow to use threads - mut http_client := c.http_client.clone() + mut http_client := c.http_client.clone()! params_map := params.to_map() res := http_client.send(prefix: 'twins/', params: params_map) or { - return error_with_code('http client error: $err.msg()', gridproxy.err_http_client) + return error_with_code('http client error: ${err.msg()}', gridproxy.err_http_client) } if !res.is_ok() { @@ -238,7 +238,7 @@ pub fn (mut c GridProxyClient) get_twins(params TwinFilter) ?[]Twin { } twins := json.decode([]Twin, res.data) or { - return error_with_code('error to get jsonstr for twin list data, json decode: twin filter: $params_map, data: $res.data', + return error_with_code('error to get jsonstr for twin list data, json decode: twin filter: ${params_map}, data: ${res.data}', gridproxy.err_json_parse) } return twins @@ -260,12 +260,12 @@ pub fn (mut c GridProxyClient) get_twins(params TwinFilter) ?[]Twin { // * `number_of_public_ips` (u64): Min number of public ips in the 'node' contract. [optional]. // // * returns: `[]Contract` or `Error`. -pub fn (mut c GridProxyClient) get_contracts(params ContractFilter) ?[]Contract { +pub fn (mut c GridProxyClient) get_contracts(params ContractFilter) ![]Contract { // needed to allow to use threads - mut http_client := c.http_client.clone() + mut http_client := c.http_client.clone()! params_map := params.to_map() res := http_client.send(prefix: 'contracts/', params: params_map) or { - return error_with_code('http client error: $err.msg()', gridproxy.err_http_client) + return error_with_code('http client error: ${err.msg()}', gridproxy.err_http_client) } if !res.is_ok() { @@ -277,7 +277,7 @@ pub fn (mut c GridProxyClient) get_contracts(params ContractFilter) ?[]Contract } contracts := json.decode([]Contract, res.data) or { - return error_with_code('error to get jsonstr for contract list data, json decode: contract filter: $params_map, data: $res.data', + return error_with_code('error to get jsonstr for contract list data, json decode: contract filter: ${params_map}, data: ${res.data}', gridproxy.err_json_parse) } return contracts @@ -301,12 +301,12 @@ pub fn (mut c GridProxyClient) get_contracts(params ContractFilter) ?[]Contract // * `stellar_address` (string): farm stellar_address. [optional]. // // returns: `[]Farm` or `Error`. -pub fn (mut c GridProxyClient) get_farms(params FarmFilter) ?[]Farm { +pub fn (mut c GridProxyClient) get_farms(params FarmFilter) ![]Farm { // needed to allow to use threads - mut http_client := c.http_client.clone() + mut http_client := c.http_client.clone()! params_map := params.to_map() res := http_client.send(prefix: 'farms/', params: params_map) or { - return error_with_code('http client error: $err.msg()', gridproxy.err_http_client) + return error_with_code('http client error: ${err.msg()}', gridproxy.err_http_client) } if !res.is_ok() { @@ -318,7 +318,7 @@ pub fn (mut c GridProxyClient) get_farms(params FarmFilter) ?[]Farm { } farms := json.decode([]Farm, res.data) or { - return error_with_code('error to get jsonstr for farm list data, json decode: farm filter: $params_map, data: $res.data', + return error_with_code('error to get jsonstr for farm list data, json decode: farm filter: ${params_map}, data: ${res.data}', gridproxy.err_json_parse) } return farms @@ -327,8 +327,8 @@ pub fn (mut c GridProxyClient) get_farms(params FarmFilter) ?[]Farm { // is_pingable checks if API server is reachable and responding. // // returns: bool, `true` if API server is reachable and responding, `false` otherwise -pub fn (mut c GridProxyClient) is_pingable() bool { - mut http_client := c.http_client.clone() +pub fn (mut c GridProxyClient) is_pingable() !bool { + mut http_client := c.http_client.clone()! res := http_client.send(prefix: 'ping/') or { return false } if !res.is_ok() { return false @@ -341,6 +341,7 @@ pub fn (mut c GridProxyClient) is_pingable() bool { return true } + // Iterators have the next() method, which returns the next page of the objects. // to be used in a loop to get all available results, or to lazely traverse pages till a specific condition is met. diff --git a/3bot/vgrid/gridproxy/gridproxy_factory.v b/3bot/vgrid/gridproxy/gridproxy_factory.v index 42b150acb..7cb26f30c 100644 --- a/3bot/vgrid/gridproxy/gridproxy_factory.v +++ b/3bot/vgrid/gridproxy/gridproxy_factory.v @@ -51,18 +51,23 @@ fn tfgrid_net_string(net TFGridNet) string { .qa { 'qa' } } } + // get returns a gridproxy client for the given net. // // * `net` (enum): the net to get the gridproxy client for (one of .main, .test, .dev, .qa). // * `use_redis_cache` (bool): if true, the gridproxy client will use a redis cache and redis should be running on the host. otherwise, the gridproxy client will not use cache. // // returns: `&GridProxyClient`. -pub fn get(net TFGridNet, use_redis_cache bool) &GridProxyClient { +pub fn get(net TFGridNet, use_redis_cache bool) !&GridProxyClient { mut f := factory_get() netstr := tfgrid_net_string(net) if netstr !in gridproxy.factory.instances { url := gridproxy_url_get(net) - mut httpconn := httpconnection.new('gridproxy_$netstr', url, use_redis_cache) + mut httpconn := httpconnection.new( + name: 'gridproxy_${netstr}' + url: url + cache: use_redis_cache + )! // do the settings on the connection httpconn.cache.expire_after = 7200 // make the cache timeout 2h mut connection := GridProxyClient{ diff --git a/3bot/vgrid/gridproxy/model/filter.v b/3bot/vgrid/gridproxy/model/filter.v index 4cdf0e30b..5c2052040 100644 --- a/3bot/vgrid/gridproxy/model/filter.v +++ b/3bot/vgrid/gridproxy/model/filter.v @@ -2,27 +2,31 @@ module model import json +type OptionU64 = EmptyOption | u64 +type OptionBool = EmptyOption | bool + [params] pub struct FarmFilter { - pub mut: - page u64 | EmptyOption = EmptyOption{} - size u64 | EmptyOption = EmptyOption{} - ret_count bool | EmptyOption = EmptyOption{} - free_ips u64 | EmptyOption = EmptyOption{} - total_ips u64 | EmptyOption = EmptyOption{} - stellar_address string - pricing_policy_id u64 | EmptyOption = EmptyOption{} - farm_id u64 | EmptyOption = EmptyOption{} - twin_id u64 | EmptyOption = EmptyOption{} - name string - name_contains string - certification_type string - dedicated bool | EmptyOption = EmptyOption{} +pub mut: + page OptionU64 = EmptyOption{} + size OptionU64 = EmptyOption{} + ret_count OptionBool = EmptyOption{} + free_ips OptionU64 = EmptyOption{} + total_ips OptionU64 = EmptyOption{} + stellar_address string + pricing_policy_id OptionU64 = EmptyOption{} + farm_id OptionU64 = EmptyOption{} + twin_id OptionU64 = EmptyOption{} + name string + name_contains string + certification_type string + dedicated OptionBool = EmptyOption{} } // serialize FarmFilter to map pub fn (f &FarmFilter) to_map() map[string]string { mut m := map[string]string{} + match f.page { EmptyOption {} u64 { @@ -74,6 +78,7 @@ pub fn (f &FarmFilter) to_map() map[string]string { m['twin_id'] = f.twin_id.str() } } + if f.name != '' { m['name'] = f.name } @@ -94,19 +99,19 @@ pub fn (f &FarmFilter) to_map() map[string]string { [params] pub struct ContractFilter { - pub mut: - page u64 | EmptyOption = EmptyOption{} - size u64 | EmptyOption = EmptyOption{} - ret_count bool | EmptyOption = EmptyOption{} - contract_id u64 | EmptyOption = EmptyOption{} - twin_id u64 | EmptyOption = EmptyOption{} - node_id u64 | EmptyOption = EmptyOption{} - contract_type string - state string - name string - number_of_public_ips u64 | EmptyOption = EmptyOption{} - deployment_data string - deployment_hash string +pub mut: + page OptionU64 = EmptyOption{} + size OptionU64 = EmptyOption{} + ret_count OptionBool = EmptyOption{} + contract_id OptionU64 = EmptyOption{} + twin_id OptionU64 = EmptyOption{} + node_id OptionU64 = EmptyOption{} + contract_type string + state string + name string + number_of_public_ips OptionU64 = EmptyOption{} + deployment_data string + deployment_hash string } // serialize ContractFilter to map @@ -174,26 +179,26 @@ pub fn (f &ContractFilter) to_map() map[string]string { [params] pub struct NodeFilter { - pub mut: - page u64 | EmptyOption = EmptyOption{} - size u64 | EmptyOption = EmptyOption{} - ret_count bool | EmptyOption = EmptyOption{} - free_mru u64 | EmptyOption = EmptyOption{} - free_sru u64 | EmptyOption = EmptyOption{} - free_hru u64 | EmptyOption = EmptyOption{} - free_ips u64 | EmptyOption = EmptyOption{} - city string - country string - farm_name string - ipv4 string - ipv6 string - domain string - status string - dedicated bool | EmptyOption = EmptyOption{} - rentable bool | EmptyOption = EmptyOption{} - rented_by u64 | EmptyOption = EmptyOption{} - available_for u64 | EmptyOption = EmptyOption{} - farm_ids []u64 +pub mut: + page OptionU64 = EmptyOption{} + size OptionU64 = EmptyOption{} + ret_count OptionBool = EmptyOption{} + free_mru OptionU64 = EmptyOption{} + free_sru OptionU64 = EmptyOption{} + free_hru OptionU64 = EmptyOption{} + free_ips OptionU64 = EmptyOption{} + city string + country string + farm_name string + ipv4 string + ipv6 string + domain string + status string + dedicated OptionBool = EmptyOption{} + rentable OptionBool = EmptyOption{} + rented_by OptionU64 = EmptyOption{} + available_for OptionU64 = EmptyOption{} + farm_ids []u64 } // serialize NodeFilter to map @@ -300,27 +305,27 @@ pub enum NodeStatus { [params] pub struct ResourceFilter { - pub mut: - free_mru_gb u64 - free_sru_gb u64 - free_hru_gb u64 - free_ips u64 +pub mut: + free_mru_gb u64 + free_sru_gb u64 + free_hru_gb u64 + free_ips u64 } [params] pub struct StatFilter { - pub mut: - status NodeStatus +pub mut: + status NodeStatus } [params] pub struct TwinFilter { - pub mut: - page u64 | EmptyOption = EmptyOption{} - size u64 | EmptyOption = EmptyOption{} - ret_count bool | EmptyOption = EmptyOption{} - twin_id u64 | EmptyOption = EmptyOption{} - account_id string +pub mut: + page OptionU64 = EmptyOption{} + size OptionU64 = EmptyOption{} + ret_count OptionBool = EmptyOption{} + twin_id OptionU64 = EmptyOption{} + account_id string } // serialize TwinFilter to map diff --git a/3bot/vgrid/gridproxy/model/iterators.v b/3bot/vgrid/gridproxy/model/iterators.v index 119c3379b..a075393de 100644 --- a/3bot/vgrid/gridproxy/model/iterators.v +++ b/3bot/vgrid/gridproxy/model/iterators.v @@ -1,11 +1,12 @@ module model -pub type NodeGetter = fn (NodeFilter) ?[]Node + +pub type NodeGetter = fn (NodeFilter) ![]Node pub struct NodeIterator { pub mut: - filter NodeFilter + filter NodeFilter pub: - get_func NodeGetter + get_func NodeGetter } pub fn (mut i NodeIterator) next() ?[]Node { @@ -16,23 +17,21 @@ pub fn (mut i NodeIterator) next() ?[]Node { u64 { i.filter.page = i.filter.page as u64 + 1 } - } - nodes := i.get_func(i.filter) or { - return err } + nodes := i.get_func(i.filter) or { return none } if nodes.len == 0 { return none } return nodes } -pub type FarmGetter = fn (FarmFilter) ?[]Farm +pub type FarmGetter = fn (FarmFilter) ![]Farm pub struct FarmIterator { pub mut: - filter FarmFilter + filter FarmFilter pub: - get_func FarmGetter + get_func FarmGetter } pub fn (mut i FarmIterator) next() ?[]Farm { @@ -43,23 +42,21 @@ pub fn (mut i FarmIterator) next() ?[]Farm { u64 { i.filter.page = i.filter.page as u64 + 1 } - } - farms := i.get_func(i.filter) or { - return err } + farms := i.get_func(i.filter) or { return none } if farms.len == 0 { return none } return farms } -pub type ContractGetter = fn (ContractFilter) ?[]Contract +pub type ContractGetter = fn (ContractFilter) ![]Contract pub struct ContractIterator { pub mut: - filter ContractFilter + filter ContractFilter pub: - get_func ContractGetter + get_func ContractGetter } pub fn (mut i ContractIterator) next() ?[]Contract { @@ -70,23 +67,21 @@ pub fn (mut i ContractIterator) next() ?[]Contract { u64 { i.filter.page = i.filter.page as u64 + 1 } - } - contracts := i.get_func(i.filter) or { - return err } + contracts := i.get_func(i.filter) or { return none } if contracts.len == 0 { return none } return contracts } -pub type TwinGetter = fn (TwinFilter) ?[]Twin +pub type TwinGetter = fn (TwinFilter) ![]Twin pub struct TwinIterator { pub mut: - filter TwinFilter + filter TwinFilter pub: - get_func TwinGetter + get_func TwinGetter } pub fn (mut i TwinIterator) next() ?[]Twin { @@ -97,13 +92,10 @@ pub fn (mut i TwinIterator) next() ?[]Twin { u64 { i.filter.page = i.filter.page as u64 + 1 } - } - twins := i.get_func(i.filter) or { - return err } + twins := i.get_func(i.filter) or { return none } if twins.len == 0 { return none } return twins } - diff --git a/install.sh b/install.sh index 2da7bf036..3eec84732 100755 --- a/install.sh +++ b/install.sh @@ -5,6 +5,7 @@ DIR_OF_THIS_SCRIPT="$( dirname "$SOURCE" )" ABS_DIR_OF_SCRIPT="$( realpath $DIR_OF_THIS_SCRIPT )" mkdir -p ~/.vmodules/threefoldtech ln -s $ABS_DIR_OF_SCRIPT/web3gw/client ~/.vmodules/threefoldtech/web3gw +ln -s $ABS_DIR_OF_SCRIPT/3bot/vgrid ~/.vmodules/threefoldtech/vgrid # install crystallib if !(v list | grep -q 'freeflowuniverse.crystallib'); then