Skip to content

Commit

Permalink
update vgrid using latest v
Browse files Browse the repository at this point in the history
Signed-off-by: mariobassem <[email protected]>
  • Loading branch information
MarioBassem committed Aug 20, 2023
1 parent 5859e50 commit aeae282
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 201 deletions.
83 changes: 42 additions & 41 deletions 3bot/vgrid/examples/get_nodes_by_capacity.v
Original file line number Diff line number Diff line change
@@ -1,86 +1,87 @@
import threefoldtech.vgrid.gridproxy {TFGridNet}
import threefoldtech.vgrid.gridproxy.model {ResourceFilter, Node}
import threefoldtech.vgrid.gridproxy { TFGridNet }
import threefoldtech.vgrid.gridproxy.model { Node, ResourceFilter }
import os

fn main() {
// Default value used in intializing the resources
mut resources_filter := ResourceFilter{}

fn main(){
//Default value used in intializing the resources
mut resources_filter := ResourceFilter {}

if "--help" in os.args {
println("This script to get nodes by available resources \n
if '--help' in os.args {
println('This script to get nodes by available resources \n
--sru nodes selected should have a minumum value of free sru in GB (ssd resource unit) equal to this (optional) \n
--hru nodes selected should have a minumum value of free hru in GB (hd resource unit) equal to this (optional) \n
--mru nodes selected should have a minumum value of free mru in GB (memory resource unit) equal to this (optional) \n
--ips nodes selected should have a minumum value of ips (ips in the farm of the node) equal to this (optional)\n
--network one of (dev, test, qa, main) (optional)(default to `test`) \n
--max-count maximum number of nodes to be selected (optional)(default to 0 which means no limit) \n
--cache enable cache (optional)(default to false")
--cache enable cache (optional)(default to false')
return
}

if "--sru" in os.args {
index_val := os.args.index("--sru")
resources_filter.free_sru_gb = os.args[index_val+1].u64()
if '--sru' in os.args {
index_val := os.args.index('--sru')
resources_filter.free_sru_gb = os.args[index_val + 1].u64()
}

if "--ips" in os.args {
index_val := os.args.index("--ips")
resources_filter.free_ips = os.args[index_val+1].u64()
if '--ips' in os.args {
index_val := os.args.index('--ips')
resources_filter.free_ips = os.args[index_val + 1].u64()
}

if "--hru" in os.args {
index_val := os.args.index("--hru")
resources_filter.free_hru_gb = os.args[index_val+1].u64()
if '--hru' in os.args {
index_val := os.args.index('--hru')
resources_filter.free_hru_gb = os.args[index_val + 1].u64()
}

if "--mru" in os.args {
index_val := os.args.index("--mru")
resources_filter.free_mru_gb = os.args[index_val+1].u64()
if '--mru' in os.args {
index_val := os.args.index('--mru')
resources_filter.free_mru_gb = os.args[index_val + 1].u64()
}

mut net := "test"
if "--net" in os.args {
index_val := os.args.index("--net")
net = os.args[index_val+1]
mut net := 'test'
if '--net' in os.args {
index_val := os.args.index('--net')
net = os.args[index_val + 1]
}

mut max_count := 0
if "--max-count" in os.args {
index_val := os.args.index("--max-count")
max_count = os.args[index_val+1].int()
if '--max-count' in os.args {
index_val := os.args.index('--max-count')
max_count = os.args[index_val + 1].int()
}

mut cache := false
if "--cache" in os.args {
if '--cache' in os.args {
cache = true
}

network := match net {
"dev" {
'dev' {
TFGridNet.dev
}
"test" {
'test' {
TFGridNet.test
}
"qa" {
'qa' {
TFGridNet.qa
}
"main" {
'main' {
TFGridNet.main
}
else {
panic("network $net not supported")
panic('network ${net} not supported')
}
}
mut gp_client := gridproxy.get(network, cache)
nodes_iter := gp_client.get_nodes_has_resources(resources_filter) /* or {
mut gp_client := gridproxy.get(network, cache)!
nodes_iter := gp_client.get_nodes_has_resources(resources_filter) /*
or {
println("got an error while getting nodes")
println("error message : ${err.msg()}")
println("error code : ${err.code()}")
return
} */
mut nodes_with_min_resources := []Node {}
}*/

mut nodes_with_min_resources := []Node{}
// itereate over all availble pages on the server and get array of nodes for each page
outer: for nodes in nodes_iter {
// flatten the array of nodes into a single array
Expand All @@ -91,10 +92,10 @@ fn main(){
}
}
}
println("found $nodes_with_min_resources.len nodes on ${net.to_upper()} network with following min resources:\n$resources_filter")
println('found ${nodes_with_min_resources.len} nodes on ${net.to_upper()} network with following min resources:\n${resources_filter}')
if max_count > 0 {
println("Note: a limit of getting at most $max_count nodes was set")
println('Note: a limit of getting at most ${max_count} nodes was set')
}
println("---------------------------------------")
println('---------------------------------------')
println(nodes_with_min_resources)
}
71 changes: 35 additions & 36 deletions 3bot/vgrid/examples/get_nodes_by_city_country.v
Original file line number Diff line number Diff line change
@@ -1,76 +1,75 @@
import threefoldtech.vgrid.gridproxy {TFGridNet}
import threefoldtech.vgrid.gridproxy.model {NodeFilter, Node}
import threefoldtech.vgrid.gridproxy { TFGridNet }
import threefoldtech.vgrid.gridproxy.model { Node, NodeFilter }
import os

fn main() {
// Default value used in intializing the resources
mut nodes_filter := NodeFilter{}

fn main(){
//Default value used in intializing the resources
mut nodes_filter := NodeFilter {}

if "--help" in os.args {
println("This script to get nodes by city or country or both \n
if '--help' in os.args {
println('This script to get nodes by city or country or both \n
--city name of the city (optional) \n
--country name of the country (optional) \n
--network one of (dev, test, qa, main) (optional)(default to `test`) \n
--max-count maximum number of nodes to be selected (optional)(default to 0 which means no limit) \n
--cache enable cache (optional)(default to false")
--cache enable cache (optional)(default to false')
return
}

if "--city" in os.args {
index_val:=os.args.index("--city")
nodes_filter.city = os.args[index_val+1].to_lower().title() // ensure that the city is in title case, which is the case in the database.

if '--city' in os.args {
index_val := os.args.index('--city')
nodes_filter.city = os.args[index_val + 1].to_lower().title() // ensure that the city is in title case, which is the case in the database.
}

if "--country" in os.args {
mut index_val:=os.args.index("--country")
nodes_filter.country = os.args[index_val+1].to_lower().title() // ensure that the country is in title case, which is the case in the database.

if '--country' in os.args {
mut index_val := os.args.index('--country')
nodes_filter.country = os.args[index_val + 1].to_lower().title() // ensure that the country is in title case, which is the case in the database.
}

mut net := "test"
if "--net" in os.args {
index_val := os.args.index("--net")
net = os.args[index_val+1]
mut net := 'test'
if '--net' in os.args {
index_val := os.args.index('--net')
net = os.args[index_val + 1]
}

mut max_count := 0
if "--max-count" in os.args {
index_val := os.args.index("--max-count")
max_count = os.args[index_val+1].int()
if '--max-count' in os.args {
index_val := os.args.index('--max-count')
max_count = os.args[index_val + 1].int()
}

mut cache := false
if "--cache" in os.args {
if '--cache' in os.args {
cache = true
}

network := match net {
"dev" {
'dev' {
TFGridNet.dev
}
"test" {
'test' {
TFGridNet.test
}
"qa" {
'qa' {
TFGridNet.qa
}
"main" {
'main' {
TFGridNet.main
}
else {
panic("network $net not supported")
panic('network ${net} not supported')
}
}
mut gp_client := gridproxy.get(network, cache)
nodes_iter := gp_client.get_nodes_iterator(nodes_filter) /* or {
mut gp_client := gridproxy.get(network, cache)!
nodes_iter := gp_client.get_nodes_iterator(nodes_filter) /*
or {
println("got an error while getting nodes")
println("error message : ${err.msg()}")
println("error code : ${err.code()}")
return
} */
mut nodes_by_city_country := []Node {}
}*/

mut nodes_by_city_country := []Node{}
outer: for nodes in nodes_iter {
for node in nodes {
nodes_by_city_country << node
Expand All @@ -79,7 +78,7 @@ fn main(){
}
}
}
println("found $nodes_by_city_country.len nodes on ${net.to_upper()} in country: $nodes_filter.country and city: $nodes_filter.city")
println("---------------------------------------")
println('found ${nodes_by_city_country.len} nodes on ${net.to_upper()} in country: ${nodes_filter.country} and city: ${nodes_filter.city}')
println('---------------------------------------')
println(nodes_by_city_country)
}
Loading

0 comments on commit aeae282

Please sign in to comment.