diff --git a/3bot/vgrid/README.md b/3bot/vgrid/README.md deleted file mode 100644 index f002c6391..000000000 --- a/3bot/vgrid/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Grid Modules (vlang) - -to install - -``` -v install --git https://github.com/threefoldtech/vgrid -``` - -## GridProxy Client - -see the GridProxy Client docs [here](gridproxy/README.md) diff --git a/3bot/vgrid/examples/README.md b/3bot/vgrid/examples/README.md deleted file mode 100644 index 9d7223d5b..000000000 --- a/3bot/vgrid/examples/README.md +++ /dev/null @@ -1,125 +0,0 @@ -## script examples - - -### - Get nodes by country or city - -This script is used to get the nodes by country or city or even both - -#### Args - -This script to get nodes by city or country or both - -```bash - --help get information about the command - - --city name of the city (optional) - - --country name of the country (optional) - - --network one of (dev, test, qa, main) (optional)(default to `test`) - - --max-count maximum number of nodes to be selected (optional)(default to 0 which means no limit) - - --cache enable cache (optional)(default to false) -``` - -##### You have to specify at least a city or country - -- Execute - - Use country only - ```bash - v run examples/get_nodes_by_city_country.v --country Albania - ``` - - Use city only - ```bash - v run examples/get_nodes_by_city_country.v --city Douzy - ``` - - Use both city and country - ```bash - v run examples/get_nodes_by_city_country.v --country Albania --city Douzy - ``` -- Help `--help` - - ```bash - v run examples/get_nodes_by_city_country.v --help - ``` - - ``` - This script to get nodes by city or country or both - - --city name of the city (optional) - - --country name of the country (optional) - - --network one of (dev, test, qa, main) (optional)(default to `test`) - - --max-count maximum number of nodes to be selected (optional)(default to 0 which means no limit) - - --cache enable cache (optional)(default to false) - - ``` - - ### - Get nodes by capacity - - This script is used to get the nodes by available resources - including ssd resource unit `sru`, hd resource unit `hru` and memory resource unit `mru`, ip resource unit `ips` - - #### Args - - This script to get nodes by available resources (sru, hru, mru, ips) - - ```bash - --help get information about the command - - --sru nodes selected should have a minumum value of free sru in GB (ssd resource unit) equal to this (optional) - - --hru nodes selected should have a minumum value of free in GB (hd resource unit) equal to this (optional) - - --mru nodes selected should have a minumum value of free mru in GB (memory resource unit) equal to this (optional) - - --ips nodes selected should have a minumum value of free ips (ip address resource unit) equal to this (optional) - - --network one of (dev, test, qa, main) (optional)(default to `test`) - - --max-count maximum number of nodes to be selected (optional)(default to 0 which means no limit) - - --cache enable cache (optional)(default to false) - ``` - -- Execute - - - Use (sru, hru, mru, ips) - - ```bash - v run examples/get_nodes_by_capacity.v --sru 500 --ips 5 --hru 500 --mru 50 - ``` - - - Use single argument - ```bash - v run examples/get_nodes_by_capacity.v --sru 500 - ``` - - Use no arguments in this case will list all the nodes - - ```bash - v run examples/get_nodes_by_capacity.v - ``` - - - Help `--help` - - ```bash - This script to get nodes by available resources - - --sru nodes selected should have a minumum value of free sru in GB (ssd resource unit) equal to this (optional) - - --hru nodes selected should have a minumum value of free hru in GB (hd resource unit) equal to this (optional) - - --mru nodes selected should have a minumum value of free mru in GB (memory resource unit) equal to this (optional) - - --ips nodes selected should have a minumum value of ips (core resource unit) equal to this (optional) - - --network one of (dev, test, qa, main) (optional)(default to `test`) - - --max-count maximum number of nodes to be selected (optional)(default to 0 which means no limit) - - --cache enable cache (optional)(default to false) - ``` diff --git a/3bot/vgrid/examples/get_nodes_by_capacity.v b/3bot/vgrid/examples/get_nodes_by_capacity.v deleted file mode 100644 index 51f636138..000000000 --- a/3bot/vgrid/examples/get_nodes_by_capacity.v +++ /dev/null @@ -1,101 +0,0 @@ -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{} - - 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') - return - } - - 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 '--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() - } - - 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() - } - - mut cache := false - if '--cache' in os.args { - cache = true - } - - network := match net { - 'dev' { - TFGridNet.dev - } - 'test' { - TFGridNet.test - } - 'qa' { - TFGridNet.qa - } - 'main' { - TFGridNet.main - } - else { - panic('network ${net} not supported') - } - } - 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{} - // 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 - for node in nodes { - nodes_with_min_resources << node - if max_count > 0 && nodes_with_min_resources.len == max_count { - break outer - } - } - } - 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('---------------------------------------') - 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 deleted file mode 100644 index 09a386bba..000000000 --- a/3bot/vgrid/examples/get_nodes_by_city_country.v +++ /dev/null @@ -1,84 +0,0 @@ -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{} - - 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') - 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 '--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 max_count := 0 - 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 { - cache = true - } - - network := match net { - 'dev' { - TFGridNet.dev - } - 'test' { - TFGridNet.test - } - 'qa' { - TFGridNet.qa - } - 'main' { - TFGridNet.main - } - else { - panic('network ${net} not supported') - } - } - 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{} - outer: for nodes in nodes_iter { - for node in nodes { - nodes_by_city_country << node - if max_count > 0 && nodes_by_city_country.len == max_count { - break outer - } - } - } - 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/examples/simple.v b/3bot/vgrid/examples/simple.v deleted file mode 100644 index 96793ad42..000000000 --- a/3bot/vgrid/examples/simple.v +++ /dev/null @@ -1,32 +0,0 @@ -import threefoldtech.vgrid.gridproxy - -fn do()!{ - mut gp_client := gridproxy.get(.test, true)! - farms := gp_client.get_farms()! - // println(farms) - - // get gateway list - gateways := gp_client.get_gateways()! - // get contract list - contracts := gp_client.get_contracts()! - // get grid stats - stats := gp_client.get_stats()! - // println(stats) - // get twins - twins := gp_client.get_twins()! - - // get node list - nodes := gp_client.get_nodes(dedicated: true,free_ips: u64(1))! - println(nodes) - - - //amazing documentation on https://github.com/threefoldtech/vgrid/blob/development/gridproxy/README.md - -} - -fn main(){ - -do() or {panic(err)} - - -} \ No newline at end of file diff --git a/3bot/vgrid/gridproxy/README.md b/3bot/vgrid/gridproxy/README.md deleted file mode 100644 index d99ee4bbf..000000000 --- a/3bot/vgrid/gridproxy/README.md +++ /dev/null @@ -1,235 +0,0 @@ -# GridProxy API client - -![GitHub contributors](https://img.shields.io/github/contributors/threefoldtech/vgrid) -![GitHub stars](https://img.shields.io/github/stars/threefoldtech/vgrid?style=social) -![GitHub forks](https://img.shields.io/github/forks/threefoldtech/vgrid?style=social) -![Twitter Follow](https://img.shields.io/twitter/follow/threefold_io?style=social) - -Easily access Threefold grid APIs from vlang. gridproxy is v module include the API client along with API-specific information such as the root URL for the different networks available in the threefold grid. They also include classes that represent entities in the context of the API in sub-module `model`, and that are useful for making conversions between JSON objects and V objects. and some types with helper methods to convert the machine-friendly units returned by the API to more human-friendly units. - - - - -## Table of Contents -- [GridProxy API client](#gridproxy-api-client) - - [Table of Contents](#table-of-contents) - - [Getting Started](#getting-started) - - [Tools Required](#tools-required) - - [Installation](#installation) - - [Development](#development) - - [client usage](#client-usage) - - [Client Examples](#client-examples) - - [Contributing](#contributing) - - [Versioning](#versioning) - - [Authors](#authors) - - [License](#license) - - [Acknowledgments](#acknowledgments) - -## Getting Started - -The project might have multiple branches which can be explained here - -* `main` this branch not available yet, it should contains aggregate code of all branches. -* `development` contains code under development. currently it is the default branch. - -the project structure is as follows: - -``` -vgrid -│ ├─ README.md -├─ LICENSE -├─ README.md -├─ examples -│ ├─ README.md -│ ├─ get_nodes_by_capacity.v -│ └─ get_nodes_by_city_country.v -├─ gridproxy -│ ├─ README.md -│ ├─ docs -│ │ ├─ threefoldtech.vgrid.gridproxy.md -│ │ └─ threefoldtech.vgrid.gridproxy.model.md -│ ├─ gridproxy_core.v -│ ├─ gridproxy_factory.v -│ ├─ gridproxy_highlevel.v -│ ├─ gridproxy_test.v -│ └─ model -│ ├─ contract.v -│ ├─ farm.v -│ ├─ filter.v -│ ├─ iterators.v -│ ├─ model.v -│ ├─ node.v -│ ├─ stats.v -│ └─ twin.v -└─ v.mod - -``` - -### Tools Required - -You would require the following tools to develop and run the project: - -* V language -* freeflowuniverse.crystallib v module - ```sh - v install https://github.com/freeflowuniverse/crystallib - ``` -* Redis-server unless you are set the caching option to false - * see [here](https://redis.io/docs/getting-started/installation/) for redis-server installation instructions - * start the redis-server on default tcp port, you can use `redis-server` command. - ```sh - redis-server --daemonize yes - ``` -or your os specific instructions for running redis-server as a service. on linux/ubuntu you can use - ```sh - sudo systemctl start redis-server.service - ``` - -### Installation - -* either clone the repository inside the `$HOME/.vmodules/threefoldtech` directory - ```sh - mkdir -p $HOME/.vmodules/threefoldtech - cd $HOME/.vmodules/threefoldtech - git clone https://github.com/threefoldtech/vgrid.git - ``` - -* or use the `v install` command to install the module. - ```sh - v install --once -v --git https://github.com/threefoldtech/vgrid - ``` - -## Development - -We assume that you runs the commands in the project root directory. - -* You don't need to worry about formatting your code or setting style guidelines. v fmt takes care of that - ```sh - v fmt -w ./gridproxy/ - ``` -* run the tests - ```sh - v -stats test ./gridproxy/ - ``` -* generate the documentation of gridproxy modules - ```sh - v doc -m ./gridproxy -f md -o ./gridproxy/docs - ``` - -## client usage - -If you want to use the client, you need to import it in your code. - -* import the client: - ```v - import threefoldtech.vgrid.gridproxy - ``` - -* create a client: - ```v - // create a client for the testnet, with API cache disabled - // you can pass true as second arg to enable cache - mut gp_client := gridproxy.get(.test, false)! - ``` - -* use the client to interact with the gridproxy API: - ```v - // get farm list - farms := gp_client.get_farms()! // you should handle any possible errors in your code - // get gateway list - gateways := gp_client.get_gateways()! - // get node list - nodes := gp_client.get_nodes()! - // get contract list - contracts := gp_client.get_contracts()! - // get grid stats - stats := gp_client.get_stats()! - // get node by id - node := gp_client.get_node_by_id(u64(16))! - // get node stats - node_stats := gp_client.get_node_stats_by_id(u64(16))! - // get twins - twins := gp_client.get_twins()! - ``` - for all available methods on the client, see [GridProxy API client modules doc](./docs/) - -* filtering: - ```v - // getting only dedicated farms - farms_dedicated := gp_client.get_farms(dedicated: true)! - // getting only farms with at least one free ip - farms_with_free_ips := gp_client.get_farms(free_ips: u64(1))! - // pagination options: - // get first page of farms - farms_first_page := gp_client.get_farms(page: u64(1))! - // you can mix any filters and pagination options - farms_first_page_dedicated := gp_client.get_farms(page: u64(1), dedicated: true)! - // access the field of first farm in the list - // the API could return an empty list if no farm is found - // you should handle this case in your code - if farms_first_page.len > 0 { - println(farms_first_page[0].name) - } - ``` - - for all available filters, see [GridProxy API client modules doc](./docs/) - -* helper methods: - ```v - node := nodes[0] - node.updated_at // 1655940222 - node.created // 1634637306 - // you can convert the timestamp to V Time object easily with the helper method - node.created.to_time() // 2021-10-19 09:55:06 - node.created.to_time().local() // 2021-10-19 11:55:06 - node.created.to_time().relative() // last Oct 19 - node.created.to_time().relative_short() // 246d ago - // lets check another field with different type - node.uptime // 18958736 - // you can convert the seconds to a human-readable duration with the helper method - node.uptime.to_days() // 219.42981481481482 - node.uptime.to_hours() // 5266.315555555556 - node.uptime.to_minutes() // 315978.93333333335 - // now to the capacity helper methods - node.total_resources.mru // 202803036160 - // you can `to_megabytes`, `to_gigabytes` and `to_terabytes` methods on any resources field. - node.total_resources.mru.to_gigabytes() // 202.80303616 - // the helper methods available for the billing to help you convert the TFT units as well - ``` - for all available helper methods, see [GridProxy API client modules doc](./docs/) - - TODO: - * Documented the client iterators and higher-level methods - -## Client Examples -there are scripts available to serve as examples in the [examples](../examples/) directory. [Docs](../examples/README.md) - -## Contributing - -We'd love to have your helping hand on `GridProxy Client`! See [CONTRIBUTING.md] for more information on what we're looking for and how to get started. - -## Versioning - -TODO - -## Authors -[Sameh Farouk](https://github.com/sameh-farouk) - -You can also see the complete [list of contributors][contributors] who participated in this project. - -## License - -`GridProxy Client` is open source software [licensed as Apache][license]. - -## Acknowledgments - -TODO - -[//]: # (HyperLinks) - -[GitHub Repository]: https://github.com/threefoldtech/vgrid -[CONTRIBUTING.md]: https://github.com/threefoldtech/vgrid/blob/development/CONTRIBUTING.md -[tags]: https://github.com/threefoldtech/vgrid/tags - -[contributors]: https://github.com/threefoldtech/vgrid/contributors -[license]: https://github.com/threefoldtech/vgrid/blob/development/LICENSE \ No newline at end of file diff --git a/3bot/vgrid/gridproxy/docs/gridproxy.md b/3bot/vgrid/gridproxy/docs/gridproxy.md deleted file mode 100644 index 43911b09f..000000000 --- a/3bot/vgrid/gridproxy/docs/gridproxy.md +++ /dev/null @@ -1,460 +0,0 @@ -# module gridproxy - - - - -## Contents -- [get](#get) -- [TFGridNet](#TFGridNet) -- [GridProxyClient](#GridProxyClient) - - [get_contracts](#get_contracts) - - [get_contracts_by_node_id](#get_contracts_by_node_id) - - [get_contracts_by_twin_id](#get_contracts_by_twin_id) - - [get_contracts_iterator](#get_contracts_iterator) - - [get_farm_by_id](#get_farm_by_id) - - [get_farm_by_name](#get_farm_by_name) - - [get_farms](#get_farms) - - [get_farms_by_twin_id](#get_farms_by_twin_id) - - [get_farms_iterator](#get_farms_iterator) - - [get_gateway_by_id](#get_gateway_by_id) - - [get_gateways](#get_gateways) - - [get_gateways_iterator](#get_gateways_iterator) - - [get_node_by_id](#get_node_by_id) - - [get_node_stats_by_id](#get_node_stats_by_id) - - [get_nodes](#get_nodes) - - [get_nodes_has_resources](#get_nodes_has_resources) - - [get_nodes_iterator](#get_nodes_iterator) - - [get_stats](#get_stats) - - [get_twin_by_account](#get_twin_by_account) - - [get_twin_by_id](#get_twin_by_id) - - [get_twins](#get_twins) - - [get_twins_iterator](#get_twins_iterator) - - [is_pingable](#is_pingable) - -## get -```v -fn get(net TFGridNet, use_redis_cache bool) !&GridProxyClient -``` - -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`. - -[[Return to contents]](#Contents) - -## TFGridNet -```v -enum TFGridNet { - main - test - dev - qa -} -``` - - -[[Return to contents]](#Contents) - -## GridProxyClient -```v -struct GridProxyClient { -pub mut: - http_client httpconnection.HTTPConnection -} -``` - - -[[Return to contents]](#Contents) - -## get_contracts -```v -fn (mut c GridProxyClient) get_contracts(params ContractFilter) ![]Contract -``` - -get_contracts fetchs contracts information with pagination. - -* `contract_id` (u64): Contract id. [optional]. -* `contract_type` (string): [optional]. -* `deployment_data` (string): Contract deployment data in case of 'node' contracts. [optional]. -* `deployment_hash` (string): Contract deployment hash in case of 'node' contracts. [optional]. -* `name` (string): Contract name in case of 'name' contracts. [optional]. -* `node_id` (u64): Node id which contract is deployed on in case of ('rent' or 'node' contracts). [optional]. -* `number_of_public_ips` (u64): Min number of public ips in the 'node' contract. [optional]. -* `page` (u64): Page number. [optional]. -* `randomize` (bool): [optional]. -* `ret_count` (bool): Set farms' count on headers based on filter. [optional]. -* `size` (u64): Max result per page. [optional]. -* `state` (string): Contract state 'Created', or 'Deleted'. [optional]. -* `twin_id` (u64): Twin id. [optional]. -* `type` (string): Contract type 'node', 'name', or 'rent'. [optional]. - -* returns: `[]Contract` or `Error`. - -[[Return to contents]](#Contents) - -## get_contracts_by_node_id -```v -fn (mut c GridProxyClient) get_contracts_by_node_id(node_id u64) ContractIterator -``` - -get_contracts_by_node_id returns iterator over all contracts deployed on specific node. - -* `node_id`: node id. - -returns: `ContractIterator`. - -[[Return to contents]](#Contents) - -## get_contracts_by_twin_id -```v -fn (mut c GridProxyClient) get_contracts_by_twin_id(twin_id u64) ContractIterator -``` - -get_contracts_by_twin_id returns iterator over all contracts owned by specific twin. - -* `twin_id`: twin id. - -returns: `ContractIterator`. - -[[Return to contents]](#Contents) - -## get_contracts_iterator -```v -fn (mut c GridProxyClient) get_contracts_iterator(filter ContractFilter) ContractIterator -``` - -get_contracts_iterator creates an iterator through contracts pages with custom filter - -[[Return to contents]](#Contents) - -## get_farm_by_id -```v -fn (mut c GridProxyClient) get_farm_by_id(farm_id u64) ?Farm -``` - -fetch specific farm information by id. - -* `farm_id`: farm id. - -returns: `Farm` or `Error`. - -[[Return to contents]](#Contents) - -## get_farm_by_name -```v -fn (mut c GridProxyClient) get_farm_by_name(farm_name string) ?Farm -``` - -fetch specific farm information by farm name. - -* `farm_name`: farm name. - -returns: `Farm` or `Error`. - -[[Return to contents]](#Contents) - -## get_farms -```v -fn (mut c GridProxyClient) get_farms(params FarmFilter) ![]Farm -``` - -get_farms fetchs farms information and public ips. - -* `certification_type` (string): Certificate type DIY or Certified. [optional]. -* `country` (string): Farm country. [optional]. -* `dedicated` (bool): Farm is dedicated. [optional]. -* `farm_id` (u64): Farm id. [optional]. -* `free_ips` (u64): Min number of free ips in the farm. [optional]. -* `name_contains` (string): Farm name contains. [optional]. -* `name` (string): Farm name. [optional]. -* `node_available_for` (u64): Twin ID of user for whom there is at least one node that is available to be deployed to in the farm. [optional]. -* `node_certified` (bool): True for farms who have at least one certified node. [optional]. -* `node_free_hru` (u64): Min free reservable hru for at least a single node that belongs to the farm, in bytes. [optional]. -* `node_free_mru` (u64): Min free reservable mru for at least a single node that belongs to the farm, in bytes. [optional]. -* `node_free_sru` (u64): Min free reservable sru for at least a single node that belongs to the farm, in bytes. [optional]. -* `node_has_gpu` (bool): True for farms who have at least one node with a GPU * `node_rented_by` (u64): Twin ID of user who has at least one rented node in the farm * `node_status` (string): Node status for at least a single node that belongs to the farm -* `page` (u64): Page number. [optional]. -* `pricing_policy_id` (u64): Pricing policy id. [optional]. -* `randomize` (bool): [optional]. -* `ret_count` (bool): Set farms' count on headers based on filter. [optional]. -* `size` (u64): Max result per page. [optional]. -* `stellar_address` (string): Farm stellar_address. [optional]. -* `total_ips` (u64): Min number of total ips in the farm. [optional]. -* `twin_id` (u64): Twin id associated with the farm. [optional]. -* `version` (u64): Farm version. [optional]. - -returns: `[]Farm` or `Error`. - -[[Return to contents]](#Contents) - -## get_farms_by_twin_id -```v -fn (mut c GridProxyClient) get_farms_by_twin_id(twin_id u64) FarmIterator -``` - -get_farms_by_twin_id returns iterator over all farms information associated with specific twin. - -* `twin_id`: twin id. - -returns: `FarmIterator`. - -[[Return to contents]](#Contents) - -## get_farms_iterator -```v -fn (mut c GridProxyClient) get_farms_iterator(filter FarmFilter) FarmIterator -``` - -get_farms_iterator creates an iterator through farms pages with custom filter - -[[Return to contents]](#Contents) - -## get_gateway_by_id -```v -fn (mut c GridProxyClient) get_gateway_by_id(node_id u64) !Node -``` - -get_gateway_by_id fetchs specific gateway information by node id. - -* `node_id` (u64): node id. - -returns: `Node` or `Error`. - -[[Return to contents]](#Contents) - -## get_gateways -```v -fn (mut c GridProxyClient) get_gateways(params NodeFilter) ![]Node -``` - -get_gateways fetchs gateways information and public configurations and domains with pagination. - -* `available_for` (u64): Available for twin id. [optional]. -* `certification_type` (string): Certificate type NotCertified, Silver or Gold. [optional]. -* `city_contains` (string): Node partial city filter. [optional]. -* `city` (string): Node city filter. [optional]. -* `country_contains` (string): Node partial country filter. [optional]. -* `country` (string): Node country filter. [optional]. -* `dedicated` (bool): Set to true to get the dedicated nodes only. [optional]. -* `domain` (string): Set to true to filter nodes with domain. [optional]. -* `farm_ids` ([]u64): List of farm ids. [optional]. -* `farm_name_contains` (string): Get nodes for specific farm. [optional]. -* `farm_name` (string): Get nodes for specific farm. [optional]. -* `free_hru` (u64): Min free reservable hru in bytes. [optional]. -* `free_ips` (u64): Min number of free ips in the farm of the node. [optional]. -* `free_mru` (u64): Min free reservable mru in bytes. [optional]. -* `free_sru` (u64): Min free reservable sru in bytes. [optional]. -* `gpu_available` (bool): Filter nodes that have available GPU. [optional]. -* `gpu_device_id` (string): Filter nodes based on GPU device ID. [optional]. -* `gpu_device_name` (string): Filter nodes based on GPU device partial name. [optional]. -* `gpu_vendor_id` (string): Filter nodes based on GPU vendor ID. [optional]. -* `gpu_vendor_name` (string): Filter nodes based on GPU vendor partial name. [optional]. -* `has_gpu`: Filter nodes on whether they have GPU support or not. [optional]. -* `ipv4` (string): Set to true to filter nodes with ipv4. [optional]. -* `ipv6` (string): Set to true to filter nodes with ipv6. [optional]. -* `node_id` (u64): Node id. [optional]. -* `page` (u64): Page number. [optional]. -* `rentable` (bool): Set to true to filter the available nodes for renting. [optional]. -* `rented_by` (u64): Rented by twin id. [optional]. -* `ret_count` (bool): Set nodes' count on headers based on filter. [optional]. -* `size` (u64): Max result per page. [optional]. -* `status` (string): Node status filter, set to 'up' to get online nodes only. [optional]. -* `total_cru` (u64): Min total cru in bytes. [optional]. -* `total_hru` (u64): Min total hru in bytes. [optional]. -* `total_mru` (u64): Min total mru in bytes. [optional]. -* `total_sru` (u64): Min total sru in bytes. [optional]. -* `twin_id` (u64): Twin id. [optional]. - -returns: `[]Node` or `Error`. - -[[Return to contents]](#Contents) - -## get_gateways_iterator -```v -fn (mut c GridProxyClient) get_gateways_iterator(filter NodeFilter) NodeIterator -``` - -get_gateways_iterator creates an iterator through gateway pages with custom filter - -[[Return to contents]](#Contents) - -## get_node_by_id -```v -fn (mut c GridProxyClient) get_node_by_id(node_id u64) !Node -``` - -get_node_by_id fetchs specific node information by node id. - -* `node_id` (u64): node id. - -returns: `Node` or `Error`. - -[[Return to contents]](#Contents) - -## get_node_stats_by_id -```v -fn (mut c GridProxyClient) get_node_stats_by_id(node_id u64) !NodeStats -``` - -get_node_stats_by_id fetchs specific node statistics by node id. - -* `node_id` (u64): node id. - -returns: `Node_stats` or `Error`. - -[[Return to contents]](#Contents) - -## get_nodes -```v -fn (mut c GridProxyClient) get_nodes(params NodeFilter) ![]Node -``` - -get_nodes fetchs nodes information and public configurations with pagination. - -* `available_for` (u64): Available for twin id. [optional]. -* `certification_type` (string): Certificate type NotCertified, Silver or Gold. [optional]. -* `city_contains` (string): Node partial city filter. [optional]. -* `city` (string): Node city filter. [optional]. -* `country_contains` (string): Node partial country filter. [optional]. -* `country` (string): Node country filter. [optional]. -* `dedicated` (bool): Set to true to get the dedicated nodes only. [optional]. -* `domain` (string): Set to true to filter nodes with domain. [optional]. -* `farm_ids` ([]u64): List of farm ids. [optional]. -* `farm_name_contains` (string): Get nodes for specific farm. [optional]. -* `farm_name` (string): Get nodes for specific farm. [optional]. -* `free_hru` (u64): Min free reservable hru in bytes. [optional]. -* `free_ips` (u64): Min number of free ips in the farm of the node. [optional]. -* `free_mru` (u64): Min free reservable mru in bytes. [optional]. -* `free_sru` (u64): Min free reservable sru in bytes. [optional]. -* `gpu_available` (bool): Filter nodes that have available GPU. [optional]. -* `gpu_device_id` (string): Filter nodes based on GPU device ID. [optional]. -* `gpu_device_name` (string): Filter nodes based on GPU device partial name. [optional]. -* `gpu_vendor_id` (string): Filter nodes based on GPU vendor ID. [optional]. -* `gpu_vendor_name` (string): Filter nodes based on GPU vendor partial name. [optional]. -* `has_gpu`: Filter nodes on whether they have GPU support or not. [optional]. -* `ipv4` (string): Set to true to filter nodes with ipv4. [optional]. -* `ipv6` (string): Set to true to filter nodes with ipv6. [optional]. -* `node_id` (u64): Node id. [optional]. -* `page` (u64): Page number. [optional]. -* `rentable` (bool): Set to true to filter the available nodes for renting. [optional]. -* `rented_by` (u64): Rented by twin id. [optional]. -* `ret_count` (bool): Set nodes' count on headers based on filter. [optional]. -* `size` (u64): Max result per page. [optional]. -* `status` (string): Node status filter, set to 'up' to get online nodes only. [optional]. -* `total_cru` (u64): Min total cru in bytes. [optional]. -* `total_hru` (u64): Min total hru in bytes. [optional]. -* `total_mru` (u64): Min total mru in bytes. [optional]. -* `total_sru` (u64): Min total sru in bytes. [optional]. -* `twin_id` (u64): Twin id. [optional]. - -returns: `[]Node` or `Error`. - -[[Return to contents]](#Contents) - -## get_nodes_has_resources -```v -fn (mut c GridProxyClient) get_nodes_has_resources(filter ResourceFilter) NodeIterator -``` - -get_nodes_has_resources returns iterator over all nodes with specific minimum free reservable resources. - -* `free_ips` (u64): minimum free ips. [optional]. -* `free_mru_gb` (u64): minimum free mru in GB. [optional]. -* `free_sru_gb` (u64): minimum free sru in GB. [optional]. -* `free_hru_gb` (u64): minimum free hru in GB. [optional]. - -returns: `NodeIterator`. - -[[Return to contents]](#Contents) - -## get_nodes_iterator -```v -fn (mut c GridProxyClient) get_nodes_iterator(filter NodeFilter) NodeIterator -``` - -get_nodes_iterator creates an iterator through node pages with custom filter - -[[Return to contents]](#Contents) - -## get_stats -```v -fn (mut c GridProxyClient) get_stats(filter StatFilter) !GridStat -``` - -get_stats fetchs stats about the grid. - -* `status` (string): Node status filter, set to 'up' to get online nodes only.. [optional]. - -returns: `GridStat` or `Error`. - -[[Return to contents]](#Contents) - -## get_twin_by_account -```v -fn (mut c GridProxyClient) get_twin_by_account(account_id string) ?Twin -``` - -fetch specific twin information by account. - -* `account_id`: account id. - -returns: `Twin` or `Error`. - -[[Return to contents]](#Contents) - -## get_twin_by_id -```v -fn (mut c GridProxyClient) get_twin_by_id(twin_id u64) ?Twin -``` - -fetch specific twin information by twin id. - -* `twin_id`: twin id. - -returns: `Twin` or `Error`. - -[[Return to contents]](#Contents) - -## get_twins -```v -fn (mut c GridProxyClient) get_twins(params TwinFilter) ![]Twin -``` - -get_twins fetchs twins information with pagaination. - -* `account_id` (string): Account address. [optional]. -* `page` (u64): Page number. [optional]. -* `public_key` (string): twin public key used for e2e encryption. [optional]. -* `relay` (string): relay domain name. [optional]. -* `ret_count` (bool): Set farms' count on headers based on filter. [optional]. -* `size` (u64): Max result per page. [optional]. -* `twin_id` (u64): Twin id. [optional]. - -returns: `[]Twin` or `Error`. - -[[Return to contents]](#Contents) - -## get_twins_iterator -```v -fn (mut c GridProxyClient) get_twins_iterator(filter TwinFilter) TwinIterator -``` - -get_twins_iterator creates an iterator through twin pages with custom filter - -[[Return to contents]](#Contents) - -## is_pingable -```v -fn (mut c GridProxyClient) is_pingable() !bool -``` - -is_pingable checks if API server is reachable and responding. - -returns: bool, `true` if API server is reachable and responding, `false` otherwise - -[[Return to contents]](#Contents) - -#### Powered by vdoc. Generated on: 21 Aug 2023 13:39:52 diff --git a/3bot/vgrid/gridproxy/docs/gridproxy.model.md b/3bot/vgrid/gridproxy/docs/gridproxy.model.md deleted file mode 100644 index f1ca69cda..000000000 --- a/3bot/vgrid/gridproxy/docs/gridproxy.model.md +++ /dev/null @@ -1,800 +0,0 @@ -# module gridproxy.model - - - - -## Contents -- [ByteUnit](#ByteUnit) - - [to_megabytes](#to_megabytes) - - [to_gigabytes](#to_gigabytes) - - [to_terabytes](#to_terabytes) - - [str](#str) -- [ContractGetter](#ContractGetter) -- [DropTFTUnit](#DropTFTUnit) - - [to_tft](#to_tft) - - [to_mtft](#to_mtft) - - [to_utft](#to_utft) - - [str](#str) -- [FarmGetter](#FarmGetter) -- [NodeGetter](#NodeGetter) -- [SecondUnit](#SecondUnit) - - [to_minutes](#to_minutes) - - [to_hours](#to_hours) - - [to_days](#to_days) - - [str](#str) -- [TwinGetter](#TwinGetter) -- [UnixTime](#UnixTime) - - [to_time](#to_time) - - [str](#str) -- [NodeStatus](#NodeStatus) -- [Contract](#Contract) - - [total_billed](#total_billed) -- [ContractBilling](#ContractBilling) -- [ContractFilter](#ContractFilter) - - [to_map](#to_map) -- [ContractIterator](#ContractIterator) - - [next](#next) -- [Farm](#Farm) -- [FarmFilter](#FarmFilter) - - [to_map](#to_map) -- [FarmIterator](#FarmIterator) - - [next](#next) -- [GridStat](#GridStat) -- [Node](#Node) - - [calc_available_resources](#calc_available_resources) - - [is_online](#is_online) -- [Node_](#Node_) - - [with_nested_capacity](#with_nested_capacity) -- [NodeCapacity](#NodeCapacity) -- [NodeContractDetails](#NodeContractDetails) -- [NodeFilter](#NodeFilter) - - [to_map](#to_map) -- [NodeIterator](#NodeIterator) - - [next](#next) -- [NodeLocation](#NodeLocation) -- [NodeResources](#NodeResources) -- [NodeStatisticsResources](#NodeStatisticsResources) -- [NodeStatisticsUsers](#NodeStatisticsUsers) -- [NodeStats](#NodeStats) -- [PublicConfig](#PublicConfig) -- [PublicIP](#PublicIP) -- [ResourceFilter](#ResourceFilter) -- [StatFilter](#StatFilter) -- [Twin](#Twin) -- [TwinFilter](#TwinFilter) - - [to_map](#to_map) -- [TwinIterator](#TwinIterator) - - [next](#next) - -## ByteUnit -## to_megabytes -```v -fn (u ByteUnit) to_megabytes() f64 -``` - - -[[Return to contents]](#Contents) - -## to_gigabytes -```v -fn (u ByteUnit) to_gigabytes() f64 -``` - - -[[Return to contents]](#Contents) - -## to_terabytes -```v -fn (u ByteUnit) to_terabytes() f64 -``` - - -[[Return to contents]](#Contents) - -## str -```v -fn (u ByteUnit) str() string -``` - - -[[Return to contents]](#Contents) - -## ContractGetter -```v -type ContractGetter = fn (ContractFilter) ![]Contract -``` - - -[[Return to contents]](#Contents) - -## DropTFTUnit -## to_tft -```v -fn (t DropTFTUnit) to_tft() f64 -``` - - -[[Return to contents]](#Contents) - -## to_mtft -```v -fn (t DropTFTUnit) to_mtft() f64 -``` - - -[[Return to contents]](#Contents) - -## to_utft -```v -fn (t DropTFTUnit) to_utft() f64 -``` - - -[[Return to contents]](#Contents) - -## str -```v -fn (u DropTFTUnit) str() string -``` - - -[[Return to contents]](#Contents) - -## FarmGetter -```v -type FarmGetter = fn (FarmFilter) ![]Farm -``` - - -[[Return to contents]](#Contents) - -## NodeGetter -```v -type NodeGetter = fn (NodeFilter) ![]Node -``` - - -[[Return to contents]](#Contents) - -## SecondUnit -## to_minutes -```v -fn (u SecondUnit) to_minutes() f64 -``` - - -[[Return to contents]](#Contents) - -## to_hours -```v -fn (u SecondUnit) to_hours() f64 -``` - - -[[Return to contents]](#Contents) - -## to_days -```v -fn (u SecondUnit) to_days() f64 -``` - - -[[Return to contents]](#Contents) - -## str -```v -fn (u SecondUnit) str() string -``` - - -[[Return to contents]](#Contents) - -## TwinGetter -```v -type TwinGetter = fn (TwinFilter) ![]Twin -``` - - -[[Return to contents]](#Contents) - -## UnixTime -## to_time -```v -fn (t UnixTime) to_time() Time -``` - - -[[Return to contents]](#Contents) - -## str -```v -fn (t UnixTime) str() string -``` - - -[[Return to contents]](#Contents) - -## NodeStatus -```v -enum NodeStatus { - all - online -} -``` - - -[[Return to contents]](#Contents) - -## Contract -```v -struct Contract { -pub: - contract_id u64 [json: contractId] - twin_id u64 [json: twinId] - state string [json: state] - created_at UnixTime [json: created_at] - contract_type string [json: 'type'] - details NodeContractDetails [json: details] - billing []ContractBilling [json: billing] -} -``` - - -[[Return to contents]](#Contents) - -## total_billed -```v -fn (c &Contract) total_billed() DropTFTUnit -``` - -total_billed returns the total amount billed for the contract. - -returns: `DropTFTUnit` - -[[Return to contents]](#Contents) - -## ContractBilling -```v -struct ContractBilling { -pub: - amount_billed DropTFTUnit [json: amountBilled] - discount_received string [json: discountReceived] - timestamp UnixTime [json: timestamp] -} -``` - - -[[Return to contents]](#Contents) - -## ContractFilter -```v -struct ContractFilter { -pub mut: - page OptionU64 = EmptyOption{} - size OptionU64 = EmptyOption{} - ret_count OptionBool = EmptyOption{} - randomize 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 -} -``` - - -[[Return to contents]](#Contents) - -## to_map -```v -fn (f &ContractFilter) to_map() map[string]string -``` - -serialize ContractFilter to map - -[[Return to contents]](#Contents) - -## ContractIterator -```v -struct ContractIterator { -pub mut: - filter ContractFilter -pub: - get_func ContractGetter -} -``` - - -[[Return to contents]](#Contents) - -## next -```v -fn (mut i ContractIterator) next() ?[]Contract -``` - - -[[Return to contents]](#Contents) - -## Farm -```v -struct Farm { -pub: - name string - farm_id u64 [json: farmId] - twin_id u64 [json: twinId] - pricing_policy_id u64 [json: pricingPolicyId] - certification_type string [json: certificationType] - stellar_address string [json: stellarAddress] - dedicated bool - public_ips []PublicIP [json: publicIps] -} -``` - - -[[Return to contents]](#Contents) - -## FarmFilter -```v -struct FarmFilter { -pub mut: - page OptionU64 = EmptyOption{} - size OptionU64 = EmptyOption{} - ret_count OptionBool = EmptyOption{} - randomize 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{} - country string - node_free_mru OptionU64 = EmptyOption{} - node_free_hru OptionU64 = EmptyOption{} - node_free_sru OptionU64 = EmptyOption{} - node_status string - node_rented_by OptionU64 = EmptyOption{} - node_available_for OptionU64 = EmptyOption{} - node_has_gpu OptionBool = EmptyOption{} - node_certified OptionBool = EmptyOption{} -} -``` - - -[[Return to contents]](#Contents) - -## to_map -```v -fn (f &FarmFilter) to_map() map[string]string -``` - -serialize FarmFilter to map - -[[Return to contents]](#Contents) - -## FarmIterator -```v -struct FarmIterator { -pub mut: - filter FarmFilter -pub: - get_func FarmGetter -} -``` - - -[[Return to contents]](#Contents) - -## next -```v -fn (mut i FarmIterator) next() ?[]Farm -``` - - -[[Return to contents]](#Contents) - -## GridStat -```v -struct GridStat { -pub: - nodes u64 - farms u64 - countries u64 - total_cru u64 [json: totalCru] - total_sru ByteUnit [json: totalSru] - total_mru ByteUnit [json: totalMru] - total_hru ByteUnit [json: totalHru] - public_ips u64 [json: publicIps] - access_nodes u64 [json: accessNodes] - gateways u64 - twins u64 - contracts u64 - nodes_distribution map[string]u64 [json: nodesDistribution] -} -``` - - -[[Return to contents]](#Contents) - -## Node -```v -struct Node { -pub: - id string - node_id u64 [json: nodeId] - farm_id u64 [json: farmId] - twin_id u64 [json: twinId] - grid_version u64 [json: gridVersion] - uptime SecondUnit - created UnixTime [json: created] - farming_policy_id u64 [json: farmingPolicyId] - updated_at UnixTime [json: updatedAt] - capacity NodeCapacity - location NodeLocation - public_config PublicConfig [json: publicConfig] - certification string [json: certificationType] - status string - dedicated bool - rent_contract_id u64 [json: rentContractId] - rented_by_twin_id u64 [json: rentedByTwinId] -} -``` - - -[[Return to contents]](#Contents) - -## calc_available_resources -```v -fn (n &Node) calc_available_resources() NodeResources -``` - -calc_available_resources calculate the reservable capacity of the node. - -Returns: `NodeResources` - -[[Return to contents]](#Contents) - -## is_online -```v -fn (n &Node) is_online() bool -``` - -is_online returns true if the node is online, otherwise false. - -[[Return to contents]](#Contents) - -## Node_ -```v -struct Node_ { -pub: - id string - node_id u64 [json: nodeId] - farm_id u64 [json: farmId] - twin_id u64 [json: twinId] - grid_version u64 [json: gridVersion] - uptime SecondUnit - created UnixTime [json: created] - farming_policy_id u64 [json: farmingPolicyId] - updated_at UnixTime [json: updatedAt] - total_resources NodeResources - used_resources NodeResources - location NodeLocation - public_config PublicConfig [json: publicConfig] - certification string [json: certificationType] - status string - dedicated bool - rent_contract_id u64 [json: rentContractId] - rented_by_twin_id u64 [json: rentedByTwinId] -} -``` - -this is ugly, but it works. we need two models for `Node` and reimplemnt the same fields expcept for capacity srtucture it's a hack to make the json parser work as the gridproxy API have some inconsistencies see for more context: https://github.com/threefoldtech/tfgridclient_proxy/issues/164 - -[[Return to contents]](#Contents) - -## with_nested_capacity -```v -fn (n &Node_) with_nested_capacity() Node -``` - -with_nested_capacity enable the client to have one representation of the node model - -[[Return to contents]](#Contents) - -## NodeCapacity -```v -struct NodeCapacity { -pub: - total_resources NodeResources - used_resources NodeResources -} -``` - - -[[Return to contents]](#Contents) - -## NodeContractDetails -```v -struct NodeContractDetails { -pub: - node_id u64 [json: nodeId] - deployment_data string [json: deployment_data] - deployment_hash string [json: deployment_hash] - number_of_public_ips u64 [json: number_of_public_ips] -} -``` - - -[[Return to contents]](#Contents) - -## NodeFilter -```v -struct NodeFilter { -pub mut: - page OptionU64 = EmptyOption{} - size OptionU64 = EmptyOption{} - ret_count OptionBool = EmptyOption{} - randomize OptionBool = EmptyOption{} - free_mru OptionU64 = EmptyOption{} - free_sru OptionU64 = EmptyOption{} - free_hru OptionU64 = EmptyOption{} - free_ips OptionU64 = EmptyOption{} - total_mru OptionU64 = EmptyOption{} - total_sru OptionU64 = EmptyOption{} - total_hru OptionU64 = EmptyOption{} - total_cru OptionU64 = EmptyOption{} - city string - city_contains string - country string - country_contains string - farm_name string - farm_name_contains string - ipv4 OptionBool = EmptyOption{} - ipv6 OptionBool = EmptyOption{} - domain OptionBool = EmptyOption{} - status string - dedicated OptionBool = EmptyOption{} - rentable OptionBool = EmptyOption{} - rented_by OptionU64 = EmptyOption{} - rented OptionBool = EmptyOption{} - available_for OptionU64 = EmptyOption{} - farm_ids []u64 - node_id OptionU64 = EmptyOption{} - twin_id OptionU64 = EmptyOption{} - certification_type string - has_gpu OptionBool = EmptyOption{} - gpu_device_id string - gpu_device_name string - gpu_vendor_id string - gpu_vendor_name string - gpu_available OptionBool = EmptyOption{} -} -``` - - -[[Return to contents]](#Contents) - -## to_map -```v -fn (p &NodeFilter) to_map() map[string]string -``` - -serialize NodeFilter to map - -[[Return to contents]](#Contents) - -## NodeIterator -```v -struct NodeIterator { -pub mut: - filter NodeFilter -pub: - get_func NodeGetter -} -``` - - -[[Return to contents]](#Contents) - -## next -```v -fn (mut i NodeIterator) next() ?[]Node -``` - - -[[Return to contents]](#Contents) - -## NodeLocation -```v -struct NodeLocation { -pub: - country string - city string -} -``` - - -[[Return to contents]](#Contents) - -## NodeResources -```v -struct NodeResources { -pub: - cru u64 - mru ByteUnit - sru ByteUnit - hru ByteUnit -} -``` - - -[[Return to contents]](#Contents) - -## NodeStatisticsResources -```v -struct NodeStatisticsResources { -pub: - cru u64 - hru ByteUnit - ipv4u u64 - mru ByteUnit - sru ByteUnit -} -``` - - -[[Return to contents]](#Contents) - -## NodeStatisticsUsers -```v -struct NodeStatisticsUsers { -pub: - deployments u64 - workloads u64 -} -``` - - -[[Return to contents]](#Contents) - -## NodeStats -```v -struct NodeStats { -pub: - system NodeStatisticsResources - - total NodeStatisticsResources - - used NodeStatisticsResources - - users NodeStatisticsUsers -} -``` - - -[[Return to contents]](#Contents) - -## PublicConfig -```v -struct PublicConfig { -pub: - domain string - gw4 string - gw6 string - ipv4 string - ipv6 string -} -``` - - -[[Return to contents]](#Contents) - -## PublicIP -```v -struct PublicIP { -pub: - id string - ip string - farm_id string [json: farmId] - contract_id int [json: contractId] - gateway string -} -``` - - -[[Return to contents]](#Contents) - -## ResourceFilter -```v -struct ResourceFilter { -pub mut: - free_mru_gb u64 - free_sru_gb u64 - free_hru_gb u64 - free_ips u64 -} -``` - - -[[Return to contents]](#Contents) - -## StatFilter -```v -struct StatFilter { -pub mut: - status NodeStatus -} -``` - - -[[Return to contents]](#Contents) - -## Twin -```v -struct Twin { -pub: - twin_id u64 [json: twinId] - account_id string [json: accountId] - ip string -} -``` - - -[[Return to contents]](#Contents) - -## TwinFilter -```v -struct TwinFilter { -pub mut: - page OptionU64 = EmptyOption{} - size OptionU64 = EmptyOption{} - ret_count OptionBool = EmptyOption{} - randomize OptionBool = EmptyOption{} - twin_id OptionU64 = EmptyOption{} - account_id string - relay string - public_key string -} -``` - - -[[Return to contents]](#Contents) - -## to_map -```v -fn (p &TwinFilter) to_map() map[string]string -``` - -serialize TwinFilter to map - -[[Return to contents]](#Contents) - -## TwinIterator -```v -struct TwinIterator { -pub mut: - filter TwinFilter -pub: - get_func TwinGetter -} -``` - - -[[Return to contents]](#Contents) - -## next -```v -fn (mut i TwinIterator) next() ?[]Twin -``` - - -[[Return to contents]](#Contents) - -#### Powered by vdoc. Generated on: 21 Aug 2023 13:39:52 diff --git a/3bot/vgrid/gridproxy/gridproxy_core.v b/3bot/vgrid/gridproxy/gridproxy_core.v deleted file mode 100644 index ef400d801..000000000 --- a/3bot/vgrid/gridproxy/gridproxy_core.v +++ /dev/null @@ -1,446 +0,0 @@ -module gridproxy - -// client library for threefold gridproxy API. -import json -import gridproxy.model { Contract, ContractFilter, ContractIterator, Farm, FarmFilter, FarmIterator, GridStat, Node, NodeFilter, NodeIterator, NodeStats, 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. -{ - msg string - code int // could be API call error code or client error code -} - -`code` is an error code that can be used to identify the error. -in API call errors, `code` represents the HTTP status code. (100..599) - -Client errors codes are represented by numbers in the range of 1..99 -currently, the following client error codes are used: -id not found error code: 4 -json parsing error code: 10 -http client error code: 11 -invalid response from server (e.g. empty response) error code: 24 -*/ -const ( - // clinet error codes - err_not_found = 4 - err_json_parse = 10 - err_http_client = 11 - err_invalid_resp = 24 - err_grid_client = 30 -) - -// get_node_by_id fetchs specific node information by node id. -// -// * `node_id` (u64): node id. -// -// returns: `Node` or `Error`. -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()! - - 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() { - return error_with_code(res.data, res.code) - } - - if res.data == '' { - return error_with_code('empty response', gridproxy.err_invalid_resp) - } - - node := json.decode(model.Node, res.data) or { - 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 -} - -// get_node_stats_by_id fetchs specific node statistics by node id. -// -// * `node_id` (u64): node id. -// -// returns: `Node_stats` or `Error`. -pub fn (mut c GridProxyClient) get_node_stats_by_id(node_id u64) !NodeStats { - // needed to allow to use threads - mut http_client := c.http_client.clone()! - - res := http_client.send(prefix: 'nodes/', id: '${node_id}/statistics') or { - return error_with_code('http client error: ${err.msg()}', gridproxy.err_http_client) - } - - if !res.is_ok() { - return error_with_code(res.data, res.code) - } - - if res.data == '' { - return error_with_code('empty response', gridproxy.err_invalid_resp) - } - - node_stats := json.decode(model.NodeStats, res.data) or { - 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_stats -} - -// get_gateway_by_id fetchs specific gateway information by node id. -// -// * `node_id` (u64): node id. -// -// returns: `Node` or `Error`. -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()! - - 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() { - return error_with_code(res.data, res.code) - } - - if res.data == '' { - return error_with_code('empty response', gridproxy.err_invalid_resp) - } - - node := json.decode(model.Node, res.data) or { - 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 -} - -// get_nodes fetchs nodes information and public configurations with pagination. -// -// * `available_for` (u64): Available for twin id. [optional]. -// * `certification_type` (string): Certificate type NotCertified, Silver or Gold. [optional]. -// * `city_contains` (string): Node partial city filter. [optional]. -// * `city` (string): Node city filter. [optional]. -// * `country_contains` (string): Node partial country filter. [optional]. -// * `country` (string): Node country filter. [optional]. -// * `dedicated` (bool): Set to true to get the dedicated nodes only. [optional]. -// * `domain` (string): Set to true to filter nodes with domain. [optional]. -// * `farm_ids` ([]u64): List of farm ids. [optional]. -// * `farm_name_contains` (string): Get nodes for specific farm. [optional]. -// * `farm_name` (string): Get nodes for specific farm. [optional]. -// * `free_hru` (u64): Min free reservable hru in bytes. [optional]. -// * `free_ips` (u64): Min number of free ips in the farm of the node. [optional]. -// * `free_mru` (u64): Min free reservable mru in bytes. [optional]. -// * `free_sru` (u64): Min free reservable sru in bytes. [optional]. -// * `gpu_available` (bool): Filter nodes that have available GPU. [optional]. -// * `gpu_device_id` (string): Filter nodes based on GPU device ID. [optional]. -// * `gpu_device_name` (string): Filter nodes based on GPU device partial name. [optional]. -// * `gpu_vendor_id` (string): Filter nodes based on GPU vendor ID. [optional]. -// * `gpu_vendor_name` (string): Filter nodes based on GPU vendor partial name. [optional]. -// * `has_gpu`: Filter nodes on whether they have GPU support or not. [optional]. -// * `ipv4` (string): Set to true to filter nodes with ipv4. [optional]. -// * `ipv6` (string): Set to true to filter nodes with ipv6. [optional]. -// * `node_id` (u64): Node id. [optional]. -// * `page` (u64): Page number. [optional]. -// * `rentable` (bool): Set to true to filter the available nodes for renting. [optional]. -// * `rented_by` (u64): Rented by twin id. [optional]. -// * `ret_count` (bool): Set nodes' count on headers based on filter. [optional]. -// * `size` (u64): Max result per page. [optional]. -// * `status` (string): Node status filter, set to 'up' to get online nodes only. [optional]. -// * `total_cru` (u64): Min total cru in bytes. [optional]. -// * `total_hru` (u64): Min total hru in bytes. [optional]. -// * `total_mru` (u64): Min total mru in bytes. [optional]. -// * `total_sru` (u64): Min total sru in bytes. [optional]. -// * `twin_id` (u64): Twin id. [optional]. -// -// returns: `[]Node` or `Error`. -pub fn (mut c GridProxyClient) get_nodes(params NodeFilter) ![]Node { - // needed to allow to use threads - 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) - } - - if !res.is_ok() { - return error_with_code(res.data, res.code) - } - - if res.data == '' { - return error_with_code('empty response', gridproxy.err_invalid_resp) - } - - nodes_ := json.decode([]model.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}', - gridproxy.err_json_parse) - } - nodes := nodes_.map(it.with_nested_capacity()) - return nodes -} - -// get_gateways fetchs gateways information and public configurations and domains with pagination. -// -// * `available_for` (u64): Available for twin id. [optional]. -// * `certification_type` (string): Certificate type NotCertified, Silver or Gold. [optional]. -// * `city_contains` (string): Node partial city filter. [optional]. -// * `city` (string): Node city filter. [optional]. -// * `country_contains` (string): Node partial country filter. [optional]. -// * `country` (string): Node country filter. [optional]. -// * `dedicated` (bool): Set to true to get the dedicated nodes only. [optional]. -// * `domain` (string): Set to true to filter nodes with domain. [optional]. -// * `farm_ids` ([]u64): List of farm ids. [optional]. -// * `farm_name_contains` (string): Get nodes for specific farm. [optional]. -// * `farm_name` (string): Get nodes for specific farm. [optional]. -// * `free_hru` (u64): Min free reservable hru in bytes. [optional]. -// * `free_ips` (u64): Min number of free ips in the farm of the node. [optional]. -// * `free_mru` (u64): Min free reservable mru in bytes. [optional]. -// * `free_sru` (u64): Min free reservable sru in bytes. [optional]. -// * `gpu_available` (bool): Filter nodes that have available GPU. [optional]. -// * `gpu_device_id` (string): Filter nodes based on GPU device ID. [optional]. -// * `gpu_device_name` (string): Filter nodes based on GPU device partial name. [optional]. -// * `gpu_vendor_id` (string): Filter nodes based on GPU vendor ID. [optional]. -// * `gpu_vendor_name` (string): Filter nodes based on GPU vendor partial name. [optional]. -// * `has_gpu`: Filter nodes on whether they have GPU support or not. [optional]. -// * `ipv4` (string): Set to true to filter nodes with ipv4. [optional]. -// * `ipv6` (string): Set to true to filter nodes with ipv6. [optional]. -// * `node_id` (u64): Node id. [optional]. -// * `page` (u64): Page number. [optional]. -// * `rentable` (bool): Set to true to filter the available nodes for renting. [optional]. -// * `rented_by` (u64): Rented by twin id. [optional]. -// * `ret_count` (bool): Set nodes' count on headers based on filter. [optional]. -// * `size` (u64): Max result per page. [optional]. -// * `status` (string): Node status filter, set to 'up' to get online nodes only. [optional]. -// * `total_cru` (u64): Min total cru in bytes. [optional]. -// * `total_hru` (u64): Min total hru in bytes. [optional]. -// * `total_mru` (u64): Min total mru in bytes. [optional]. -// * `total_sru` (u64): Min total sru in bytes. [optional]. -// * `twin_id` (u64): Twin id. [optional]. -// -// returns: `[]Node` or `Error`. -pub fn (mut c GridProxyClient) get_gateways(params NodeFilter) ![]Node { - // needed to allow to use threads - 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) - } - - if !res.is_ok() { - return error_with_code(res.data, res.code) - } - - if res.data == '' { - return error_with_code('empty response', gridproxy.err_invalid_resp) - } - - nodes_ := json.decode([]model.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}', - gridproxy.err_json_parse) - } - nodes := nodes_.map(it.with_nested_capacity()) - return nodes -} - -// get_stats fetchs stats about the grid. -// -// * `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 { - // needed to allow to use threads - mut http_client := c.http_client.clone()! - mut params_map := map[string]string{} - params_map['status'] = match filter.status { - .all { '' } - .online { 'up' } - } - - res := http_client.send(prefix: 'stats/', params: params_map) or { - return error_with_code('http client error: ${err.msg()}', gridproxy.err_http_client) - } - - if !res.is_ok() { - return error_with_code(res.data, res.code) - } - - if res.data == '' { - return error_with_code('empty response', gridproxy.err_invalid_resp) - } - - stats := json.decode(model.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}', - gridproxy.err_json_parse) - } - return stats -} - -// get_twins fetchs twins information with pagaination. -// -// * `account_id` (string): Account address. [optional]. -// * `page` (u64): Page number. [optional]. -// * `public_key` (string): twin public key used for e2e encryption. [optional]. -// * `relay` (string): relay domain name. [optional]. -// * `ret_count` (bool): Set farms' count on headers based on filter. [optional]. -// * `size` (u64): Max result per page. [optional]. -// * `twin_id` (u64): Twin id. [optional]. -// -// returns: `[]Twin` or `Error`. -pub fn (mut c GridProxyClient) get_twins(params TwinFilter) ![]Twin { - // needed to allow to use threads - 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) - } - - if !res.is_ok() { - return error_with_code(res.data, res.code) - } - - if res.data == '' { - return error_with_code('empty response', gridproxy.err_invalid_resp) - } - - twins := json.decode([]model.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}', - gridproxy.err_json_parse) - } - return twins -} - -// get_contracts fetchs contracts information with pagination. -// -// * `contract_id` (u64): Contract id. [optional]. -// * `contract_type` (string): [optional]. -// * `deployment_data` (string): Contract deployment data in case of 'node' contracts. [optional]. -// * `deployment_hash` (string): Contract deployment hash in case of 'node' contracts. [optional]. -// * `name` (string): Contract name in case of 'name' contracts. [optional]. -// * `node_id` (u64): Node id which contract is deployed on in case of ('rent' or 'node' contracts). [optional]. -// * `number_of_public_ips` (u64): Min number of public ips in the 'node' contract. [optional]. -// * `page` (u64): Page number. [optional]. -// * `randomize` (bool): [optional]. -// * `ret_count` (bool): Set farms' count on headers based on filter. [optional]. -// * `size` (u64): Max result per page. [optional]. -// * `state` (string): Contract state 'Created', or 'Deleted'. [optional]. -// * `twin_id` (u64): Twin id. [optional]. -// * `type` (string): Contract type 'node', 'name', or 'rent'. [optional]. -// -// * returns: `[]Contract` or `Error`. -pub fn (mut c GridProxyClient) get_contracts(params ContractFilter) ![]Contract { - // needed to allow to use threads - 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) - } - - if !res.is_ok() { - return error_with_code(res.data, res.code) - } - - if res.data == '' { - return error_with_code('empty response', gridproxy.err_invalid_resp) - } - - contracts := json.decode([]model.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}', - gridproxy.err_json_parse) - } - return contracts -} - -// get_farms fetchs farms information and public ips. -// -// * `certification_type` (string): Certificate type DIY or Certified. [optional]. -// * `country` (string): Farm country. [optional]. -// * `dedicated` (bool): Farm is dedicated. [optional]. -// * `farm_id` (u64): Farm id. [optional]. -// * `free_ips` (u64): Min number of free ips in the farm. [optional]. -// * `name_contains` (string): Farm name contains. [optional]. -// * `name` (string): Farm name. [optional]. -// * `node_available_for` (u64): Twin ID of user for whom there is at least one node that is available to be deployed to in the farm. [optional]. -// * `node_certified` (bool): True for farms who have at least one certified node. [optional]. -// * `node_free_hru` (u64): Min free reservable hru for at least a single node that belongs to the farm, in bytes. [optional]. -// * `node_free_mru` (u64): Min free reservable mru for at least a single node that belongs to the farm, in bytes. [optional]. -// * `node_free_sru` (u64): Min free reservable sru for at least a single node that belongs to the farm, in bytes. [optional]. -// * `node_has_gpu` (bool): True for farms who have at least one node with a GPU -// * `node_rented_by` (u64): Twin ID of user who has at least one rented node in the farm -// * `node_status` (string): Node status for at least a single node that belongs to the farm -// * `page` (u64): Page number. [optional]. -// * `pricing_policy_id` (u64): Pricing policy id. [optional]. -// * `randomize` (bool): [optional]. -// * `ret_count` (bool): Set farms' count on headers based on filter. [optional]. -// * `size` (u64): Max result per page. [optional]. -// * `stellar_address` (string): Farm stellar_address. [optional]. -// * `total_ips` (u64): Min number of total ips in the farm. [optional]. -// * `twin_id` (u64): Twin id associated with the farm. [optional]. -// * `version` (u64): Farm version. [optional]. -// -// returns: `[]Farm` or `Error`. -pub fn (mut c GridProxyClient) get_farms(params FarmFilter) ![]Farm { - // needed to allow to use threads - 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) - } - - if !res.is_ok() { - return error_with_code(res.data, res.code) - } - - if res.data == '' { - return error_with_code('empty response', gridproxy.err_invalid_resp) - } - - farms := json.decode([]model.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}', - gridproxy.err_json_parse) - } - return farms -} - -// 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()! - res := http_client.send(prefix: 'ping/') or { return false } - if !res.is_ok() { - return false - } - health_map := json.decode(map[string]string, res.data) or { return false } - - if health_map['ping'] != 'pong' { - return false - } - - 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. - -// get_nodes_iterator creates an iterator through node pages with custom filter -pub fn (mut c GridProxyClient) get_nodes_iterator(filter NodeFilter) NodeIterator { - return NodeIterator{filter, c.get_nodes} -} - -// get_gateways_iterator creates an iterator through gateway pages with custom filter -pub fn (mut c GridProxyClient) get_gateways_iterator(filter NodeFilter) NodeIterator { - return NodeIterator{filter, c.get_gateways} -} - -// get_farms_iterator creates an iterator through farms pages with custom filter -pub fn (mut c GridProxyClient) get_farms_iterator(filter FarmFilter) FarmIterator { - return FarmIterator{filter, c.get_farms} -} - -// get_twins_iterator creates an iterator through twin pages with custom filter -pub fn (mut c GridProxyClient) get_twins_iterator(filter TwinFilter) TwinIterator { - return TwinIterator{filter, c.get_twins} -} - -// get_contracts_iterator creates an iterator through contracts pages with custom filter -pub fn (mut c GridProxyClient) get_contracts_iterator(filter ContractFilter) ContractIterator { - return ContractIterator{filter, c.get_contracts} -} diff --git a/3bot/vgrid/gridproxy/gridproxy_factory.v b/3bot/vgrid/gridproxy/gridproxy_factory.v deleted file mode 100644 index cff03c571..000000000 --- a/3bot/vgrid/gridproxy/gridproxy_factory.v +++ /dev/null @@ -1,79 +0,0 @@ -module gridproxy - -import freeflowuniverse.crystallib.httpconnection - -[heap] -pub struct GridProxyClient { -pub mut: - http_client httpconnection.HTTPConnection -} - -pub enum TFGridNet { - main - test - dev - qa -} - -[heap] -struct GridproxyFactory { -mut: - instances map[string]&GridProxyClient -} - -fn init_factory() GridproxyFactory { - mut ef := GridproxyFactory{} - return ef -} - -// Singleton creation -const factory = init_factory() - -fn factory_get() &GridproxyFactory { - return &gridproxy.factory -} - -fn gridproxy_url_get(net TFGridNet) string { - return match net { - .main { 'https://gridproxy.grid.tf' } - .test { 'https://gridproxy.test.grid.tf' } - .dev { 'https://gridproxy.dev.grid.tf' } - .qa { 'https://gridproxy.qa.grid.tf/' } - } -} - -// return which net in string form -fn tfgrid_net_string(net TFGridNet) string { - return match net { - .main { 'main' } - .test { 'test' } - .dev { 'dev' } - .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 { - mut f := factory_get() - netstr := tfgrid_net_string(net) - if netstr !in gridproxy.factory.instances { - url := gridproxy_url_get(net) - 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{ - http_client: httpconn - } - f.instances[netstr] = &connection - } - return f.instances[netstr] or { return error_with_code('http client error: unknow error happened while trying to access the GridProxyClient instance', err_grid_client) } -} diff --git a/3bot/vgrid/gridproxy/gridproxy_highlevel.v b/3bot/vgrid/gridproxy/gridproxy_highlevel.v deleted file mode 100644 index 959e0554c..000000000 --- a/3bot/vgrid/gridproxy/gridproxy_highlevel.v +++ /dev/null @@ -1,130 +0,0 @@ -module gridproxy - -import gridproxy.model { ContractFilter, ContractIterator, Farm, FarmFilter, FarmIterator, NodeFilter, NodeIterator, ResourceFilter, Twin } - -// fetch specific twin information by twin id. -// -// * `twin_id`: twin id. -// -// returns: `Twin` or `Error`. -pub fn (mut c GridProxyClient) get_twin_by_id(twin_id u64) !Twin { - twins := c.get_twins(twin_id: twin_id) or { - return error_with_code('http client error: ${err.msg()}', err_http_client) - } - if twins.len == 0 { - return error_with_code('no twin found for id: ${twin_id}', err_not_found) - } - return twins[0] -} - -// fetch specific twin information by account. -// -// * `account_id`: account id. -// -// returns: `Twin` or `Error`. -pub fn (mut c GridProxyClient) get_twin_by_account(account_id string) !Twin { - twins := c.get_twins(account_id: account_id) or { - return error_with_code('http client error: ${err.msg()}', err_http_client) - } - if twins.len == 0 { - return error_with_code('no twin found for account_id: ${account_id}', err_not_found) - } - return twins[0] -} - -// fetch specific farm information by id. -// -// * `farm_id`: farm id. -// -// returns: `Farm` or `Error`. -pub fn (mut c GridProxyClient) get_farm_by_id(farm_id u64) !Farm { - farms := c.get_farms(farm_id: farm_id) or { - return error_with_code('http client error: ${err.msg()}', err_http_client) - } - if farms.len == 0 { - return error_with_code('no farm found for id: ${farm_id}', err_not_found) - } - return farms[0] -} - -// fetch specific farm information by farm name. -// -// * `farm_name`: farm name. -// -// returns: `Farm` or `Error`. -pub fn (mut c GridProxyClient) get_farm_by_name(farm_name string) !Farm { - farms := c.get_farms(name: farm_name) or { - return error_with_code('http client error: ${err.msg()}', err_http_client) - } - if farms.len == 0 { - return error_with_code('no farm found with name: ${farm_name}', err_not_found) - } - return farms[0] -} - -// get_farms_by_twin_id returns iterator over all farms information associated with specific twin. -// -// * `twin_id`: twin id. -// -// returns: `FarmIterator`. -pub fn (mut c GridProxyClient) get_farms_by_twin_id(twin_id u64) FarmIterator { - mut filter := FarmFilter{ - twin_id: twin_id - } - mut iter := c.get_farms_iterator(filter) - return iter -} - -// get_contracts_by_twin_id returns iterator over all contracts owned by specific twin. -// -// * `twin_id`: twin id. -// -// returns: `ContractIterator`. -pub fn (mut c GridProxyClient) get_contracts_by_twin_id(twin_id u64) ContractIterator { - /* - contracts := c.get_contracts(twin_id: twin_id) or { - return error_with_code('http client error: $err.msg()', gridproxy.err_http_client) - }*/ - mut filter := ContractFilter{ - twin_id: twin_id - } - mut iter := c.get_contracts_iterator(filter) - return iter -} - -// get_contracts_by_node_id returns iterator over all contracts deployed on specific node. -// -// * `node_id`: node id. -// -// returns: `ContractIterator`. -pub fn (mut c GridProxyClient) get_contracts_by_node_id(node_id u64) ContractIterator { - /* - contracts := c.get_contracts(node_id: node_id) or { - return error_with_code('http client error: $err.msg()', gridproxy.err_http_client) - }*/ - mut filter := ContractFilter{ - node_id: node_id - } - mut iter := c.get_contracts_iterator(filter) - return iter -} - -// get_nodes_has_resources returns iterator over all nodes with specific minimum free reservable resources. -// -// * `free_ips` (u64): minimum free ips. [optional]. -// * `free_mru_gb` (u64): minimum free mru in GB. [optional]. -// * `free_sru_gb` (u64): minimum free sru in GB. [optional]. -// * `free_hru_gb` (u64): minimum free hru in GB. [optional]. -// -// returns: `NodeIterator`. -pub fn (mut c GridProxyClient) get_nodes_has_resources(filter ResourceFilter) NodeIterator { - mut filter_ := NodeFilter{ - free_ips: filter.free_ips - free_mru: filter.free_mru_gb * (1204 * 1204 * 1204 * 1204) - free_sru: filter.free_sru_gb * (1204 * 1204 * 1204 * 1204) - free_hru: filter.free_hru_gb * (1204 * 1204 * 1204 * 1204) - } - mut iter := c.get_nodes_iterator(filter_) - - return iter -} diff --git a/3bot/vgrid/gridproxy/gridproxy_test.v b/3bot/vgrid/gridproxy/gridproxy_test.v deleted file mode 100644 index b83200559..000000000 --- a/3bot/vgrid/gridproxy/gridproxy_test.v +++ /dev/null @@ -1,249 +0,0 @@ -module gridproxy - -import gridproxy.model -import time - -const ( - cache = false - dummy_node = model.Node{ - id: '0000129706-000001-c1e78' - node_id: 1 - farm_id: 2 - twin_id: 8 - grid_version: 3 - uptime: model.SecondUnit(86400) // 86400 seconds = 1440 minutes = 24 hours = 1 day - created: model.UnixTime(1654848126) // GMT: 2022-06-10 08:02:06 - farming_policy_id: 1 - updated_at: model.UnixTime(1654848132) // GMT: 2022-06-10 08:02:12 - capacity: model.NodeCapacity{ - total_resources: model.NodeResources{ - cru: 4 - mru: model.ByteUnit(5178437632) // 5178437632 bytes = 5178.437632 megabytes = 5.2 gigabytes = 0.005178437632 terabytes - sru: model.ByteUnit(1610612736000) // 1610612736000 bytes = 1610612.736000 megabytes = 1610.612736 gigabytes = 16.1 terabytes - hru: model.ByteUnit(1073741824000) // 1073741824000 bytes = 1073741.824 megabytes = 1073.741824 gigabytes = 10.7 terabytes - } - used_resources: model.NodeResources{ - cru: 0 - mru: model.ByteUnit(0) - sru: model.ByteUnit(0) - hru: model.ByteUnit(0) - } - } - location: model.NodeLocation{ - country: 'Belgium' - city: 'Lochristi' - } - public_config: model.PublicConfig{ - domain: '' - gw4: '' - gw6: '' - ipv4: '' - ipv6: '' - } - certification: 'Diy' - status: 'down' - dedicated: false - rent_contract_id: 0 - rented_by_twin_id: 0 - } - dummy_contract_billing = model.ContractBilling{ - amount_billed: model.DropTFTUnit(10000000) // 1 TFT == 1000 mTFT == 1000000 uTFT - discount_received: 'None' - timestamp: model.UnixTime(1655118966) - } -) - -fn test_create_gridproxy_client_qa() { - mut gp := get(.qa, gridproxy.cache)! - assert gp.is_pingable()! == true -} - -fn test_create_gridproxy_client_dev() { - mut gp := get(.dev, gridproxy.cache)! - assert gp.is_pingable()! == true -} - -fn test_create_gridproxy_client_test() { - mut gp := get(.test, gridproxy.cache)! - assert gp.is_pingable()! == true -} - -fn test_create_gridproxy_client_main() { - mut gp := get(.main, gridproxy.cache)! - assert gp.is_pingable()! == true -} - -fn test_get_nodes_qa() { - mut gp := get(.qa, gridproxy.cache)! - nodes := gp.get_nodes() or { panic('Failed to get nodes') } - assert nodes.len > 0 -} - -fn test_get_nodes_dev() { - mut gp := get(.dev, gridproxy.cache)! - nodes := gp.get_nodes() or { panic('Failed to get nodes') } - assert nodes.len > 0 -} - -fn test_get_nodes_test() { - mut gp := get(.test, gridproxy.cache)! - nodes := gp.get_nodes() or { panic('Failed to get nodes') } - assert nodes.len > 0 -} - -fn test_get_nodes_main() { - mut gp := get(.main, gridproxy.cache)! - nodes := gp.get_nodes() or { panic('Failed to get nodes') } - assert nodes.len > 0 -} - -fn test_get_gateways_qa() { - mut gp := get(.qa, gridproxy.cache)! - nodes := gp.get_gateways() or { panic('Failed to get gateways') } - assert nodes.len > 0 -} - -fn test_get_gateways_dev() { - mut gp := get(.dev, gridproxy.cache)! - nodes := gp.get_gateways() or { panic('Failed to get gateways') } - assert nodes.len > 0 -} - -fn test_get_gateways_test() { - mut gp := get(.test, gridproxy.cache)! - nodes := gp.get_gateways() or { panic('Failed to get gateways') } - assert nodes.len > 0 -} - -fn test_get_gateways_main() { - mut gp := get(.main, gridproxy.cache)! - nodes := gp.get_gateways() or { panic('Failed to get gateways') } - assert nodes.len > 0 -} - -fn test_get_twins_qa() { - mut gp := get(.qa, gridproxy.cache)! - twins := gp.get_twins() or { panic('Failed to get twins') } - assert twins.len > 0 -} - -fn test_get_twins_dev() { - mut gp := get(.dev, gridproxy.cache)! - twins := gp.get_twins() or { panic('Failed to get twins') } - assert twins.len > 0 -} - -fn test_get_twins_test() { - mut gp := get(.test, gridproxy.cache)! - twins := gp.get_twins() or { panic('Failed to get twins') } - assert twins.len > 0 -} - -fn test_get_twins_main() { - mut gp := get(.main, gridproxy.cache)! - twins := gp.get_twins() or { panic('Failed to get twins') } - assert twins.len > 0 -} - -fn test_get_stats_qa() { - mut gp := get(.qa, gridproxy.cache)! - stats := gp.get_stats() or { panic('Failed to get stats') } - assert stats.nodes > 0 -} - -fn test_get_stats_dev() { - mut gp := get(.dev, gridproxy.cache)! - stats := gp.get_stats() or { panic('Failed to get stats') } - assert stats.nodes > 0 -} - -fn test_get_stats_test() { - mut gp := get(.test, gridproxy.cache)! - stats := gp.get_stats() or { panic('Failed to get stats') } - assert stats.nodes > 0 -} - -fn test_get_stats_main() { - mut gp := get(.test, gridproxy.cache)! - stats := gp.get_stats() or { panic('Failed to get stats') } - assert stats.nodes > 0 -} - -fn test_get_contracts_qa() { - mut gp := get(.qa, gridproxy.cache)! - contracts := gp.get_contracts() or { panic('Failed to get contracts') } - assert contracts.len > 0 -} - -fn test_get_contracts_dev() { - mut gp := get(.dev, gridproxy.cache)! - contracts := gp.get_contracts() or { panic('Failed to get contracts') } - assert contracts.len > 0 -} - -fn test_get_contracts_test() { - mut gp := get(.test, gridproxy.cache)! - contracts := gp.get_contracts() or { panic('Failed to get contracts') } - assert contracts.len > 0 -} - -fn test_get_contracts_main() { - mut gp := get(.main, gridproxy.cache)! - contracts := gp.get_contracts() or { panic('Failed to get contracts') } - assert contracts.len > 0 -} - -fn test_get_farms_qa() { - mut gp := get(.qa, gridproxy.cache)! - farms := gp.get_farms() or { panic('Failed to get farms') } - assert farms.len > 0 -} - -fn test_get_farms_dev() { - mut gp := get(.dev, gridproxy.cache)! - farms := gp.get_farms() or { panic('Failed to get farms') } - assert farms.len > 0 -} - -fn test_get_farms_test() { - mut gp := get(.test, gridproxy.cache)! - farms := gp.get_farms() or { panic('Failed to get farms') } - assert farms.len > 0 -} - -fn test_get_farms_main() { - mut gp := get(.main, gridproxy.cache)! - farms := gp.get_farms() or { panic('Failed to get farms') } - assert farms.len > 0 -} - -fn test_elapsed_seconds_conversion() { - assert gridproxy.dummy_node.uptime.to_minutes() == 1440 - assert gridproxy.dummy_node.uptime.to_hours() == 24 - assert gridproxy.dummy_node.uptime.to_days() == 1 -} - -fn test_timestamp_conversion() { - assert gridproxy.dummy_node.created.to_time() == time.unix(1654848126) - assert gridproxy.dummy_node.updated_at.to_time() == time.unix(1654848132) -} - -fn test_storage_unit_conversion() { - assert gridproxy.dummy_node.capacity.total_resources.mru.to_megabytes() == 5178.437632 - assert gridproxy.dummy_node.capacity.total_resources.mru.to_gigabytes() == 5.178437632 - assert gridproxy.dummy_node.capacity.total_resources.mru.to_terabytes() == 0.005178437632 -} - -fn test_tft_conversion() { - assert gridproxy.dummy_contract_billing.amount_billed.to_tft() == 1 - assert gridproxy.dummy_contract_billing.amount_billed.to_mtft() == 1000 - assert gridproxy.dummy_contract_billing.amount_billed.to_utft() == 1000000 -} - -fn test_calc_available_resources_on_node() { - // dummy node was created with 0 used resources - assert gridproxy.dummy_node.calc_available_resources().mru == gridproxy.dummy_node.capacity.total_resources.mru - assert gridproxy.dummy_node.calc_available_resources().hru == gridproxy.dummy_node.capacity.total_resources.hru - assert gridproxy.dummy_node.calc_available_resources().sru == gridproxy.dummy_node.capacity.total_resources.sru - assert gridproxy.dummy_node.calc_available_resources().cru == gridproxy.dummy_node.capacity.total_resources.cru -} diff --git a/3bot/vgrid/gridproxy/model/contract.v b/3bot/vgrid/gridproxy/model/contract.v deleted file mode 100644 index c124dc14f..000000000 --- a/3bot/vgrid/gridproxy/model/contract.v +++ /dev/null @@ -1,46 +0,0 @@ -module model - -pub struct ContractBilling { -pub: - amount_billed DropTFTUnit [json: amountBilled] - discount_received string [json: discountReceived] - timestamp UnixTime [json: timestamp] -} - -pub struct NodeContractDetails { -pub: - node_id u64 [json: nodeId] - deployment_data string [json: deployment_data] - deployment_hash string [json: deployment_hash] - number_of_public_ips u64 [json: number_of_public_ips] -} - -pub struct Contract { -pub: - contract_id u64 [json: contractId] - twin_id u64 [json: twinId] - state string [json: state] - created_at UnixTime [json: created_at] - contract_type string [json: 'type'] - details NodeContractDetails [json: details] - billing []ContractBilling [json: billing] -} - -// total_billed returns the total amount billed for the contract. -// -// returns: `DropTFTUnit` -pub fn (c &Contract) total_billed() DropTFTUnit { - if c.billing.len == 0 { - return 0 - } - mut total := u64(0) - for b in c.billing { - total += b.amount_billed - } - return DropTFTUnit(total) -} - -// TODO: Implement Limit struct (size, page, retcount, randomize) -// and embeded it in other structs like Contract to avoid duplicated code -// TODO: check if RetCount is bool or string as swagger doc says -// TODO: check if Randomize can be used in the client and where, it is not documnetd in swagger diff --git a/3bot/vgrid/gridproxy/model/farm.v b/3bot/vgrid/gridproxy/model/farm.v deleted file mode 100644 index 167d7c77c..000000000 --- a/3bot/vgrid/gridproxy/model/farm.v +++ /dev/null @@ -1,22 +0,0 @@ -module model - -pub struct PublicIP { -pub: - id string - ip string - farm_id string [json: farmId] - contract_id int [json: contractId] - gateway string -} - -pub struct Farm { -pub: - name string - farm_id u64 [json: farmId] - twin_id u64 [json: twinId] - pricing_policy_id u64 [json: pricingPolicyId] - certification_type string [json: certificationType] - stellar_address string [json: stellarAddress] - dedicated bool - public_ips []PublicIP [json: publicIps] -} diff --git a/3bot/vgrid/gridproxy/model/filter.v b/3bot/vgrid/gridproxy/model/filter.v deleted file mode 100644 index 2d502a1c7..000000000 --- a/3bot/vgrid/gridproxy/model/filter.v +++ /dev/null @@ -1,555 +0,0 @@ -module model - -import json - -type OptionU64 = EmptyOption | u64 -type OptionBool = EmptyOption | bool - -[params] -pub struct FarmFilter { -pub mut: - page OptionU64 = EmptyOption{} - size OptionU64 = EmptyOption{} - ret_count OptionBool = EmptyOption{} - randomize 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{} - country string - node_free_mru OptionU64 = EmptyOption{} - node_free_hru OptionU64 = EmptyOption{} - node_free_sru OptionU64 = EmptyOption{} - node_status string - node_rented_by OptionU64 = EmptyOption{} - node_available_for OptionU64 = EmptyOption{} - node_has_gpu OptionBool = EmptyOption{} - node_certified 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 { - m['page'] = f.page.str() - } - } - match f.size { - EmptyOption {} - u64 { - m['size'] = f.size.str() - } - } - match f.ret_count { - EmptyOption {} - bool { - m['ret_count'] = f.ret_count.str() - } - } - match f.randomize { - EmptyOption {} - bool { - m['randomize'] = f.randomize.str() - } - } - match f.free_ips { - EmptyOption {} - u64 { - m['free_ips'] = f.free_ips.str() - } - } - match f.total_ips { - EmptyOption {} - u64 { - m['total_ips'] = f.total_ips.str() - } - } - if f.stellar_address != '' { - m['stellar_address'] = f.stellar_address - } - match f.pricing_policy_id { - EmptyOption {} - u64 { - m['pricing_policy_id'] = f.pricing_policy_id.str() - } - } - match f.farm_id { - EmptyOption {} - u64 { - m['farm_id'] = f.farm_id.str() - } - } - match f.twin_id { - EmptyOption {} - u64 { - m['twin_id'] = f.twin_id.str() - } - } - - if f.name != '' { - m['name'] = f.name - } - if f.name_contains != '' { - m['name_contains'] = f.name_contains - } - if f.certification_type != '' { - m['certification_type'] = f.certification_type - } - match f.dedicated { - EmptyOption {} - bool { - m['dedicated'] = f.dedicated.str() - } - } - match f.node_available_for { - EmptyOption {} - u64 { - m['node_available_for'] = f.node_available_for.str() - } - } - match f.node_free_hru { - EmptyOption {} - u64 { - m['node_free_hru'] = f.node_free_hru.str() - } - } - match f.node_free_mru { - EmptyOption {} - u64 { - m['node_free_mru'] = f.node_free_mru.str() - } - } - match f.node_free_sru { - EmptyOption {} - u64 { - m['node_free_sru'] = f.node_free_sru.str() - } - } - match f.node_rented_by { - EmptyOption {} - u64 { - m['node_rented_by'] = f.node_rented_by.str() - } - } - match f.node_has_gpu { - EmptyOption {} - bool { - m['node_has_gpu'] = f.node_has_gpu.str() - } - } - match f.node_certified { - EmptyOption {} - bool { - m['node_certified'] = f.node_certified.str() - } - } - if f.node_status != '' { - m['node_status'] = f.node_status - } - return m -} - -[params] -pub struct ContractFilter { -pub mut: - page OptionU64 = EmptyOption{} - size OptionU64 = EmptyOption{} - ret_count OptionBool = EmptyOption{} - randomize 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 -pub fn (f &ContractFilter) to_map() map[string]string { - mut m := map[string]string{} - match f.page { - EmptyOption {} - u64 { - m['page'] = f.page.str() - } - } - match f.size { - EmptyOption {} - u64 { - m['size'] = f.size.str() - } - } - match f.ret_count { - EmptyOption {} - bool { - m['ret_count'] = f.ret_count.str() - } - } - match f.randomize { - EmptyOption {} - bool { - m['randomize'] = f.randomize.str() - } - } - match f.contract_id { - EmptyOption {} - u64 { - m['contract_id'] = f.contract_id.str() - } - } - match f.twin_id { - EmptyOption {} - u64 { - m['twin_id'] = f.twin_id.str() - } - } - match f.node_id { - EmptyOption {} - u64 { - m['node_id'] = f.node_id.str() - } - } - if f.contract_type != '' { - m['contract_type'] = f.contract_type - } - if f.state != '' { - m['state'] = f.state - } - if f.name != '' { - m['name'] = f.name - } - match f.number_of_public_ips { - EmptyOption {} - u64 { - m['number_of_public_ips'] = f.number_of_public_ips.str() - } - } - if f.deployment_data != '' { - m['deployment_data'] = f.deployment_data - } - if f.deployment_hash != '' { - m['deployment_hash'] = f.deployment_hash - } - return m -} - -[params] -pub struct NodeFilter { -pub mut: - page OptionU64 = EmptyOption{} - size OptionU64 = EmptyOption{} - ret_count OptionBool = EmptyOption{} - randomize OptionBool = EmptyOption{} - free_mru OptionU64 = EmptyOption{} - free_sru OptionU64 = EmptyOption{} - free_hru OptionU64 = EmptyOption{} - free_ips OptionU64 = EmptyOption{} - total_mru OptionU64 = EmptyOption{} - total_sru OptionU64 = EmptyOption{} - total_hru OptionU64 = EmptyOption{} - total_cru OptionU64 = EmptyOption{} - city string - city_contains string - country string - country_contains string - farm_name string - farm_name_contains string - ipv4 OptionBool = EmptyOption{} - ipv6 OptionBool = EmptyOption{} - domain OptionBool = EmptyOption{} - status string - dedicated OptionBool = EmptyOption{} - rentable OptionBool = EmptyOption{} - rented_by OptionU64 = EmptyOption{} - rented OptionBool = EmptyOption{} - available_for OptionU64 = EmptyOption{} - farm_ids []u64 - node_id OptionU64 = EmptyOption{} - twin_id OptionU64 = EmptyOption{} - certification_type string - has_gpu OptionBool = EmptyOption{} - gpu_device_id string - gpu_device_name string - gpu_vendor_id string - gpu_vendor_name string - gpu_available OptionBool = EmptyOption{} -} - -// serialize NodeFilter to map -pub fn (p &NodeFilter) to_map() map[string]string { - mut m := map[string]string{} - match p.page { - EmptyOption {} - u64 { - m['page'] = p.page.str() - } - } - match p.size { - EmptyOption {} - u64 { - m['size'] = p.size.str() - } - } - match p.ret_count { - EmptyOption {} - bool { - m['ret_count'] = p.ret_count.str() - } - } - match p.randomize { - EmptyOption {} - bool { - m['randomize'] = p.randomize.str() - } - } - match p.free_mru { - EmptyOption {} - u64 { - m['free_mru'] = p.free_mru.str() - } - } - match p.free_sru { - EmptyOption {} - u64 { - m['free_sru'] = p.free_sru.str() - } - } - match p.free_hru { - EmptyOption {} - u64 { - m['free_hru'] = p.free_hru.str() - } - } - match p.free_ips { - EmptyOption {} - u64 { - m['free_ips'] = p.free_ips.str() - } - } - match p.total_cru { - EmptyOption {} - u64 { - m['total_cru'] = p.total_cru.str() - } - } - match p.total_hru { - EmptyOption {} - u64 { - m['total_hru'] = p.total_hru.str() - } - } - match p.total_mru { - EmptyOption {} - u64 { - m['total_mru'] = p.total_mru.str() - } - } - match p.total_sru { - EmptyOption {} - u64 { - m['total_sru'] = p.total_sru.str() - } - } - if p.status != '' { - m['status'] = p.status - } - if p.city != '' { - m['city'] = p.city - } - if p.city_contains != '' { - m['city_contains'] = p.city_contains - } - if p.country != '' { - m['country'] = p.country - } - if p.country_contains != '' { - m['country_contains'] = p.country_contains - } - if p.farm_name != '' { - m['farm_name'] = p.farm_name - } - if p.farm_name_contains != '' { - m['farm_name_contains'] = p.farm_name_contains - } - match p.ipv4 { - EmptyOption {} - bool { - m['ipv4'] = p.ipv4.str() - } - } - match p.ipv6 { - EmptyOption {} - bool { - m['ipv6'] = p.ipv6.str() - } - } - match p.domain { - EmptyOption {} - bool { - m['domain'] = p.domain.str() - } - } - match p.dedicated { - EmptyOption {} - bool { - m['dedicated'] = p.dedicated.str() - } - } - match p.rentable { - EmptyOption {} - bool { - m['rentable'] = p.rentable.str() - } - } - match p.rented_by { - EmptyOption {} - u64 { - m['rented_by'] = p.rented_by.str() - } - } - match p.rented { - EmptyOption {} - bool { - m['rented'] = p.rented.str() - } - } - match p.available_for { - EmptyOption {} - u64 { - m['available_for'] = p.available_for.str() - } - } - if p.farm_ids.len > 0 { - m['farm_ids'] = json.encode(p.farm_ids).all_after('[').all_before(']') - } - match p.node_id { - EmptyOption {} - u64 { - m['node_id'] = p.node_id.str() - } - } - match p.twin_id { - EmptyOption {} - u64 { - m['twin_id'] = p.twin_id.str() - } - } - if p.certification_type != '' { - m['certification_type'] = p.certification_type - } - match p.has_gpu { - EmptyOption {} - bool { - m['has_gpu'] = p.has_gpu.str() - } - } - if p.gpu_device_id != '' { - m['gpu_device_id'] = p.gpu_device_id - } - if p.gpu_device_name != '' { - m['gpu_device_name'] = p.gpu_device_name - } - if p.gpu_vendor_id != '' { - m['gpu_vendor_id'] = p.gpu_vendor_id - } - if p.gpu_vendor_name != '' { - m['gpu_vendor_name'] = p.gpu_vendor_name - } - match p.gpu_available { - EmptyOption {} - bool { - m['gpu_available'] = p.gpu_available.str() - } - } - return m -} - -pub enum NodeStatus { - all - online -} - -[params] -pub struct ResourceFilter { -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 -} - -[params] -pub struct TwinFilter { -pub mut: - page OptionU64 = EmptyOption{} - size OptionU64 = EmptyOption{} - ret_count OptionBool = EmptyOption{} - randomize OptionBool = EmptyOption{} - twin_id OptionU64 = EmptyOption{} - account_id string - relay string - public_key string -} - -// serialize TwinFilter to map -pub fn (p &TwinFilter) to_map() map[string]string { - mut m := map[string]string{} - match p.page { - EmptyOption {} - u64 { - m['page'] = p.page.str() - } - } - match p.size { - EmptyOption {} - u64 { - m['size'] = p.size.str() - } - } - match p.ret_count { - EmptyOption {} - bool { - m['ret_count'] = p.ret_count.str() - } - } - match p.randomize { - EmptyOption {} - bool { - m['randomize'] = p.randomize.str() - } - } - match p.twin_id { - EmptyOption {} - u64 { - m['twin_id'] = p.twin_id.str() - } - } - if p.account_id != '' { - m['account_id'] = p.account_id - } - if p.relay != '' { - m['relay'] = p.relay - } - if p.public_key != '' { - m['public_key'] = p.public_key - } - return m -} diff --git a/3bot/vgrid/gridproxy/model/iterators.v b/3bot/vgrid/gridproxy/model/iterators.v deleted file mode 100644 index 9628b7271..000000000 --- a/3bot/vgrid/gridproxy/model/iterators.v +++ /dev/null @@ -1,101 +0,0 @@ -module model - -pub type NodeGetter = fn (NodeFilter) ![]Node - -pub struct NodeIterator { -pub mut: - filter NodeFilter -pub: - get_func NodeGetter [required] -} - -pub fn (mut i NodeIterator) next() ?[]Node { - match i.filter.page { - EmptyOption { - i.filter.page = u64(1) - } - u64 { - i.filter.page = i.filter.page as u64 + 1 - } - } - nodes := i.get_func(i.filter) or { return none } - if nodes.len == 0 { - return none - } - return nodes -} - -pub type FarmGetter = fn (FarmFilter) ![]Farm - -pub struct FarmIterator { -pub mut: - filter FarmFilter -pub: - get_func FarmGetter [required] -} - -pub fn (mut i FarmIterator) next() ?[]Farm { - match i.filter.page { - EmptyOption { - i.filter.page = u64(1) - } - u64 { - i.filter.page = i.filter.page as u64 + 1 - } - } - farms := i.get_func(i.filter) or { return none } - if farms.len == 0 { - return none - } - return farms -} - -pub type ContractGetter = fn (ContractFilter) ![]Contract - -pub struct ContractIterator { -pub mut: - filter ContractFilter -pub: - get_func ContractGetter [required] -} - -pub fn (mut i ContractIterator) next() ?[]Contract { - match i.filter.page { - EmptyOption { - i.filter.page = u64(1) - } - u64 { - i.filter.page = i.filter.page as u64 + 1 - } - } - contracts := i.get_func(i.filter) or { return none } - if contracts.len == 0 { - return none - } - return contracts -} - -pub type TwinGetter = fn (TwinFilter) ![]Twin - -pub struct TwinIterator { -pub mut: - filter TwinFilter -pub: - get_func TwinGetter [required] -} - -pub fn (mut i TwinIterator) next() ?[]Twin { - match i.filter.page { - EmptyOption { - i.filter.page = u64(1) - } - u64 { - i.filter.page = i.filter.page as u64 + 1 - } - } - twins := i.get_func(i.filter) or { return none } - if twins.len == 0 { - return none - } - return twins -} diff --git a/3bot/vgrid/gridproxy/model/model.v b/3bot/vgrid/gridproxy/model/model.v deleted file mode 100644 index 9198cc866..000000000 --- a/3bot/vgrid/gridproxy/model/model.v +++ /dev/null @@ -1,106 +0,0 @@ -module model - -import time { Time } -import math { floor, pow10 } - -type ByteUnit = u64 - -pub fn (u ByteUnit) to_megabytes() f64 { - return f64(u) / 1e+6 -} - -pub fn (u ByteUnit) to_gigabytes() f64 { - return f64(u) / 1e+9 -} - -pub fn (u ByteUnit) to_terabytes() f64 { - return f64(u) / 1e+12 -} - -pub fn (u ByteUnit) str() string { - if u >= 1e+12 { - return '${u.to_terabytes():.2} TB' - } else if u >= 1e+9 { - return '${u.to_gigabytes():.2} GB' - } else if u >= 1e+6 { - return '${u.to_megabytes():.2} MB' - } - return '${u64(u)} Bytes' -} - -// SecondUnit represents a duration in seconds -type SecondUnit = u64 - -pub fn (u SecondUnit) to_minutes() f64 { - return f64(u) / 60 -} - -pub fn (u SecondUnit) to_hours() f64 { - return f64(u) / (60 * 60) -} - -pub fn (u SecondUnit) to_days() f64 { - return f64(u) / (60 * 60 * 24) -} - -pub fn (u SecondUnit) str() string { - sec_num := u64(u) - d := floor(sec_num / 86400) - h := math.fmod(floor(sec_num / 3600), 24) - m := math.fmod(floor(sec_num / 60), 60) - s := sec_num % 60 - mut str := '' - if d > 0 { - str += '${d} days ' - } - if h > 0 { - str += '${h} hours ' - } - if m > 0 { - str += '${m} minutes ' - } - if s > 0 { - str += '${s} seconds' - } - return str -} - -// UnixTime represent time in seconds since epoch (timestamp) -type UnixTime = u64 - -pub fn (t UnixTime) to_time() Time { - return time.unix(t) -} - -pub fn (t UnixTime) str() string { - return '${t.to_time().local()}' -} - -// this is the smallest unit used to calculate the billing and and the one natively fetched from the API -// 1 TFT = 10_000_000 drops = 1_000 mTFT = 1_000_000 uTFT -type DropTFTUnit = u64 - -pub fn (t DropTFTUnit) to_tft() f64 { - return f64(t) / pow10(7) // 1 TFT = 10_000_000 drops -} - -pub fn (t DropTFTUnit) to_mtft() f64 { - return f64(t) / pow10(4) // 1 mTFT (milliTFT) = 10_000 drops -} - -pub fn (t DropTFTUnit) to_utft() f64 { - return f64(t) / 10.0 // 1 uTFT (microTFT) = 10 drops -} - -pub fn (u DropTFTUnit) str() string { - if u >= pow10(7) { - return '${u.to_tft():.3} TFT' - } else if u >= pow10(4) { - return '${u.to_mtft():.3} mTFT' - } else if u >= 10 { - return '${u.to_utft():.3} uTFT' - } - return '${u64(u)} dTFT' // Short for dropTFT (1 TFT = 10_000_000 drops). dylan suggests the name and i'm using this till we have an officail name! -} - -struct EmptyOption {} diff --git a/3bot/vgrid/gridproxy/model/node.v b/3bot/vgrid/gridproxy/model/node.v deleted file mode 100644 index 0b719fe0f..000000000 --- a/3bot/vgrid/gridproxy/model/node.v +++ /dev/null @@ -1,125 +0,0 @@ -module model - -pub struct NodeResources { -pub: - cru u64 - mru ByteUnit - sru ByteUnit - hru ByteUnit -} - -pub struct NodeCapacity { -pub: - total_resources NodeResources - used_resources NodeResources -} - -pub struct NodeLocation { -pub: - country string - city string -} - -pub struct PublicConfig { -pub: - domain string - gw4 string - gw6 string - ipv4 string - ipv6 string -} - -// this is ugly, but it works. we need two models for `Node` and reimplemnt the same fields expcept for capacity srtucture -// it's a hack to make the json parser work as the gridproxy API have some inconsistencies -// see for more context: https://github.com/threefoldtech/tfgridclient_proxy/issues/164 -pub struct Node_ { -pub: - id string - node_id u64 [json: nodeId] - farm_id u64 [json: farmId] - twin_id u64 [json: twinId] - grid_version u64 [json: gridVersion] - uptime SecondUnit - created UnixTime [json: created] - farming_policy_id u64 [json: farmingPolicyId] - updated_at UnixTime [json: updatedAt] - total_resources NodeResources - used_resources NodeResources - location NodeLocation - public_config PublicConfig [json: publicConfig] - certification string [json: certificationType] - status string - dedicated bool - rent_contract_id u64 [json: rentContractId] - rented_by_twin_id u64 [json: rentedByTwinId] -} - -pub struct Node { -pub: - id string - node_id u64 [json: nodeId] - farm_id u64 [json: farmId] - twin_id u64 [json: twinId] - grid_version u64 [json: gridVersion] - uptime SecondUnit - created UnixTime [json: created] - farming_policy_id u64 [json: farmingPolicyId] - updated_at UnixTime [json: updatedAt] - capacity NodeCapacity - location NodeLocation - public_config PublicConfig [json: publicConfig] - certification string [json: certificationType] - status string - dedicated bool - rent_contract_id u64 [json: rentContractId] - rented_by_twin_id u64 [json: rentedByTwinId] -} - -fn calc_available_resources(total_resources NodeResources, used_resources NodeResources) NodeResources { - return NodeResources{ - cru: total_resources.cru - used_resources.cru - mru: total_resources.mru - used_resources.mru - sru: total_resources.sru - used_resources.sru - hru: total_resources.hru - used_resources.hru - } -} - -// calc_available_resources calculate the reservable capacity of the node. -// -// Returns: `NodeResources` -pub fn (n &Node) calc_available_resources() NodeResources { - total_resources := n.capacity.total_resources - used_resources := n.capacity.used_resources - return calc_available_resources(total_resources, used_resources) -} - -// with_nested_capacity enable the client to have one representation of the node model -pub fn (n &Node_) with_nested_capacity() Node { - return Node{ - id: n.id - node_id: n.node_id - farm_id: n.farm_id - twin_id: n.twin_id - grid_version: n.grid_version - uptime: n.uptime - created: n.created - farming_policy_id: n.farming_policy_id - updated_at: n.updated_at - capacity: NodeCapacity{ - total_resources: n.total_resources - used_resources: n.used_resources - } - location: n.location - public_config: n.public_config - certification: n.certification - status: n.status - dedicated: n.dedicated - rent_contract_id: n.rent_contract_id - rented_by_twin_id: n.rented_by_twin_id - } -} - -// is_online returns true if the node is online, otherwise false. -pub fn (n &Node) is_online() bool { - return n.status == 'up' -} diff --git a/3bot/vgrid/gridproxy/model/stats.v b/3bot/vgrid/gridproxy/model/stats.v deleted file mode 100644 index 587b7055c..000000000 --- a/3bot/vgrid/gridproxy/model/stats.v +++ /dev/null @@ -1,44 +0,0 @@ -module model - -pub struct GridStat { -pub: - nodes u64 - farms u64 - countries u64 - total_cru u64 [json: totalCru] - total_sru ByteUnit [json: totalSru] - total_mru ByteUnit [json: totalMru] - total_hru ByteUnit [json: totalHru] - public_ips u64 [json: publicIps] - access_nodes u64 [json: accessNodes] - gateways u64 - twins u64 - contracts u64 - nodes_distribution map[string]u64 [json: nodesDistribution] -} - -pub struct NodeStatisticsResources { -pub: - cru u64 - hru ByteUnit - ipv4u u64 - mru ByteUnit - sru ByteUnit -} - -pub struct NodeStatisticsUsers { -pub: - deployments u64 - workloads u64 -} - -pub struct NodeStats { -pub: - system NodeStatisticsResources - - total NodeStatisticsResources - - used NodeStatisticsResources - - users NodeStatisticsUsers -} diff --git a/3bot/vgrid/gridproxy/model/twin.v b/3bot/vgrid/gridproxy/model/twin.v deleted file mode 100644 index 565f24c19..000000000 --- a/3bot/vgrid/gridproxy/model/twin.v +++ /dev/null @@ -1,8 +0,0 @@ -module model - -pub struct Twin { -pub: - twin_id u64 [json: twinId] - account_id string [json: accountId] - ip string -} diff --git a/3bot/vgrid/v.mod b/3bot/vgrid/v.mod deleted file mode 100644 index 9ac6fd518..000000000 --- a/3bot/vgrid/v.mod +++ /dev/null @@ -1,10 +0,0 @@ -Module { - name: 'vgrid' - description: 'Threefold Grid v modules' - version: '0.0.1' - author: 'threefoldtech' - repo_url: 'https://github.com/threefoldtech/vgrid' - license: 'Apache-2.0' - dependencies: [] - vcs: 'git' -} \ No newline at end of file diff --git a/griddriver/build.sh b/griddriver/build.sh new file mode 100644 index 000000000..869e25844 --- /dev/null +++ b/griddriver/build.sh @@ -0,0 +1,4 @@ +set -ex +cd ~/code/github/threefoldtech/3bot/griddriver +go env -w CGO_ENABLED="0" +go build -o griddriver \ No newline at end of file diff --git a/v2go2tgrid/grid_cli/go.mod b/griddriver/go.mod similarity index 63% rename from v2go2tgrid/grid_cli/go.mod rename to griddriver/go.mod index 627116cbf..0dcd35a02 100644 --- a/v2go2tgrid/grid_cli/go.mod +++ b/griddriver/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( github.com/pkg/errors v0.9.1 - github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20230809064214-d8ef5ca360eb + github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20231004130631-a920b0f5d3de github.com/threefoldtech/tfgrid-sdk-go/grid-client v0.11.2 github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.11.2 github.com/threefoldtech/zos v0.5.6-0.20230809073554-ddb0ad98fc4c @@ -15,52 +15,52 @@ require ( github.com/blang/semver v3.5.1+incompatible // indirect github.com/cenkalti/backoff/v3 v3.2.2 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect - github.com/go-ole/go-ole v1.2.6 // indirect + github.com/go-ole/go-ole v1.3.0 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/gomodule/redigo v2.0.0+incompatible // indirect github.com/google/uuid v1.3.1 // indirect - github.com/hashicorp/errwrap v1.0.0 // indirect + github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/patrickmn/go-cache v2.1.0+incompatible // indirect github.com/shirou/gopsutil v3.21.11+incompatible // indirect - github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.10.2 // indirect - github.com/tklauser/go-sysconf v0.3.9 // indirect - github.com/tklauser/numcpus v0.6.0 // indirect + github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.11.2 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect github.com/tyler-smith/go-bip39 v1.1.0 // indirect - github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852 // indirect - github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f // indirect - github.com/yusufpapurcu/wmi v1.2.2 // indirect - golang.org/x/exp v0.0.0-20230206171751-46f607a40771 // indirect - golang.org/x/sync v0.3.0 // indirect - golang.zx2c4.com/wireguard/wgctrl v0.0.0-20200609130330-bd2cb7843e1b // indirect + github.com/vishvananda/netlink v1.2.1-beta.2 // indirect + github.com/vishvananda/netns v0.0.4 // indirect + github.com/yusufpapurcu/wmi v1.2.3 // indirect + golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect + golang.org/x/sync v0.4.0 // indirect + golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6 // indirect google.golang.org/protobuf v1.31.0 // indirect ) require ( - github.com/ChainSafe/go-schnorrkel v1.0.0 // indirect + github.com/ChainSafe/go-schnorrkel v1.1.0 // indirect github.com/cenkalti/backoff v2.2.1+incompatible // indirect - github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.12 // indirect + github.com/centrifuge/go-substrate-rpc-client/v4 v4.1.0 // indirect github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/deckarep/golang-set v1.8.0 // indirect github.com/decred/base58 v1.0.5 // indirect github.com/decred/dcrd/crypto/blake256 v1.0.1 // indirect - github.com/ethereum/go-ethereum v1.11.6 // indirect + github.com/ethereum/go-ethereum v1.13.2 // indirect github.com/go-stack/stack v1.8.1 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/gtank/merlin v0.1.1 // indirect github.com/gtank/ristretto255 v0.1.2 // indirect - github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c // indirect + github.com/holiman/uint256 v1.2.3 // indirect github.com/jbenet/go-base58 v0.0.0-20150317085156-6237cf65f3a6 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/mimoo/StrobeGo v0.0.0-20220103164710-9a04d6ca976b // indirect github.com/pierrec/xxHash v0.1.5 // indirect - github.com/rs/cors v1.9.0 // indirect - github.com/rs/zerolog v1.30.0 + github.com/rs/cors v1.10.1 // indirect + github.com/rs/zerolog v1.31.0 github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/vedhavyas/go-subkey v1.0.3 // indirect - golang.org/x/crypto v0.13.0 // indirect - golang.org/x/sys v0.12.0 // indirect + github.com/vedhavyas/go-subkey v1.0.4 // indirect + golang.org/x/crypto v0.14.0 // indirect + golang.org/x/sys v0.13.0 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect ) diff --git a/v2go2tgrid/grid_cli/go.sum b/griddriver/go.sum similarity index 81% rename from v2go2tgrid/grid_cli/go.sum rename to griddriver/go.sum index 2ab3cc776..3f0ff786e 100644 --- a/v2go2tgrid/grid_cli/go.sum +++ b/griddriver/go.sum @@ -1,6 +1,8 @@ github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/ChainSafe/go-schnorrkel v1.0.0 h1:3aDA67lAykLaG1y3AOjs88dMxC88PgUuHRrLeDnvGIM= github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z7vcchBSbMBEhCw4= +github.com/ChainSafe/go-schnorrkel v1.1.0 h1:rZ6EU+CZFCjB4sHUE1jIu8VDoB/wRKZxoe1tkcO71Wk= +github.com/ChainSafe/go-schnorrkel v1.1.0/go.mod h1:ABkENxiP+cvjFiByMIZ9LYbRoNNLeBLiakC1XeTFxfE= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/btcsuite/btcd v0.22.0-beta h1:LTDpDKUM5EeOFBPM8IXpinEcmZ6FWfNZbE3lfrfdnWo= @@ -12,6 +14,8 @@ github.com/cenkalti/backoff/v3 v3.2.2 h1:cfUAAO3yvKMYKPrvhDuHSwQnhZNk/RMHKdZqKTx github.com/cenkalti/backoff/v3 v3.2.2/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs= github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.12 h1:DCYWIBOalB0mKKfUg2HhtGgIkBbMA1fnlnkZp7fHB18= github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.12/go.mod h1:5g1oM4Zu3BOaLpsKQ+O8PAv2kNuq+kPcA1VzFbsSqxE= +github.com/centrifuge/go-substrate-rpc-client/v4 v4.1.0 h1:GEvub7kU5YFAcn5A2uOo4AZSM1/cWZCOvfu7E3gQmK8= +github.com/centrifuge/go-substrate-rpc-client/v4 v4.1.0/go.mod h1:szA5wf9suAIcNg/1S3rGeFITHqrnqH5TC6b+O0SEQ94= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY= @@ -32,8 +36,12 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etly github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/ethereum/go-ethereum v1.11.6 h1:2VF8Mf7XiSUfmoNOy3D+ocfl9Qu8baQBrCNbo2CXQ8E= github.com/ethereum/go-ethereum v1.11.6/go.mod h1:+a8pUj1tOyJ2RinsNQD4326YS+leSoKGiG/uVVb0x6Y= +github.com/ethereum/go-ethereum v1.13.2 h1:g9mCpfPWqCA1OL4e6C98PeVttb0HadfBRuKTGvMnOvw= +github.com/ethereum/go-ethereum v1.13.2/go.mod h1:gkQ5Ygi64ZBh9M/4iXY1R8WqoNCx1Ey0CkYn2BD4/fw= github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE= +github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78= github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -60,10 +68,14 @@ github.com/gtank/ristretto255 v0.1.2 h1:JEqUCPA1NvLq5DwYtuzigd7ss8fwbYay9fi4/5uM github.com/gtank/ristretto255 v0.1.2/go.mod h1:Ph5OpO6c7xKUGROZfWVLiJf9icMDwUeIvY4OmlYW69o= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= +github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c h1:DZfsyhDK1hnSS5lH8l+JggqzEleHteTYfutAiVlSUM8= github.com/holiman/uint256 v1.2.2-0.20230321075855-87b91420868c/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= +github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o= +github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= github.com/jbenet/go-base58 v0.0.0-20150317085156-6237cf65f3a6 h1:4zOlv2my+vf98jT1nQt4bT/yKWUImevYPJ2H344CloE= github.com/jbenet/go-base58 v0.0.0-20150317085156-6237cf65f3a6/go.mod h1:r/8JmuR0qjuCiEhAolkfvdZgmPiHTnJaG0UXCSeR1Zo= github.com/jsimonetti/rtnetlink v0.0.0-20190606172950-9527aa82566a/go.mod h1:Oz+70psSo5OFh8DBl0Zv2ACw7Esh6pPUphlvZG9x7uw= @@ -93,9 +105,13 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rs/cors v1.9.0 h1:l9HGsTsHJcvW14Nk7J9KFz8bzeAWXn3CG6bgt7LsrAE= github.com/rs/cors v1.9.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= +github.com/rs/cors v1.10.1 h1:L0uuZVXIKlI1SShY2nhFfo44TYvDPQ1w4oFkUJNfhyo= +github.com/rs/cors v1.10.1/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c= github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w= +github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= +github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= @@ -111,32 +127,48 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20230809064214-d8ef5ca360eb h1:ljvL1BMwTPrV0kAz9E56zJ5jq39TPRsd/tP6l0+0TzY= github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20230809064214-d8ef5ca360eb/go.mod h1:dtDKAPiUDxAwIkfHV7xcAFZcOm+xwNIuOI1MLFS+MeQ= +github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20231004130631-a920b0f5d3de h1:23ByQIFyaZlkyPrWGRLt5bT14pTqeYrncdZUVHzyP5A= +github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20231004130631-a920b0f5d3de/go.mod h1:dtDKAPiUDxAwIkfHV7xcAFZcOm+xwNIuOI1MLFS+MeQ= github.com/threefoldtech/tfgrid-sdk-go/grid-client v0.11.2 h1:6aZYW8fzlgAqiCjuqecL7on+2eBmTeBRpFFnSlsKalc= github.com/threefoldtech/tfgrid-sdk-go/grid-client v0.11.2/go.mod h1:EroQwveJ0tZGneNwAwqBcf6noRFzV0040RAMxxBosIY= github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.10.2 h1:oilBnj9qfD4mH5Cv2J1g1CURizekpEx+LbunCFsyKz8= github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.10.2/go.mod h1:FQA/A4B5IwSM8aO1dt+52B/vv8n8ol0wvsP0vpz0ef8= +github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.11.2 h1:EaTRHvVJ95TL1WjBKGDlGuHM0tyIsNljI+5KcvyMQuI= +github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.11.2/go.mod h1:5wldHWnp4POrhzFMj6+JlsJWa7dgeiY5DBEfZhpNlg8= github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.11.2 h1:mB63grKdktD5JfF1w5hgmEDexkbwRODWq1geg6138Cc= github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.11.2/go.mod h1:IAvYTKCMhl1ngwITEmMhmM7zJHbF1clywZ5kZ+ouPM0= github.com/threefoldtech/zos v0.5.6-0.20230809073554-ddb0ad98fc4c h1:koGfjcZgxN/Yyo+hM5t5Xyfz/kodxOxitTEmcRD4t9I= github.com/threefoldtech/zos v0.5.6-0.20230809073554-ddb0ad98fc4c/go.mod h1:Ao/K9+ChdIQbTCjSGmdG/MEKI1PpP6f2tgugkpSFLY8= github.com/tklauser/go-sysconf v0.3.9 h1:JeUVdAOWhhxVcU6Eqr/ATFHgXk/mmiItdKeJPev3vTo= github.com/tklauser/go-sysconf v0.3.9/go.mod h1:11DU/5sG7UexIrp/O6g35hrWzu0JxlwQ3LSFUzyeuhs= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.3.0/go.mod h1:yFGUr7TUHQRAhyqBcEg0Ge34zDBAsIvJJcyE6boqnA8= github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8= github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U= github.com/urfave/cli v1.22.14 h1:ebbhrRiGK2i4naQJr+1Xj92HXZCrK7MsyTS/ob3HnAk= github.com/urfave/cli v1.22.14/go.mod h1:X0eDS6pD6Exaclxm99NJ3FiCDRED7vIHpx2mDOHLvkA= github.com/vedhavyas/go-subkey v1.0.3 h1:iKR33BB/akKmcR2PMlXPBeeODjWLM90EL98OrOGs8CA= github.com/vedhavyas/go-subkey v1.0.3/go.mod h1:CloUaFQSSTdWnINfBRFjVMkWXZANW+nd8+TI5jYcl6Y= +github.com/vedhavyas/go-subkey v1.0.4 h1:QwjBZx4w7qXC2lmqol2jJfhaNXPI9BsgLZiMiCwqGDU= +github.com/vedhavyas/go-subkey v1.0.4/go.mod h1:aOIil/KS9hJlnr9ZSQKSoXdu/MbnkCxG4x9IOlLsMtI= github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852 h1:cPXZWzzG0NllBLdjWoD1nDfaqu98YMv+OneaKc8sPOA= github.com/vishvananda/netlink v1.1.1-0.20201029203352-d40f9887b852/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho= +github.com/vishvananda/netlink v1.2.1-beta.2 h1:Llsql0lnQEbHj0I1OuKyp8otXp0r3q0mPkuhwHfStVs= +github.com/vishvananda/netlink v1.2.1-beta.2/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho= github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f h1:p4VB7kIXpOQvVn1ZaTIVp+3vuYAXFe3OJEvjbUYJLaA= github.com/vishvananda/netns v0.0.0-20210104183010-2eb08e3e575f/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= +github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8= +github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM= github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= +github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -145,8 +177,12 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= +golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= golang.org/x/exp v0.0.0-20230206171751-46f607a40771 h1:xP7rWLUr1e1n2xkK5YB4LI0hPEy3LJC6Wk+D4pGlOJg= golang.org/x/exp v0.0.0-20230206171751-46f607a40771/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= +golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -155,6 +191,8 @@ golang.org/x/net v0.0.0-20191007182048-72f939374954/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= +golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190411185658-b44545bcd369/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -170,17 +208,25 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= +golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.zx2c4.com/wireguard v0.0.20200121/go.mod h1:P2HsVp8SKwZEufsnezXZA4GRX/T49/HlU7DGuelXsU4= +golang.zx2c4.com/wireguard v0.0.20200320 h1:1vE6zVeO7fix9cJX1Z9ZQ+ikPIIx7vIyU0o0tLDD88g= golang.zx2c4.com/wireguard/wgctrl v0.0.0-20200609130330-bd2cb7843e1b h1:l4mBVCYinjzZuR5DtxHuBD6wyd4348TGiavJ5vLrhEc= golang.zx2c4.com/wireguard/wgctrl v0.0.0-20200609130330-bd2cb7843e1b/go.mod h1:UdS9frhv65KTfwxME1xE8+rHYoFpbm36gOud1GhBe9c= +golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6 h1:CawjfCvYQH2OU3/TnxLx97WDSUDRABfT18pCOYwc2GE= +golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6/go.mod h1:3rxYc4HtVcSG9gVaTs2GEBdehh+sYPOwKtyUWEOTb80= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= diff --git a/v2go2tgrid/grid_cli/main.go b/griddriver/main.go similarity index 100% rename from v2go2tgrid/grid_cli/main.go rename to griddriver/main.go diff --git a/v2go2tgrid/grid_cli/network.go b/griddriver/network.go similarity index 100% rename from v2go2tgrid/grid_cli/network.go rename to griddriver/network.go diff --git a/griddriver/readme.md b/griddriver/readme.md new file mode 100644 index 000000000..07632292a --- /dev/null +++ b/griddriver/readme.md @@ -0,0 +1,10 @@ +# GridDriver + +is a small commandline which can be used to proxy information to TFGrid, its super low level and used by + +to build + +``` +cd ~/code/github/threefoldtech/3bot/griddriver +go build +``` \ No newline at end of file diff --git a/v2go2tgrid/grid_cli/rmb.go b/griddriver/rmb.go similarity index 100% rename from v2go2tgrid/grid_cli/rmb.go rename to griddriver/rmb.go diff --git a/v2go2tgrid/grid_cli/substrate.go b/griddriver/substrate.go similarity index 100% rename from v2go2tgrid/grid_cli/substrate.go rename to griddriver/substrate.go diff --git a/griddriver/update.sh b/griddriver/update.sh new file mode 100644 index 000000000..ed8386b15 --- /dev/null +++ b/griddriver/update.sh @@ -0,0 +1,4 @@ + +go get -u ./... +go mod tidy + diff --git a/v2go2tgrid/README.md b/v2go2tgrid/README.md deleted file mode 100644 index b5b1b9b4b..000000000 --- a/v2go2tgrid/README.md +++ /dev/null @@ -1,5 +0,0 @@ - -# V to GO Command Line to TFGrid/ZOS - -V will create workloads in native low level format, and then use a GO binary to post it to TFChain as well as send it to ZOS. - diff --git a/v2go2tgrid/examples/vm_deploy/vm_deploy.v b/v2go2tgrid/examples/vm_deploy/vm_deploy.v deleted file mode 100644 index 716c711d9..000000000 --- a/v2go2tgrid/examples/vm_deploy/vm_deploy.v +++ /dev/null @@ -1,17 +0,0 @@ - -module main - -//TODO: import - -import os - -fn do()!{ - -//deploy 1 VM - -} - -fn main() { - - do() or {panic(err)} -} diff --git a/v2go2tgrid/mail/client.v b/v2go2tgrid/mail/client.v deleted file mode 100644 index 6c7f3982a..000000000 --- a/v2go2tgrid/mail/client.v +++ /dev/null @@ -1,77 +0,0 @@ -module mail - -import log -import freeflowuniverse.crystallib.jsonrpc -import freeflowuniverse.crystallib.rpcwebsocket -import x.json2 - -// client for reverse echo json rpc ws server -struct MailOpenRpcClient { - jsonrpc.JsonRpcClient -} - -pub fn (mut client MailOpenRpcClient) close() ! { - _ := client.send_json_rpc[string, json2.Null]('close', '', 1000)! -} - -pub fn (mut client MailOpenRpcClient) login(params LoginParams) ! { - _ := client.send_json_rpc[LoginParams, json2.Null]('login', params, 1000)! -} - -pub fn (mut client MailOpenRpcClient) select_(params SelectParams) !SelectData { - return client.send_json_rpc[SelectParams, SelectData]('select_', params, 1000)! -} - -pub fn (mut client MailOpenRpcClient) create(options CreateParams) ! { - _ := client.send_json_rpc[CreateParams, json2.Null]('create', options, 1000)! -} - -pub fn (mut client MailOpenRpcClient) delete(mailbox string) ! { - _ := client.send_json_rpc[string, json2.Null]('delete', mailbox, 1000)! -} - -pub fn (mut client MailOpenRpcClient) rename(params RenameParams) ! { - _ := client.send_json_rpc[RenameParams, json2.Null]('rename', params, 1000)! -} - -pub fn (mut client MailOpenRpcClient) subscribe(mailbox string) ! { - _ := client.send_json_rpc[string, json2.Null]('subscribe', mailbox, 1000)! -} - -pub fn (mut client MailOpenRpcClient) unsubscribe(mailbox string) ! { - _ := client.send_json_rpc[string, json2.Null]('unsubscribe', mailbox, 1000)! -} - -pub fn (mut client MailOpenRpcClient) list(options ListOptions) ! { - _ := client.send_json_rpc[ListOptions, json2.Null]('list', options, 1000)! -} - -pub fn (mut client MailOpenRpcClient) status(options StatusParams) !string { - return client.send_json_rpc[StatusParams, string]('status', options, 1000)! -} - -pub fn (mut client MailOpenRpcClient) append(options AppendParams) !bool { - return client.send_json_rpc[AppendParams, bool]('append', options, 1000)! -} - -pub fn (mut client MailOpenRpcClient) poll(allow_expunge bool) ! { - _ := client.send_json_rpc[bool, json2.Null]('poll', allow_expunge, 1000)! -} - -pub fn (mut client MailOpenRpcClient) idle() ! { - _ := client.send_json_rpc[string, json2.Null]('idle', '', 1000)! -} - -// run_client creates and runs jsonrpc client -// uses reverse_echo method to perform rpc and prints result -pub fn new_client(mut transport rpcwebsocket.RpcWsClient) !&MailOpenRpcClient { - mut logger := log.Logger(&log.Log{ - level: .debug - }) - - mut client := MailOpenRpcClient{ - transport: transport - } - spawn transport.run() - return &client -} diff --git a/v2go2tgrid/mail/handler.v b/v2go2tgrid/mail/handler.v deleted file mode 100644 index 1ef199f1e..000000000 --- a/v2go2tgrid/mail/handler.v +++ /dev/null @@ -1,210 +0,0 @@ -module mail - -import log -import json -import freeflowuniverse.crystallib.jsonrpc { jsonrpcrequest_decode } -import freeflowuniverse.crystallib.openrpc as crystallib_openrpc { OpenRpcHandler } -import freeflowuniverse.crystallib.rpchandler - -struct MailOpenRpcHandler { - OpenRpcHandler -} - -fn (mut handler MailOpenRpcHandler) close_handle(data string) !string { - mut receiver := &Mail(handler.state) - - request := json.decode(jsonrpc.JsonRpcRequestAny, data)! - receiver.close()! - - response := jsonrpc.JsonRpcResponse[string]{ - jsonrpc: '2.0.0' - id: request.id - result: '' - } - return response.to_json() -} - -fn (mut handler MailOpenRpcHandler) select__handle(data string) !string { - mut receiver := &Mail(handler.state) - - request := jsonrpcrequest_decode[SelectParams](data)! - receiver.select_(request.params)! - - response := jsonrpc.JsonRpcResponse[string]{ - jsonrpc: '2.0.0' - id: request.id - result: '' - } - return response.to_json() -} - -fn (mut handler MailOpenRpcHandler) create_handle(data string) !string { - mut receiver := &Mail(handler.state) - - request := jsonrpcrequest_decode[CreateParams](data)! - receiver.create(request.params)! - - response := jsonrpc.JsonRpcResponse[string]{ - jsonrpc: '2.0.0' - id: request.id - result: '' - } - return response.to_json() -} - -fn (mut handler MailOpenRpcHandler) delete_handle(data string) !string { - mut receiver := &Mail(handler.state) - - request := jsonrpcrequest_decode[string](data)! - receiver.delete(request.params)! - - response := jsonrpc.JsonRpcResponse[string]{ - jsonrpc: '2.0.0' - id: request.id - result: '' - } - return response.to_json() -} - -fn (mut handler MailOpenRpcHandler) rename_handle(data string) !string { - mut receiver := &Mail(handler.state) - - request := jsonrpcrequest_decode[RenameParams](data)! - receiver.rename(request.params)! - - response := jsonrpc.JsonRpcResponse[string]{ - jsonrpc: '2.0.0' - id: request.id - result: '' - } - return response.to_json() -} - -fn (mut handler MailOpenRpcHandler) subscribe_handle(data string) !string { - mut receiver := &Mail(handler.state) - - request := jsonrpcrequest_decode[string](data)! - receiver.subscribe(request.params)! - - response := jsonrpc.JsonRpcResponse[string]{ - jsonrpc: '2.0.0' - id: request.id - result: '' - } - return response.to_json() -} - -fn (mut handler MailOpenRpcHandler) unsubscribe_handle(data string) !string { - mut receiver := &Mail(handler.state) - - request := jsonrpcrequest_decode[string](data)! - receiver.unsubscribe(request.params)! - - response := jsonrpc.JsonRpcResponse[string]{ - jsonrpc: '2.0.0' - id: request.id - result: '' - } - return response.to_json() -} - -fn (mut handler MailOpenRpcHandler) list_handle(data string) !string { - mut receiver := &Mail(handler.state) - - request := jsonrpcrequest_decode[ListOptions](data)! - receiver.list(request.params)! - - response := jsonrpc.JsonRpcResponse[string]{ - jsonrpc: '2.0.0' - id: request.id - result: '' - } - return response.to_json() -} - -fn (mut handler MailOpenRpcHandler) status_handle(data string) !string { - mut receiver := &Mail(handler.state) - - request := jsonrpcrequest_decode[StatusParams](data)! - receiver.status(request.params)! - - response := jsonrpc.JsonRpcResponse[string]{ - jsonrpc: '2.0.0' - id: request.id - result: '' - } - return response.to_json() -} - -fn (mut handler MailOpenRpcHandler) append_handle(data string) !string { - mut receiver := &Mail(handler.state) - - request := jsonrpcrequest_decode[AppendParams](data)! - receiver.append(request.params)! - - response := jsonrpc.JsonRpcResponse[string]{ - jsonrpc: '2.0.0' - id: request.id - result: '' - } - return response.to_json() -} - -fn (mut handler MailOpenRpcHandler) poll_handle(data string) !string { - mut receiver := &Mail(handler.state) - - request := jsonrpcrequest_decode[bool](data)! - receiver.poll(request.params)! - - response := jsonrpc.JsonRpcResponse[string]{ - jsonrpc: '2.0.0' - id: request.id - result: '' - } - return response.to_json() -} - -fn (mut handler MailOpenRpcHandler) idle_handle(data string) !string { - mut receiver := &Mail(handler.state) - - request := json.decode(jsonrpc.JsonRpcRequestAny, data)! - receiver.idle()! - - response := jsonrpc.JsonRpcResponse[string]{ - jsonrpc: '2.0.0' - id: request.id - result: '' - } - return response.to_json() -} - -pub struct HandlerParams { - logger &log.Logger - state voidptr - openrpc_path string -} - -// run_server creates and runs a jsonrpc ws server -// handles rpc requests to reverse_echo function -pub fn new_handler(params HandlerParams) !&MailOpenRpcHandler { - mut handler := MailOpenRpcHandler{ - OpenRpcHandler: crystallib_openrpc.new_handler(params.logger, params.openrpc_path)! - } - - handler.state = params.state - // register rpc methods - handler.register('close', handler.close_handle)! - handler.register('select_', handler.select__handle)! - handler.register('create', handler.create_handle)! - handler.register('delete', handler.delete_handle)! - handler.register('rename', handler.rename_handle)! - handler.register('subscribe', handler.subscribe_handle)! - handler.register('unsubscribe', handler.unsubscribe_handle)! - handler.register('list', handler.list_handle)! - handler.register('status', handler.status_handle)! - handler.register('append', handler.append_handle)! - handler.register('poll', handler.poll_handle)! - handler.register('idle', handler.idle_handle)! - - return &handler -} diff --git a/v2go2tgrid/mail/methods.v b/v2go2tgrid/mail/methods.v deleted file mode 100644 index 703785a3f..000000000 --- a/v2go2tgrid/mail/methods.v +++ /dev/null @@ -1,110 +0,0 @@ -module mail - -import time - -pub fn (mail Mail) close() ! {} - -pub struct LoginParams { - username string - password string -} - -pub struct SelectParams { - mailbox string -} - -pub struct SelectData {} - -pub fn (mail Mail) select_(params SelectParams) !SelectData { - return SelectData{} -} - -pub struct CreateParams { - mailbox string -} - -pub fn (mut mail Mail) create(params CreateParams) ! { - if params.mailbox in mail.mailboxes { - return error('Mailbox already exists') - } - mail.mailboxes[params.mailbox] = Mailbox{ - name: params.mailbox - } -} - -pub fn (mut mail Mail) delete(mailbox string) ! { - if mailbox !in mail.mailboxes { - return error("Mailbox doesn't exists") - } - mail.mailboxes.delete(mailbox) -} - -pub struct RenameParams { - mailbox string - new_name string -} - -pub fn (mut mail Mail) rename(params RenameParams) ! { - if params.new_name in mail.mailboxes { - return error('Mailbox already exists') - } - mut mbox := mail.mailboxes[params.mailbox] or { return error("Mailbox doesn't exist") } - mbox.name = params.new_name - mail.mailboxes.delete(params.mailbox) - mail.mailboxes[params.new_name] = mbox -} - -pub fn (mut mail Mail) subscribe(mailbox string) ! { - if mailbox !in mail.mailboxes { - return error("Mailbox doesn't exist") - } - mail.mailboxes[mailbox].subscribed = true -} - -pub fn (mut mail Mail) unsubscribe(mailbox string) ! { - if mailbox !in mail.mailboxes { - return error("Mailbox doesn't exist") - } - mail.mailboxes[mailbox].subscribed = false -} - -pub struct ListOptions { - patterns []string -} - -pub fn (mail Mail) list(options ListOptions) ![]Mailbox { - return mail.mailboxes.values() -} - -pub struct StatusParams { - mailbox string - flags []string -} - -pub fn (mail Mail) status(params StatusParams) !string { - mbox := mail.mailboxes[params.mailbox] or { return error("Mailbox doesn't exist") } - mut statuses := []string{} // an array of flag statuses - for flag in params.flags { - statuses << '${flag} ${mbox.mails.filter(flag in it.flags).len}' - } - return statuses.join(' ') -} - -pub struct AppendParams { - mailbox string - message string -} - -pub fn (mut mail Mail) append(params AppendParams) ! { - if params.mailbox !in mail.mailboxes { - return error("Mailbox doesn't exists") - } - mail.mailboxes[params.mailbox].mails << Email{ - body: params.message - time: time.now() - } -} - -pub fn (mail Mail) poll(allow_expunge bool) ! {} - -pub fn (mail Mail) idle() ! {} diff --git a/v2go2tgrid/mail/model.v b/v2go2tgrid/mail/model.v deleted file mode 100644 index 53c9b2619..000000000 --- a/v2go2tgrid/mail/model.v +++ /dev/null @@ -1,28 +0,0 @@ -module mail - -import time - -pub struct Mail { -mut: - mailboxes map[string]Mailbox -} - -struct Mailbox { -mut: - name string - mails []Email - subscribed bool -} - -struct Email { - time time.Time - subject string - from EmailAddress - cc EmailAddress - bcc EmailAddress - body string - flags []Flag -} - -type EmailAddress = string -type Flag = string diff --git a/v2go2tgrid/tfgrid/README.md b/v2go2tgrid/tfgrid/README.md deleted file mode 100644 index 008893149..000000000 --- a/v2go2tgrid/tfgrid/README.md +++ /dev/null @@ -1,126 +0,0 @@ -# Deployments - -## Prerequisites - -> TODO: should not be needed to use a proxy - -- redis server - - step by step installation [here](https://developer.redis.com/create/linux/) -- [rmb peer](https://github.com/threefoldtech/rmb-rs) -- grid cli - - this is a helper binary to facilitate tfgrid interactions - - how to install: - -```bash -cd 3bot/grid_cli -go build -o grid-cli -sudo mv grid-cli /usr/bin/ -``` - -## How to deploy - -- for example to make a deployment with Znet and a Zmachine, do the following: - - create a zmachine workload. - -```go -zmachine := zos.Zmachine{ - flist: 'https://hub.grid.tf/tf-official-apps/base:latest.flist' - network: zos.ZmachineNetwork{ - public_ip: '' - interfaces: [ - zos.ZNetworkInterface{ - network: 'network' - ip: '10.1.1.3' - }, - ] - planetary: true - } - compute_capacity: zos.ComputeCapacity{ - cpu: 1 - memory: i64(1024) * 1024 * 1024 * 2 - } - env: { - 'SSH_KEY': 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCs3qtlU13/hHKLE8KUkyt+yAH7z5IKs6PH63dhkeQBBG+VdxlTg/a+6DEXqc5VVL6etKRpKKKpDVqUFKuWIK1x3sE+Q6qZ/FiPN+cAAQZjMyevkr5nmX/ofZbvGUAQGo7erxypB0Ye6PFZZVlkZUQBs31dcbNXc6CqtwunJIgWOjCMLIl/wkKUAiod7r4O2lPvD7M2bl0Y/oYCA/FnY9+3UdxlBIi146GBeAvm3+Lpik9jQPaimriBJvAeb90SYIcrHtSSe86t2/9NXcjjN8O7Fa/FboindB2wt5vG+j4APOSbvbWgpDpSfIDPeBbqreSdsqhjhyE36xWwr1IqktX+B9ZuGRoIlPWfCHPJSw/AisfFGPeVeZVW3woUdbdm6bdhoRmGDIGAqPu5Iy576iYiZJnuRb+z8yDbtsbU2eMjRCXn1jnV2GjQcwtxViqiAtbFbqX0eQ0ZU8Zsf0IcFnH1W5Tra/yp9598KmipKHBa+AtsdVu2RRNRW6S4T3MO5SU= mario@mario-machine' - } -} - -mut zmachine_workload := zos.Workload{ - version: 0 - name: 'vm2' - type_: zos.workload_types.zmachine - data: json.encode(zmachine) - description: 'zmachine test' -} -``` - -- create a znet workload: - -```go -mut network := zos.Znet{ - ip_range: '10.1.0.0/16' - subnet: '10.1.1.0/24' - wireguard_private_key: 'GDU+cjKrHNJS9fodzjFDzNFl5su3kJXTZ3ipPgUjOUE=' - wireguard_listen_port: 8080 - peers: [ - zos.Peer{ - subnet: '10.1.2.0/24' - wireguard_public_key: '4KTvZS2KPWYfMr+GbiUUly0ANVg8jBC7xP9Bl79Z8zM=' - allowed_ips: ['10.1.2.0/24', '100.64.1.2/32'] - }, - ] -} - -mut znet_workload := zos.Workload{ - version: 0 - name: 'network' - type_: zos.workload_types.network - data: json.encode_pretty(network) - description: 'test network2' -} -``` - -- create a deployment containing the two workloads: - -```go -mut deployment := zos.Deployment{ - version: 0 - twin_id: deployer.twin_id - metadata: 'zm dep' - description: 'zm kjasdf1nafvbeaf1234t21' - workloads: [znet_workload, zmachine_workload] - signature_requirement: zos.SignatureRequirement{ - weight_required: 1 - requests: [ - zos.SignatureRequest{ - twin_id: deployer.twin_id - weight: 1 - }, - ] - } -} -``` - -- create a deployer instance: - -```vlang - mnemonics := '' - substrate_url := 'wss://tfchain.dev.grid.tf/ws' - mut client := rmb.new(nettype: rmb.TFNetType.dev, tfchain_mnemonic: mnemonics)! - mut deployer := zos.Deployer{ - mnemonics: mnemonics - substrate_url: substrate_url - twin_id: 'YOUR TWIN ID' - rmb_cl: client - } -``` - -- use the deployer to deploy the deployment: - -```vlang - contract_id := deployer.deploy(node_id, mut deployment, '', 0) or { - logger.error('failed to deploy deployment: ${err}') - exit(1) - } -``` - -For more examples, go to [examples](./examples/) diff --git a/v2go2tgrid/tfgrid/contracts.v b/v2go2tgrid/tfgrid/contracts.v deleted file mode 100644 index ca7af80fb..000000000 --- a/v2go2tgrid/tfgrid/contracts.v +++ /dev/null @@ -1,36 +0,0 @@ -module tfgrid - -import strconv -import os - -pub fn (mut d Deployer) create_node_contract(node_id u32, body string, hash string, public_ips u32, solution_provider u64) !u64 { - res := os.execute("grid-cli new-node-cn --substrate ${d.substrate_url} --mnemonics \"${d.mnemonics}\" --node_id ${node_id} --hash \"${hash}\" --public_ips ${public_ips} --body ${body} --solution_provider ${solution_provider}") - if res.exit_code != 0 { - return error(res.output) - } - - return strconv.parse_uint(res.output, 10, 64)! -} - -pub fn (mut d Deployer) create_name_contract(name string) !u64 { - res := os.execute("grid-cli new-name-cn --substrate ${d.substrate_url} --mnemonics \"${d.mnemonics}\" --name ${name}") - if res.exit_code != 0 { - return error(res.output) - } - - return strconv.parse_uint(res.output, 10, 64)! -} - -pub fn (mut d Deployer) update_node_contract(contract_id u64, body string, hash string) ! { - res := os.execute("grid-cli update-cn --substrate ${d.substrate_url} --mnemonics \"${d.mnemonics}\" --contract_id ${contract_id} --body \"${body}\" --hash \"${hash}\"") - if res.exit_code != 0 { - return error(res.output) - } -} - -pub fn (mut d Deployer) cancel_contract(contract_id u64) ! { - res := os.execute("grid-cli cancel-cn --substrate ${d.substrate_url} --mnemonics \"${d.mnemonics}\" --contract_id ${contract_id}") - if res.exit_code != 0 { - return error(res.output) - } -} diff --git a/v2go2tgrid/tfgrid/deploy_test.v b/v2go2tgrid/tfgrid/deploy_test.v deleted file mode 100644 index ec7ab3d3f..000000000 --- a/v2go2tgrid/tfgrid/deploy_test.v +++ /dev/null @@ -1,117 +0,0 @@ -module tfgrid - -import freeflowuniverse.crystallib.threefold.rmb -import json - -fn test_deploy_deployment() { - mnemonics := '' - substrate_url := 'wss://tfchain.dev.grid.tf/ws' - mut deployer := Deployer{ - mnemonics: mnemonics - substrate_url: substrate_url - } - node_id := u32(14) - twin_id := u32(49) - node_twin_id := u32(22) - - mut network := Znet{ - ip_range: '10.1.0.0/16' - subnet: '10.1.1.0/24' - wireguard_private_key: 'GDU+cjKrHNJS9fodzjFDzNFl5su3kJXTZ3ipPgUjOUE=' - wireguard_listen_port: 3011 - peers: [ - Peer{ - subnet: '10.1.2.0/24' - wireguard_public_key: '4KTvZS2KPWYfMr+GbiUUly0ANVg8jBC7xP9Bl79Z8zM=' - allowed_ips: ['10.1.2.0/24', '100.64.1.2/32'] - }, - ] - } - mut znet_workload := Workload{ - version: 0 - name: 'network' - type_: workload_types.network - data: json.encode_pretty(network) - description: 'test network2' - } - - zmachine := Zmachine{ - flist: 'https://hub.grid.tf/tf-official-apps/base:latest.flist' - network: ZmachineNetwork{ - public_ip: '' - interfaces: [ - ZNetworkInterface{ - network: 'network' - ip: '10.1.1.3' - }, - ] - planetary: true - } - compute_capacity: ComputeCapacity{ - cpu: 1 - memory: i64(1024) * 1024 * 1024 * 2 - } - env: { - 'SSH_KEY': 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCs3qtlU13/hHKLE8KUkyt+yAH7z5IKs6PH63dhkeQBBG+VdxlTg/a+6DEXqc5VVL6etKRpKKKpDVqUFKuWIK1x3sE+Q6qZ/FiPN+cAAQZjMyevkr5nmX/ofZbvGUAQGo7erxypB0Ye6PFZZVlkZUQBs31dcbNXc6CqtwunJIgWOjCMLIl/wkKUAiod7r4O2lPvD7M2bl0Y/oYCA/FnY9+3UdxlBIi146GBeAvm3+Lpik9jQPaimriBJvAeb90SYIcrHtSSe86t2/9NXcjjN8O7Fa/FboindB2wt5vG+j4APOSbvbWgpDpSfIDPeBbqreSdsqhjhyE36xWwr1IqktX+B9ZuGRoIlPWfCHPJSw/AisfFGPeVeZVW3woUdbdm6bdhoRmGDIGAqPu5Iy576iYiZJnuRb+z8yDbtsbU2eMjRCXn1jnV2GjQcwtxViqiAtbFbqX0eQ0ZU8Zsf0IcFnH1W5Tra/yp9598KmipKHBa+AtsdVu2RRNRW6S4T3MO5SU= mario@mario-machine' - } - } - - mut zmachine_workload := Workload{ - version: 0 - name: 'vm2' - type_: workload_types.zmachine - data: json.encode(zmachine) - description: 'zmachine test' - } - - mut deployment := Deployment{ - version: 0 - twin_id: twin_id - metadata: 'zm dep' - description: 'zm kjasdf1nafvbeaf1234t21' - workloads: [znet_workload, zmachine_workload] - signature_requirement: SignatureRequirement{ - weight_required: 1 - requests: [ - SignatureRequest{ - twin_id: twin_id - weight: 1 - }, - ] - } - } - - hash := deployment.challenge_hash() - hex_hash := hash.hex() - - contract_id := deployer.create_node_contract(0, '', hex_hash, 0, 0)! - deployment.contract_id = contract_id - - signature := deployer.sign_deployment(hex_hash)! - deployment.add_signature(twin_id, signature) - - payload := deployment.json_encode()! - print('payload: ${payload}') - exit(0) - mut client := rmb.new(nettype: rmb.TFNetType.dev, tfchain_mnemonic: mnemonics)! - response := client.rmb_request('zos.deployment.deploy', node_twin_id, payload) or { - print('error: ${err}') - exit(1) - } - if response.err.code != 0 { - print(response.err.message) - } - // mut mb := client.MessageBusClient - // { - // client: - // redisclient.connect('localhost:6379') or { panic(err) } - // } - // mut msg := client.prepare('zos.deployment.deploy', [2], 0, 2) - // mb.send(msg, payload) - // response := mb.read(msg) - // println('Result Received for reply: ${msg.retqueue}') - // for result in response { - // println(result) - // println(result.data) - // } -} diff --git a/v2go2tgrid/tfgrid/deployer.v b/v2go2tgrid/tfgrid/deployer.v deleted file mode 100644 index 179125d00..000000000 --- a/v2go2tgrid/tfgrid/deployer.v +++ /dev/null @@ -1,160 +0,0 @@ -module tfgrid - -import os -import json -import time -import log -import models - -pub struct Deployer { -pub: - mnemonics string - substrate_url string - twin_id u32 - relay_url string - env string -pub mut: - logger log.Log -} - -pub enum ChainNetwork { - dev - qa - test - main -} - -const substrate_url = { - ChainNetwork.dev: 'wss://tfchain.dev.grid.tf/ws' - ChainNetwork.qa: 'wss://tfchain.qa.grid.tf/ws' - ChainNetwork.test: 'wss://tfchain.test.grid.tf/ws' - ChainNetwork.main: 'wss://tfchain.grid.tf/ws' -} - -const envs = { - ChainNetwork.dev: 'dev' - ChainNetwork.qa: 'qa' - ChainNetwork.test: 'test' - ChainNetwork.main: 'main' -} - -const relay_url = { - ChainNetwork.dev: 'wss://relay.dev.grid.tf' - ChainNetwork.qa: 'wss://relay.qa.grid.tf' - ChainNetwork.test: 'wss://relay.test.grid.tf' - ChainNetwork.main: 'wss://relay.grid.tf' -} - -pub fn get_mnemonics() !string { - mnemonics := os.getenv('MNEMONICS') - if mnemonics == '' { - return error('failed to get mnemonics, run `export MNEMONICS=....`') - } - return mnemonics -} - -pub fn new_deployer(mnemonics string, chain_network ChainNetwork, mut logger log.Log) !Deployer { - twin_id := get_user_twin(mnemonics, tfgrid.substrate_url[chain_network])! - - return Deployer{ - mnemonics: mnemonics - substrate_url: tfgrid.substrate_url[chain_network] - twin_id: twin_id - relay_url: tfgrid.relay_url[chain_network] - env: tfgrid.envs[chain_network] - logger: logger - } -} - -fn (mut d Deployer) handel_deploy(node_id u32, mut dl models.Deployment, body string, solution_provider u64, hash_hex string) !u64 { - signature := d.sign_deployment(hash_hex)! - dl.add_signature(d.twin_id, signature) - payload := dl.json_encode() - - node_twin_id := get_node_twin(node_id, d.substrate_url)! - d.rmb_deployment_deploy(node_twin_id, payload)! - workload_versions := d.assign_versions(dl) - d.wait_deployment(node_id, dl.contract_id, workload_versions)! - return dl.contract_id -} - -pub fn (mut d Deployer) deploy(node_id u32, mut dl models.Deployment, body string, solution_provider u64) !u64 { - public_ips := dl.count_public_ips() - hash_hex := dl.challenge_hash().hex() - - contract_id := d.create_node_contract(node_id, body, hash_hex, public_ips, solution_provider)! - d.logger.info('ContractID: ${contract_id}') - dl.contract_id = contract_id - - return d.handel_deploy(node_id, mut dl, body, solution_provider, hash_hex) or { - d.logger.info('Rolling back...') - d.logger.info('deleting contract id: ${contract_id}') - d.cancel_contract(contract_id)! - return err - } -} - -pub fn (mut d Deployer) assign_versions(dl models.Deployment) map[string]u32 { - mut workload_versions := map[string]u32{} - for wl in dl.workloads { - workload_versions[wl.name] = wl.version - } - return workload_versions -} - -pub fn (mut d Deployer) wait_deployment(node_id u32, contract_id u64, workload_versions map[string]u32) ! { - start := time.now() - num_workloads := workload_versions.len - for { - mut state_ok := 0 - changes := d.deployment_changes(node_id, contract_id)! - for wl in changes { - if wl.version == workload_versions[wl.name] - && wl.result.state == models.result_states.ok { - state_ok++ - } else if wl.version == workload_versions[wl.name] - && wl.result.state == models.result_states.error { - return error('failed to deploy deployment due error: ${wl.result.message}') - } - } - if state_ok == num_workloads { - return - } - if (time.now() - start).minutes() > 5 { - return error('failed to deploy deployment: contractID: ${contract_id}, some workloads are not ready after wating 5 minutes') - } else { - d.logger.info('Waiting for deployment to become ready') - time.sleep(1 * time.second) - } - } -} - -pub fn (mut d Deployer) get_deployment(contract_id u64, node_id u32) !models.Deployment { - twin_id := get_node_twin(node_id, d.substrate_url)! - payload := { - 'contract_id': contract_id - } - res := d.rmb_deployment_get(twin_id, json.encode(payload))! - return json.decode(models.Deployment, res) -} - -pub fn (mut d Deployer) deployment_changes(node_id u32, contract_id u64) ![]models.Workload { - twin_id := get_node_twin(node_id, d.substrate_url)! - - res := d.rmb_deployment_changes(twin_id, contract_id)! - return json.decode([]models.Workload, res) -} - -pub fn (mut d Deployer) sign_deployment(hash string) !string { - res := os.execute("grid-cli sign --substrate \"${d.substrate_url}\" --mnemonics \"${d.mnemonics}\" --hash \"${hash}\"") - if res.exit_code != 0 { - return error(res.output) - } - return res.output -} - -pub fn (mut d Deployer) deploy_single_vm(node_id u32, solution_type string, vm models.VM) !string{ - data := vm.json_encode() - res := os.execute("grid-cli deploy-single --mnemonics \"${d.mnemonics}\" --env ${d.env} --solution_type \"${solution_type}\" --node ${node_id} --data '${data}'") - return res.output -} diff --git a/v2go2tgrid/tfgrid/examples/cancel_deployment.v b/v2go2tgrid/tfgrid/examples/cancel_deployment.v deleted file mode 100644 index 04662fb42..000000000 --- a/v2go2tgrid/tfgrid/examples/cancel_deployment.v +++ /dev/null @@ -1,22 +0,0 @@ -module main - -import log -import threefoldtech.tfgrid - -fn main() { - mut logger := log.Log{ - level: .debug - } - - mnemonics := tfgrid.get_mnemonics() or { - logger.error(err.str()) - exit(1) - } - chain_network := tfgrid.ChainNetwork.dev // User your desired network - mut deployer := tfgrid.new_deployer(mnemonics, chain_network, mut logger)! - - contract_id := u64(39332) // replace with contract id that you want to cancel - deployer.cancel_contract(contract_id)! - - logger.info('contract ${contract_id} is canceled') -} diff --git a/v2go2tgrid/tfgrid/examples/deploy_gw_fqdn.v b/v2go2tgrid/tfgrid/examples/deploy_gw_fqdn.v deleted file mode 100644 index 7ce26f0b8..000000000 --- a/v2go2tgrid/tfgrid/examples/deploy_gw_fqdn.v +++ /dev/null @@ -1,51 +0,0 @@ -module main - -import log -import threefoldtech.tfgrid -import threefoldtech.tfgrid.models -fn main() { - mut logger := log.Log{ - level: .debug - } - - mnemonics := tfgrid.get_mnemonics() or { - logger.error(err.str()) - exit(1) - } - chain_network := tfgrid.ChainNetwork.dev // User your desired network - mut deployer := tfgrid.new_deployer(mnemonics, chain_network, mut logger)! - - gw := models.GatewayFQDNProxy{ - tls_passthrough: false - backends: ['http://1.1.1.1:9000'] - fqdn: 'domaind.gridtesting.xyz' - } - wl := gw.to_workload(name: 'mywlname') - node_id := u32(11) - logger.info('trying to get node ${node_id} public configuration') - deployer.get_node_pub_config(node_id) or { - logger.error('please select another node: ${err}') - exit(1) - } - logger.info('preparing the deployment..') - signature_requirement := models.SignatureRequirement{ - weight_required: 1 - requests: [ - models.SignatureRequest{ - twin_id: deployer.twin_id - weight: 1 - }, - ] - } - mut deployment := models.new_deployment( - twin_id: deployer.twin_id - workloads: [wl] - signature_requirement: signature_requirement - ) - - node_contract_id := deployer.deploy(node_id, mut deployment, '', 0) or { - logger.error(err.str()) - exit(1) - } - logger.info('node contract created with id ${node_contract_id}') -} diff --git a/v2go2tgrid/tfgrid/examples/deploy_gw_name.v b/v2go2tgrid/tfgrid/examples/deploy_gw_name.v deleted file mode 100644 index 2572c0375..000000000 --- a/v2go2tgrid/tfgrid/examples/deploy_gw_name.v +++ /dev/null @@ -1,47 +0,0 @@ -module main - -import log -import threefoldtech.tfgrid -import threefoldtech.tfgrid.models -fn main() { - mut logger := log.Log{ - level: .debug - } - - mnemonics := tfgrid.get_mnemonics() or { - logger.error(err.str()) - exit(1) - } - chain_network := tfgrid.ChainNetwork.dev // User your desired network - mut deployer := tfgrid.new_deployer(mnemonics, chain_network, mut logger)! - - gw := models.GatewayNameProxy{ - tls_passthrough: false - backends: ['http://1.1.1.1'] - name: 'hamada_gw' - } - - wl := gw.to_workload(name: 'hamada_gw') - - name_contract_id := deployer.create_name_contract(wl.name)! - logger.info('name contract ${wl.name} created with id ${name_contract_id}') - - signature_requirement := models.SignatureRequirement{ - weight_required: 1 - requests: [ - models.SignatureRequest{ - twin_id: deployer.twin_id - weight: 1 - }, - ] - } - - mut deployment := models.new_deployment( - twin_id: deployer.twin_id - workloads: [wl] - signature_requirement: signature_requirement - ) - - node_contract_id := deployer.deploy(11, mut deployment, '', 0)! - logger.info('node contract created with id ${node_contract_id}') -} diff --git a/v2go2tgrid/tfgrid/examples/deploy_vm.v b/v2go2tgrid/tfgrid/examples/deploy_vm.v deleted file mode 100644 index b2b0deb33..000000000 --- a/v2go2tgrid/tfgrid/examples/deploy_vm.v +++ /dev/null @@ -1,99 +0,0 @@ -module main - -import json -import threefoldtech.tfgrid.models -import threefoldtech.tfgrid -import log -import os - -fn main() { - mut logger := log.Log{ - level: .debug - } - mnemonics := os.getenv('MNEMONICS') - chain_network := tfgrid.ChainNetwork.dev // User your desired network - mut deployer := tfgrid.new_deployer(mnemonics, chain_network, mut logger)! - - node_id := u32(27) - network_name := 'network1' - wg_port := deployer.assign_wg_port(node_id)! - mut network := models.Znet{ - ip_range: '10.1.0.0/16' - subnet: '10.1.1.0/24' - wireguard_private_key: 'GDU+cjKrHNJS9fodzjFDzNFl5su3kJXTZ3ipPgUjOUE=' - wireguard_listen_port: wg_port - peers: [ - models.Peer{ - subnet: '10.1.2.0/24' - wireguard_public_key: '4KTvZS2KPWYfMr+GbiUUly0ANVg8jBC7xP9Bl79Z8zM=' - allowed_ips: ['10.1.2.0/24', '100.64.1.2/32'] - }, - ] - } - mut znet_workload := network.to_workload(name: network_name, description: 'test_network1') - - zmachine := models.Zmachine{ - flist: 'https://hub.grid.tf/tf-official-apps/threefoldtech-ubuntu-22.04.flist' - network: models.ZmachineNetwork{ - public_ip: '' - interfaces: [ - models.ZNetworkInterface{ - network: network_name - ip: '10.1.1.3' - }, - ] - planetary: true - } - entrypoint: '/sbin/zinit init' - compute_capacity: models.ComputeCapacity{ - cpu: 1 - memory: i64(1024) * 1024 * 1024 * 2 - } - env: { - 'SSH_KEY': 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTwULSsUubOq3VPWL6cdrDvexDmjfznGydFPyaNcn7gAL9lRxwFbCDPMj7MbhNSpxxHV2+/iJPQOTVJu4oc1N7bPP3gBCnF51rPrhTpGCt5pBbTzeyNweanhedkKDsCO2mIEh/92Od5Hg512dX4j7Zw6ipRWYSaepapfyoRnNSriW/s3DH/uewezVtL5EuypMdfNngV/u2KZYWoeiwhrY/yEUykQVUwDysW/xUJNP5o+KSTAvNSJatr3FbuCFuCjBSvageOLHePTeUwu6qjqe+Xs4piF1ByO/6cOJ8bt5Vcx0bAtI8/MPApplUU/JWevsPNApvnA/ntffI+u8DCwgP' - } - } - mut zmachine_workload := zmachine.to_workload(name: 'vm2', description: 'zmachine_test') - - signature_requirement := models.SignatureRequirement{ - weight_required: 1 - requests: [ - models.SignatureRequest{ - twin_id: deployer.twin_id - weight: 1 - }, - ] - } - - mut deployment := models.new_deployment( - twin_id: deployer.twin_id - description: 'test deployment' - workloads: [znet_workload, zmachine_workload] - signature_requirement: signature_requirement - ) - deployment.add_metadata('vm', 'SimpleVM') - - contract_id := deployer.deploy(node_id, mut deployment, deployment.metadata, 0) or { - logger.error('failed to deploy deployment: ${err}') - exit(1) - } - logger.info('deployment contract id: ${contract_id}') - dl := deployer.get_deployment(contract_id, node_id) or { - logger.error('failed to get deployment data: ${err}') - exit(1) - } - - machine_res := get_machine_result(dl)! - logger.info('zmachine result: ${machine_res}') -} - -fn get_machine_result(dl models.Deployment) !models.ZmachineResult { - for _, w in dl.workloads { - if w.type_ == models.workload_types.zmachine { - res := json.decode(models.ZmachineResult, w.result.data)! - return res - } - } - - return error('failed to get zmachine workload') -} diff --git a/v2go2tgrid/tfgrid/examples/deploy_vm_high_level.v b/v2go2tgrid/tfgrid/examples/deploy_vm_high_level.v deleted file mode 100644 index 9ac4ad6b8..000000000 --- a/v2go2tgrid/tfgrid/examples/deploy_vm_high_level.v +++ /dev/null @@ -1,22 +0,0 @@ -module main - -import threefoldtech.tfgrid.models -import threefoldtech.tfgrid -import log -import os - -fn main() { - mut logger := log.Log{ - level: .debug - } - mnemonics := os.getenv('MNEMONICS') - chain_network := tfgrid.ChainNetwork.dev // User your desired network - mut deployer := tfgrid.new_deployer(mnemonics, chain_network, mut logger)! - vm := models.VM{ - name: "vm1" - env_vars: {"SSH_KEY": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTwULSsUubOq3VPWL6cdrDvexDmjfznGydFPyaNcn7gAL9lRxwFbCDPMj7MbhNSpxxHV2+/iJPQOTVJu4oc1N7bPP3gBCnF51rPrhTpGCt5pBbTzeyNweanhedkKDsCO2mIEh/92Od5Hg512dX4j7Zw6ipRWYSaepapfyoRnNSriW/s3DH/uewezVtL5EuypMdfNngV/u2KZYWoeiwhrY/yEUykQVUwDysW/xUJNP5o+KSTAvNSJatr3FbuCFuCjBSvageOLHePTeUwu6qjqe+Xs4piF1ByO/6cOJ8bt5Vcx0bAtI8/MPApplUU/JWevsPNApvnA/ntffI+u8DCwgP"} - - } - res := deployer.deploy_single_vm(11 , "myproject", vm)! - println(res) -} diff --git a/v2go2tgrid/tfgrid/examples/deploy_zdb.v b/v2go2tgrid/tfgrid/examples/deploy_zdb.v deleted file mode 100644 index 5ce5f7647..000000000 --- a/v2go2tgrid/tfgrid/examples/deploy_zdb.v +++ /dev/null @@ -1,44 +0,0 @@ -module main - -import log -import threefoldtech.tfgrid -import threefoldtech.tfgrid.models -fn main() { - mut logger := log.Log{ - level: .debug - } - - mnemonics := tfgrid.get_mnemonics() or { - logger.error(err.str()) - exit(1) - } - chain_network := tfgrid.ChainNetwork.dev // Use your desired network - mut deployer := tfgrid.new_deployer(mnemonics, chain_network, mut logger)! - - zdb := models.Zdb{ - size: u64(2) * 1024 * 1024 - mode: 'user' - password: 'pass' - } - - wl := zdb.to_workload(name: 'mywlname') - - signature_requirement := models.SignatureRequirement{ - weight_required: 1 - requests: [ - models.SignatureRequest{ - twin_id: deployer.twin_id - weight: 1 - }, - ] - } - - mut deployment := models.new_deployment( - twin_id: deployer.twin_id - workloads: [wl] - signature_requirement: signature_requirement - ) - - node_contract_id := deployer.deploy(33, mut deployment, '', 0)! - logger.info('node contract created with id ${node_contract_id}') -} diff --git a/v2go2tgrid/tfgrid/graphql.v b/v2go2tgrid/tfgrid/graphql.v deleted file mode 100644 index 546be8081..000000000 --- a/v2go2tgrid/tfgrid/graphql.v +++ /dev/null @@ -1,156 +0,0 @@ -module tfgrid - -import net.http -import json -import x.json2 -import log -import models - -pub struct GraphQl { - url string -pub mut: - logger log.Log -} - -pub struct Contract { -pub: - contract_id string [json: contractID] - deployment_data string [json: deploymentData] - state string - node_id u32 [json: nodeID] - name string -} - -pub struct Contracts { -pub mut: - name_contracts []Contract [json: nameContracts] - node_contracts []Contract [json: nodeContracts] - rent_contracts []Contract [json: rentContracts] -} - -// contractsList, err := c.ListContractsByTwinID([]string{"Created, GracePeriod"}) -pub fn (mut g GraphQl) list_twin_contracts(twin_id u32, states []string) !Contracts { - state := '[${states.join(', ')}]' - - options := '(where: {twinID_eq: ${twin_id}, state_in: ${state}}, orderBy: twinID_ASC)' - name_contracts_count := g.get_item_total_count('nameContracts', options)! - node_contracts_count := g.get_item_total_count('nodeContracts', options)! - rent_contracts_count := g.get_item_total_count('rentContracts', options)! - contracts_data := g.query('query getContracts(\$nameContractsCount: Int!, \$nodeContractsCount: Int!, \$rentContractsCount: Int!){ - nameContracts(where: {twinID_eq: ${twin_id}, state_in: ${state}}, limit: \$nameContractsCount) { - contractID - state - name - } - nodeContracts(where: {twinID_eq: ${twin_id}, state_in: ${state}}, limit: \$nodeContractsCount) { - contractID - deploymentData - state - nodeID - } - rentContracts(where: {twinID_eq: ${twin_id}, state_in: ${state}}, limit: \$rentContractsCount) { - contractID - state - nodeID - } - }', // map[string]u32{} - { - 'nodeContractsCount': node_contracts_count - 'nameContractsCount': name_contracts_count - 'rentContractsCount': rent_contracts_count - })! - - return json.decode(Contracts, contracts_data.str())! -} - -// GetItemTotalCount return count of items -fn (g GraphQl) get_item_total_count(item_name string, options string) !u32 { - count_body := 'query { items: ${item_name}Connection${options} { count: totalCount } }' - request_body := { - 'query': count_body - } - json_body := json.encode(request_body) - - resp := http.post_json(g.url, json_body)! - query_data := json2.raw_decode(resp.body)! - query_map := query_data.as_map() - - errors := query_map['errors'] or { '' }.str() - if errors != '' { - return error('graphQl query error: ${errors}') - } - - data := query_map['data']! as map[string]json2.Any - items := data['items']! as map[string]json2.Any - count := u32(items['count']!.int()) - return count -} - -struct QueryRequest { - query string - variables map[string]u32 -} - -// Query queries graphql -fn (g GraphQl) query(body string, variables map[string]u32) !map[string]json2.Any { - mut request_body := QueryRequest{ - query: body - variables: variables - } - json_body := json.encode(request_body) - resp := http.post_json(g.url, json_body)! - - query_data := json2.raw_decode(resp.body)! - data_map := query_data.as_map() - result := data_map['data']!.as_map() - return result -} - -pub fn (mut g GraphQl) get_contract_by_project_name(mut deployer Deployer, project_name string) !Contracts { - mut contracts := Contracts{} - - g.logger.debug('Getting user twin') - twin_id := get_user_twin(deployer.mnemonics, deployer.substrate_url)! - g.logger.debug('Getting twin ${twin_id} contracts...') - - contract_list := g.list_twin_contracts(twin_id, ['Created', 'GracePeriod'])! - - g.logger.debug('filtering contract with project name: ${project_name}') - for contract in contract_list.node_contracts { - data := json.decode(models.DeploymentData, contract.deployment_data)! - if data.project_name == project_name { - contracts.node_contracts << contract - } - } - g.logger.debug('filtering name contracts related to project name: ${project_name}') - gw_workload := name_gw_in_node_contract(mut deployer, contracts.node_contracts)! - contracts.name_contracts << filter_name_contract(contract_list.name_contracts, gw_workload)! - return contracts -} - -fn name_gw_in_node_contract(mut deployer Deployer, node_contracts []Contract) ![]models.Workload { - mut gw_workloads := []models.Workload{} - for contract in node_contracts { - dl := deployer.get_deployment(contract.contract_id.u64(), contract.node_id) or { - return error("Couldn't get deployment workloads: ${err}") - } - for wl in dl.workloads { - if wl.type_ == models.workload_types.gateway_name { - gw_workloads << wl - } - } - } - return gw_workloads -} - -fn filter_name_contract(name_contract []Contract, gw_workload []models.Workload) ![]Contract { - mut contracts := []Contract{} - for contract in name_contract { - for wl in gw_workload { - if wl.name == contract.name { - contracts << contract - } - } - } - return contracts -} diff --git a/v2go2tgrid/tfgrid/models/computecapacity.v b/v2go2tgrid/tfgrid/models/computecapacity.v deleted file mode 100644 index 2f9d7b4ac..000000000 --- a/v2go2tgrid/tfgrid/models/computecapacity.v +++ /dev/null @@ -1,21 +0,0 @@ -module models - -pub struct ComputeCapacity { -pub mut: - // cpu cores, minimal 10 cpu_centi_core - // always reserved with overprovisioning of about 1/4-1/6 - cpu u8 - // memory in bytes, minimal 100 MB - // always reserved - memory i64 - // min disk size reserved (to make sure you have growth potential) - // when reserved it means you payment - // if you use more, you pay for it -} - -pub fn (mut c ComputeCapacity) challenge() string { - mut out := '' - out += '${c.cpu}' - out += '${c.memory}' - return out -} diff --git a/v2go2tgrid/tfgrid/models/deployment.v b/v2go2tgrid/tfgrid/models/deployment.v deleted file mode 100644 index d1697889c..000000000 --- a/v2go2tgrid/tfgrid/models/deployment.v +++ /dev/null @@ -1,186 +0,0 @@ -module models - -import crypto.md5 -import json - -pub struct SignatureRequest { -pub mut: - // unique id as used in TFGrid DB - twin_id u32 - // if put on required then this twin_id needs to sign - required bool - // signing weight - weight int -} - -// Challenge computes challenge for SignatureRequest -pub fn (request SignatureRequest) challenge() string { - mut out := []string{} - out << '${request.twin_id}' - out << '${request.required}' - out << '${request.weight}' - - return out.join('') -} - -pub struct Signature { -pub mut: - // unique id as used in TFGrid DB - twin_id u32 - // signature (done with private key of the twin_id) - signature string - signature_type string -} - -pub struct SignatureRequirement { -pub mut: - // the requests which can allow to get to required quorum - requests []SignatureRequest - // minimal weight which needs to be achieved to let this workload become valid - weight_required int - signatures []Signature - signature_style string -} - -// Challenge computes challenge for SignatureRequest -pub fn (mut requirement SignatureRequirement) challenge() string { - mut out := []string{} - - for request in requirement.requests { - out << request.challenge() - } - - out << '${requirement.weight_required}' - out << '${requirement.signature_style}' - return out.join('') -} - -// deployment is given to each Zero-OS who needs to deploy something -// the zero-os'es will only take out what is relevant for them -// if signature not done on the main Deployment one, nothing will happen -pub struct Deployment { -pub mut: - // increments for each new interation of this model - // signature needs to be achieved when version goes up - version int = 1 - // the twin who is responsible for this deployment - twin_id u32 - // each deployment has unique id (in relation to originator) - contract_id u64 - // when the full workload will stop working - // default, 0 means no expiration - expiration i64 - metadata string - description string - // list of all worklaods - workloads []Workload - - signature_requirement SignatureRequirement -} - -[params] -pub struct DeploymentArgs { - version ?int - twin_id u32 - contract_id u64 - expiration ?i64 - metadata ?string - description ?string - workloads []Workload - signature_requirement SignatureRequirement -} - -pub fn (mut deployment Deployment) challenge() string { - // we need to scape `"` with `\"`char when sending the payload to be a valid json but when calculating the challenge we should remove `\` so we don't get invlaid signature - metadata := deployment.metadata.replace('\\"', '"') - mut out := []string{} - out << '${deployment.version}' - out << '${deployment.twin_id}' - out << '${metadata}' - out << '${deployment.description}' - out << '${deployment.expiration}' - for mut workload in deployment.workloads { - out << workload.challenge() - } - out << deployment.signature_requirement.challenge() - ret := out.join('') - return ret -} - -// ChallengeHash computes the hash of the challenge signed -// by the user. used for validation -pub fn (mut deployment Deployment) challenge_hash() []u8 { - return md5.sum(deployment.challenge().bytes()) -} - -pub fn (mut d Deployment) add_signature(twin u32, signature string) { - for mut sig in d.signature_requirement.signatures { - if sig.twin_id == twin { - sig.signature = signature - return - } - } - - d.signature_requirement.signatures << Signature{ - twin_id: twin - signature: signature - signature_type: 'sr25519' - } -} - -pub fn (mut d Deployment) json_encode() string { - mut encoded_workloads := []string{} - for mut w in d.workloads { - encoded_workloads << w.json_encode() - } - - workloads := '[${encoded_workloads.join(',')}]' - return '{"version":${d.version},"twin_id":${d.twin_id},"contract_id":${d.contract_id},"expiration":${d.expiration},"metadata":"${d.metadata}","description":"${d.description}","workloads":${workloads},"signature_requirement":${json.encode(d.signature_requirement)}}' -} - -pub fn (dl Deployment) count_public_ips() u8 { - mut count := u8(0) - for wl in dl.workloads { - if wl.type_ == workload_types.public_ip { - count += 1 - } - } - return count -} - -pub fn new_deployment(args DeploymentArgs) Deployment { - return Deployment{ - version: args.version or { 0 } - twin_id: args.twin_id - contract_id: args.contract_id - expiration: args.expiration or { 0 } - metadata: args.metadata or { '' } - description: args.description or { '' } - workloads: args.workloads - signature_requirement: args.signature_requirement - } -} - -pub struct DeploymentData { -pub: - type_ string [json: 'type'] - name string - project_name string [json: 'projectName'] -} - -pub fn (mut data DeploymentData) json_encode() string { - return "{\\\"type\\\":\\\"${data.type_}\\\",\\\"name\\\":\\\"${data.name}\\\",\\\"projectName\\\":\\\"${data.project_name}\\\"}" -} - -pub fn (mut dl Deployment) add_metadata(type_ string, project_name string) { - mut data := DeploymentData{ - type_: type_ - name: project_name - project_name: project_name - } - dl.metadata = data.json_encode() -} - -pub fn (mut d Deployment) parse_metadata() !DeploymentData { - return json.decode(DeploymentData, d.metadata)! -} diff --git a/v2go2tgrid/tfgrid/models/gw_fqdn.v b/v2go2tgrid/tfgrid/models/gw_fqdn.v deleted file mode 100644 index b009ebc67..000000000 --- a/v2go2tgrid/tfgrid/models/gw_fqdn.v +++ /dev/null @@ -1,34 +0,0 @@ -module models - -import json - -pub struct GatewayFQDNProxy { - tls_passthrough bool - backends []string - network ?string - fqdn string -} - -pub fn (g GatewayFQDNProxy) challenge() string { - mut output := '' - output += g.fqdn - output += '${g.tls_passthrough}' - for b in g.backends { - output += b - } - output += g.network or { '' } - - return output -} - -pub fn (g GatewayFQDNProxy) to_workload(args WorkloadArgs) Workload { - return Workload{ - version: args.version or { 0 } - name: args.name - type_: workload_types.gateway_fqdn - data: json.encode(g) - metadata: args.metadata or { '' } - description: args.description or { '' } - result: args.result or { WorkloadResult{} } - } -} diff --git a/v2go2tgrid/tfgrid/models/gw_name.v b/v2go2tgrid/tfgrid/models/gw_name.v deleted file mode 100644 index 758ab0504..000000000 --- a/v2go2tgrid/tfgrid/models/gw_name.v +++ /dev/null @@ -1,40 +0,0 @@ -module models - -import json - -pub struct GatewayNameProxy { - tls_passthrough bool - backends []string // format? - network ?string // format? - name string // format? -} - -pub fn (g GatewayNameProxy) challenge() string { - mut output := '' - output += g.name - output += '${g.tls_passthrough}' - for b in g.backends { - output += b - } - output += g.network or { '' } - - return output -} - -// GatewayProxyResult results -pub struct GatewayProxyResult { -pub mut: - fqdn string -} - -pub fn (g GatewayNameProxy) to_workload(args WorkloadArgs) Workload { - return Workload{ - version: args.version or { 0 } - name: args.name - type_: workload_types.gateway_name - data: json.encode(g) - metadata: args.metadata or { '' } - description: args.description or { '' } - result: args.result or { WorkloadResult{} } - } -} diff --git a/v2go2tgrid/tfgrid/models/ip.v b/v2go2tgrid/tfgrid/models/ip.v deleted file mode 100644 index 6bc587627..000000000 --- a/v2go2tgrid/tfgrid/models/ip.v +++ /dev/null @@ -1,36 +0,0 @@ -module models - -import json - -pub struct PublicIP { - v4 bool - v6 bool -} - -pub fn (p PublicIP) challenge() string { - mut output := '' - output += '${p.v4}' - output += '${p.v6}' - - return output -} - -// PublicIPResult result returned by publicIP reservation -struct PublicIPResult { -mut: - ip string - ip6 string - gateway string -} - -pub fn (p PublicIP) to_workload(args WorkloadArgs) Workload { - return Workload{ - version: args.version or { 0 } - name: args.name - type_: workload_types.public_ip - data: json.encode(p) - metadata: args.metadata or { '' } - description: args.description or { '' } - result: args.result or { WorkloadResult{} } - } -} diff --git a/v2go2tgrid/tfgrid/models/qsfs.v b/v2go2tgrid/tfgrid/models/qsfs.v deleted file mode 100644 index 6482fa3d8..000000000 --- a/v2go2tgrid/tfgrid/models/qsfs.v +++ /dev/null @@ -1,52 +0,0 @@ -module models - -pub struct QuantumSafeFS { - cache u64 - config QuantumSafeFSConfig -} - -pub struct QuantumSafeFSConfig { - minimal_shards u32 - expected_shards u32 - redundant_groups u32 - redundant_nodes u32 - max_zdb_data_dir_size u32 - encryption Encryption - meta QuantumSafeMeta - goups []ZDBGroup - compression QuantumCompression -} - -pub struct Encryption { - algorithm string // format? - key []u8 // TODO: how to create challenge, document -} - -pub struct QuantumSafeMeta { - type_ string [json: 'type'] - config QuantumSafeConfig -} - -pub struct ZDBGroup { - backends []ZDBBackend -} - -pub struct ZDBBackend { - address string // format? - namespace string - password string -} - -pub struct QuantumCompression { - algorithm string // format? -} - -pub struct QuantumSafeConfig { - prefix string - encryption Encryption - backends []ZDBBackend -} - -pub fn (qsfs QuantumSafeFS) challenge() string { - return '' -} diff --git a/v2go2tgrid/tfgrid/models/workload.v b/v2go2tgrid/tfgrid/models/workload.v deleted file mode 100644 index 6a8500574..000000000 --- a/v2go2tgrid/tfgrid/models/workload.v +++ /dev/null @@ -1,160 +0,0 @@ -module models - -import json - -pub struct WorkloadTypes { -pub: - zmachine string = 'zmachine' - zmount string = 'zmount' - network string = 'network' - zdb string = 'zdb' - public_ip string = 'ip' - qsfs string = 'qsfs' - gateway_name string = 'gateway-name-proxy' - gateway_fqdn string = 'gateway-fqdn-proxy' - zlogs string = 'zlogs' -} - -pub const workload_types = WorkloadTypes{} - -type WorkloadType = string - -pub struct ResultStates { -pub: - error ResultState = 'error' - ok ResultState = 'ok' - deleted ResultState = 'deleted' -} - -pub const result_states = ResultStates{} - -type ResultState = string - -pub fn challenge(data string, type_ string) !string { - match type_ { - models.workload_types.zmount { - mut w := json.decode(Zmount, data)! - return w.challenge() - } - models.workload_types.network { - mut w := json.decode(Znet, data)! - return w.challenge() - } - models.workload_types.zdb { - mut w := json.decode(Zdb, data)! - return w.challenge() - } - models.workload_types.zmachine { - mut w := json.decode(Zmachine, data)! - return w.challenge() - } - models.workload_types.qsfs { - mut w := json.decode(QuantumSafeFS, data)! - return w.challenge() - } - models.workload_types.public_ip { - mut w := json.decode(PublicIP, data)! - return w.challenge() - } - models.workload_types.gateway_name { - mut w := json.decode(GatewayNameProxy, data)! - return w.challenge() - } - models.workload_types.gateway_fqdn { - mut w := json.decode(GatewayFQDNProxy, data)! - return w.challenge() - } - models.workload_types.zlogs { - mut w := json.decode(ZLogs, data)! - return w.challenge() - } - else { - return '' - } - } -} - -pub enum Right { - restart - delete - stats - logs -} - -// Access Control Entry -pub struct ACE { - // the administrator twin id - twin_ids []int - rights []Right -} - -pub struct WorkloadResult { -pub mut: - created i64 - state ResultState - error string - data string [raw] // also json.RawMessage - message string -} - -pub struct Workload { -pub mut: - version u32 - // unique name per Deployment - name string - type_ WorkloadType [json: 'type'] - // this should be something like json.RawMessage in golang - data string [raw] // serialize({size: 10}) ---> "data": {size:10}, - metadata string - description string - // list of Access Control Entries - // what can an administrator do - // not implemented in zos - // acl []ACE - - result WorkloadResult -} - -pub fn (mut workload Workload) challenge() string { - mut out := []string{} - out << '${workload.version}' - out << '${workload.name}' - out << '${workload.type_}' - out << '${workload.metadata}' - out << '${workload.description}' - out << challenge(workload.data, workload.type_) or { return out.join('') } - - return out.join('') -} - -pub fn (mut w Workload) json_encode() string { - return '{"version":${w.version},"name":"${w.name}","type":"${w.type_}","data":${w.data},"metadata":"${w.metadata}","description":"${w.description}"}' -} - -type WorkloadData = GatewayFQDNProxy - | GatewayNameProxy - | PublicIP - | QuantumSafeFS - | ZLogs - | Zdb - | Zmachine - | Zmount - | Znet -type WorkloadDataResult = GatewayProxyResult - | PublicIPResult - | ZdbResult - | ZmachineResult - | ZmountResult - -// pub fn(mut w WorkloadData) challenge() string { -// return w.challenge() -// } - -[params] -pub struct WorkloadArgs { - version ?u32 - name string - description ?string - metadata ?string - result ?WorkloadResult -} diff --git a/v2go2tgrid/tfgrid/models/zdb.v b/v2go2tgrid/tfgrid/models/zdb.v deleted file mode 100644 index f90b508db..000000000 --- a/v2go2tgrid/tfgrid/models/zdb.v +++ /dev/null @@ -1,61 +0,0 @@ -module models - -import json - -type ZdbMode = string - -pub struct ZdbModes { -pub: - seq string = 'seq' - user string = 'user' -} - -pub const zdb_modes = ZdbModes{} - -type DeviceType = string - -pub struct DeviceTypes { -pub: - hdd string = 'hdd' - ssd string = 'ssd' -} - -pub const device_types = DeviceTypes{} - -pub struct Zdb { -pub mut: - // size in bytes - size u64 - mode ZdbMode - password string - public bool -} - -pub fn (mut z Zdb) challenge() string { - mut out := '' - out += '${z.size}' - out += '${z.mode}' - out += z.password - out += '${z.public}' - - return out -} - -pub struct ZdbResult { -pub mut: - namespace string - ips []string - port u32 -} - -pub fn (z Zdb) to_workload(args WorkloadArgs) Workload { - return Workload{ - version: args.version or { 0 } - name: args.name - type_: workload_types.zdb - data: json.encode(z) - metadata: args.metadata or { '' } - description: args.description or { '' } - result: args.result or { WorkloadResult{} } - } -} diff --git a/v2go2tgrid/tfgrid/models/zlogs.v b/v2go2tgrid/tfgrid/models/zlogs.v deleted file mode 100644 index 7f78b5683..000000000 --- a/v2go2tgrid/tfgrid/models/zlogs.v +++ /dev/null @@ -1,28 +0,0 @@ -module models - -import json - -pub struct ZLogs { - zmachine string // zmachine name to stream logs of - output string // the `target` location to stream the logs to, it must be a redis or web-socket url -} - -pub fn (z ZLogs) challenge() string { - mut output := '' - output += z.zmachine - output += z.output - - return output -} - -pub fn (z ZLogs) to_workload(args WorkloadArgs) Workload { - return Workload{ - version: args.version or { 0 } - name: args.name - type_: workload_types.zlogs - data: json.encode(z) - metadata: args.metadata or { '' } - description: args.description or { '' } - result: args.result or { WorkloadResult{} } - } -} diff --git a/v2go2tgrid/tfgrid/models/zmachine.v b/v2go2tgrid/tfgrid/models/zmachine.v deleted file mode 100644 index d7522c669..000000000 --- a/v2go2tgrid/tfgrid/models/zmachine.v +++ /dev/null @@ -1,118 +0,0 @@ -module models - -import json - -pub struct Zmachine { -pub mut: - flist string // if full url means custom flist meant for containers, if just name should be an official vm - network ZmachineNetwork - size u64 // size of the rootfs disk in bytes - compute_capacity ComputeCapacity - mounts []Mount - entrypoint string // how to invoke that in a vm? - env map[string]string // environment for the zmachine - corex bool - gpu []string -} - -pub struct ZmachineNetwork { -pub mut: - public_ip string // name of public ip address - interfaces []ZNetworkInterface - planetary bool -} - -pub struct ZNetworkInterface { -pub mut: - network string // Network name (znet name) to join - ip string // IP of the zmachine on this network must be a valid Ip in the selected network -} - -pub fn (mut n ZmachineNetwork) challenge() string { - mut out := '' - out += n.public_ip - out += n.planetary.str() - - for iface in n.interfaces { - out += iface.network - out += iface.ip - } - return out -} - -pub struct Mount { -pub mut: - name string - mountpoint string // the path to mount the disk into e.g. '/disk1' -} - -pub fn (mut m Mount) challenge() string { - mut out := '' - out += m.name - out += m.mountpoint - return out -} - -pub fn (mut m Zmachine) challenge() string { - mut out := '' - - out += m.flist - out += m.network.challenge() - out += '${m.size}' - out += m.compute_capacity.challenge() - - for mut mnt in m.mounts { - out += mnt.challenge() - } - out += m.entrypoint - for k, v in m.env { - out += k - out += '=' - out += v - } - return out -} - -// response of the deployment -pub struct ZmachineResult { -pub mut: - // name unique per deployment, re-used in request & response - id string - ip string - ygg_ip string - console_url string -} - -pub fn (z Zmachine) to_workload(args WorkloadArgs) Workload { - return Workload{ - version: args.version or { 0 } - name: args.name - type_: workload_types.zmachine - data: json.encode(z) - metadata: args.metadata or { '' } - description: args.description or { '' } - result: args.result or { WorkloadResult{} } - } -} - -// VM struct used to deploy machine in a high level manner -pub struct VM { - name string ='myvm' - flist string = 'https://hub.grid.tf/tf-official-apps/base:latest.flist' - entrypoint string = '/sbin/zinit init' - env_vars map[string]string - cpu int = 1 - memory int = 1024 - rootfs_size int -} - - -pub fn (vm VM) json_encode() string { - mut env_vars := []string{} - for k, v in vm.env_vars{ - env_vars << '"${k}": "${v}"' - } - - - return '{"name":"${vm.name}","flist":"${vm.flist}","entrypoint":"${vm.entrypoint}","env_vars":{${env_vars.join(",")}},"cpu":${vm.cpu},"memory":${vm.memory}, "rootfs_size": ${vm.rootfs_size}}' -} \ No newline at end of file diff --git a/v2go2tgrid/tfgrid/models/zmount.v b/v2go2tgrid/tfgrid/models/zmount.v deleted file mode 100644 index acc2e316d..000000000 --- a/v2go2tgrid/tfgrid/models/zmount.v +++ /dev/null @@ -1,32 +0,0 @@ -// ssd mounts under zmachine - -module models - -import json - -// ONLY possible on SSD -pub struct Zmount { -pub mut: - size i64 // bytes -} - -pub fn (mut mount Zmount) challenge() string { - return '${mount.size}' -} - -pub struct ZmountResult { -pub mut: - volume_id string -} - -pub fn (z Zmount) to_workload(args WorkloadArgs) Workload { - return Workload{ - version: args.version or { 0 } - name: args.name - type_: workload_types.zmount - data: json.encode(z) - metadata: args.metadata or { '' } - description: args.description or { '' } - result: args.result or { WorkloadResult{} } - } -} diff --git a/v2go2tgrid/tfgrid/models/znet.v b/v2go2tgrid/tfgrid/models/znet.v deleted file mode 100644 index 4f53abcbe..000000000 --- a/v2go2tgrid/tfgrid/models/znet.v +++ /dev/null @@ -1,96 +0,0 @@ -module models - -import json -import rand -// wg network reservation (znet) - -pub struct Znet { -pub mut: - // unique nr for each network chosen, this identified private networks as connected to a container or vm or ... - // corresponds to the 2nd number of a class B ipv4 address - // is a class C of a chosen class B - // IPV4 subnet for this network resource - // this must be a valid subnet of the entire network ip range. - // for example 10.1.1.0/24 - subnet string - // IP range of the network, must be an IPv4 /16 - // for example a 10.1.0.0/16 - ip_range string - // wireguard private key, curve25519 - wireguard_private_key string // can be generated using `wg genkey` command - wireguard_listen_port u16 - peers []Peer -} - -pub fn (mut n Znet) challenge() string { - mut out := '' - out += n.ip_range - out += n.subnet - out += n.wireguard_private_key - out += n.wireguard_listen_port.str() - for mut p in n.peers { - out += p.challenge() - } - - return out -} - -// is a remote wireguard client which can connect to this node -pub struct Peer { -pub mut: - subnet string // IPV4 subnet of the network resource of the peer - // WGPublicKey of the peer (driven from its private key) - wireguard_public_key string // can be generated by `echo | wg pubkey` command - // is ipv4 or ipv6 address from a wireguard client who connects - // this should be the node's subnet and the wireguard routing ip that should start with `100.64` - // then the 2nd and 3rd part of the node's subnet - // e.g. ["10.20.2.0/24", "100.64.20.2/32"] - allowed_ips []string - // Entrypoint of the peer; ipv4 or ipv6, - // can be empty, one of the 2 need to be filled in though - // e.g. [2a10:b600:0:9:225:90ff:fe82:7130]:7777 - endpoint string -} - -pub struct PublicConfig { -pub: - type_ string // Type define if we need to use the Vlan field or the MacVlan - ipv4 string - ipv6 string - gw4 string - gw6 string - domain string // Domain is the node domain name e.g. gent01.devnet.grid.tf -} - -pub fn (mut p Peer) challenge() string { - mut out := '' - out += p.wireguard_public_key - out += p.endpoint - out += p.subnet - - for ip in p.allowed_ips { - out += ip - } - return out -} - -pub fn (z Znet) to_workload(args WorkloadArgs) Workload { - return Workload{ - version: args.version or { 0 } - name: args.name - type_: workload_types.network - data: json.encode(z) - metadata: args.metadata or { '' } - description: args.description or { '' } - result: args.result or { WorkloadResult{} } - } -} - -pub fn rand_port(takenPorts []u16) !u16 { - mut port := u16(rand.u32n(u32(6000))! + 2000) - - for takenPorts.any(it == port) { - port = u16(rand.u32n(u32(6000))! + 2000) - } - return port -} diff --git a/v2go2tgrid/tfgrid/rmb.v b/v2go2tgrid/tfgrid/rmb.v deleted file mode 100644 index a6dcbbc98..000000000 --- a/v2go2tgrid/tfgrid/rmb.v +++ /dev/null @@ -1,59 +0,0 @@ -module tfgrid - -import os -import json -import models - -pub fn (mut d Deployer) rmb_deployment_changes(dst u32, contract_id u64) !string { - res := os.execute("grid-cli rmb-dl-changes --substrate ${d.substrate_url} --mnemonics \"${d.mnemonics}\" --relay ${d.relay_url} --dst ${dst} --contract_id '${contract_id}'") - if res.exit_code != 0 { - return error(res.output) - } - - return res.output -} - -pub fn (mut d Deployer) rmb_deployment_get(dst u32, data string) !string { - res := os.execute("grid-cli rmb-dl-get --substrate ${d.substrate_url} --mnemonics \"${d.mnemonics}\" --relay ${d.relay_url} --dst ${dst} --data '${data}'") - if res.exit_code != 0 { - return error(res.output) - } - - return res.output -} - -pub fn (mut d Deployer) get_node_pub_config(node_id u32) !models.PublicConfig { - node_twin := get_node_twin(node_id, d.substrate_url)! - res := os.execute("grid-cli rmb-node-pubConfig --substrate ${d.substrate_url} --mnemonics \"${d.mnemonics}\" --relay ${d.relay_url} --dst ${node_twin} ") - if res.exit_code != 0 { - return error(res.output.trim_space()) - } - - public_config := json.decode(models.PublicConfig, res.output) or { return err } - - return public_config -} - -pub fn (mut d Deployer) assign_wg_port(node_id u32) !u16 { - node_twin := get_node_twin(node_id, d.substrate_url)! - res := os.execute("grid-cli rmb-taken-ports --substrate ${d.substrate_url} --mnemonics \"${d.mnemonics}\" --relay ${d.relay_url} --dst ${node_twin} ") - if res.exit_code != 0 { - return error(res.output) - } - - taken_ports := json.decode([]u16, res.output) or { - return error("can't parse node taken ports: ${err}") - } - port := models.rand_port(taken_ports) or { return error("can't assign wireguard port: ${err}") } - - return port -} - -pub fn (mut d Deployer) rmb_deployment_deploy(dst u32, data string) !string { - res := os.execute("grid-cli rmb-dl-deploy --substrate ${d.substrate_url} --mnemonics \"${d.mnemonics}\" --relay ${d.relay_url} --dst ${dst} --data '${data}'") - if res.exit_code != 0 { - return error(res.output) - } - - return res.output -} diff --git a/v2go2tgrid/tfgrid/utils.v b/v2go2tgrid/tfgrid/utils.v deleted file mode 100644 index 6d0a5d8e4..000000000 --- a/v2go2tgrid/tfgrid/utils.v +++ /dev/null @@ -1,22 +0,0 @@ -module tfgrid - -import strconv -import os - -pub fn get_user_twin(mnemonics string, substrate_url string) !u32 { - res := os.execute("grid-cli user-twin --mnemonics \"${mnemonics}\" --substrate \"${substrate_url}\"") - if res.exit_code != 0 { - return error(res.output) - } - - return u32(strconv.parse_uint(res.output, 10, 32)!) -} - -pub fn get_node_twin(node_id u64, substrate_url string) !u32 { - res := os.execute('grid-cli node-twin --substrate ${substrate_url} --node_id ${node_id}') - if res.exit_code != 0 { - return error(res.output) - } - - return u32(strconv.parse_uint(res.output, 10, 32)!) -} diff --git a/v2go2tgrid/threebot.v b/v2go2tgrid/threebot.v deleted file mode 100644 index b11f04e44..000000000 --- a/v2go2tgrid/threebot.v +++ /dev/null @@ -1,27 +0,0 @@ -module threebot - -import log -import freeflowuniverse.threebot.mail -import freeflowuniverse.crystallib.rpcwebsocket - -pub struct Threebot { - mail mail.Mail -} - -pub fn (bot Threebot) run() ! { - mut logger := log.Logger(&log.Log{ - level: .debug - }) - - mail_handler := mail.new_handler( - logger: &logger - state: &bot.mail - openrpc_path: '.' - )! - - mut jsonrpc_ws_server := rpcwebsocket.new_rpcwsserver(8080, mail_handler, &logger)! - jsonrpc_ws_server.run()! -} - - -> TODO: what is this???? \ No newline at end of file