This commit is contained in:
2024-02-23 06:07:41 +03:00
commit a83f4cd5e8
1963 changed files with 56869 additions and 0 deletions

View File

@@ -0,0 +1,158 @@
# TF Grid DB client
is written in vlang see https://vlang.io/
source see https://github.com/threefoldtech/vgrid/tree/main/tfgriddb
## Prerequisites
- install vlang
to install client do
```
v install https://github.com/threefoldtech/vgrid
```
## Usage
By default the client has a local cache which makes sure you are not hitting the graphql backend all the time.
Caching happens in redis (if started on your local machine).
```v
#import explorer client
import threefoldtech.vgrid.explorer
// Create a new instance of the client
mut explorer := explorer.get(.test)
//TO MAKE SURE CACHE IS EMPTY DO FOLLOWING
explorer.cache_drop_all()?
// mut r := explorer.twin_list()?
mut r := explorer.nodes_list()?
println(r)
```
## List entities
```v
entities := tfgrid.entity_list()?
println(entities)
```
## Get Entity by ID
```v
entity := tfgrid.entity_get_by_id(1) ?
print(entity)
```
## List twins
```v
twins := tfgrid.twin_list()?
println(twins)
```
## Get Twin by ID
```v
twin := tfgrid.twin_get_by_id(1) ?
print(twin)
```
## List nodes
```v
nodes := tfgrid.nodes_list()?
println(nodes)
```
## Get Node by ID
```v
node := tfgrid.nodes_get_by_id(1) ?
print(node)
```
## Get Nodes by resource values
```v
sru := 150
cru := 2
hru := 3000
mru := 5
nodes_by_resources := tfgrid.nodes_list_by_resource(sru, cru, hru, mru)?
println(nodes_by_resources)
```
## List farms
```v
farms := tfgrid.farms_list()?
println(farms)
```
## Get farm by ID
```v
farm := tfgrid.farm_get_by_id(1) ?
print(farm)
```
## List countries
```v
countries := tfgrid.countries_list()?
println(countries)
```
## Get country by substring in name
```v
countries_by_name_substring := tfgrid.countries_by_name_substring("elgium")?
println(countries_by_name_substring)
```
## Get country by ID
```v
country_by_id := tfgrid.country_by_id(65)?
println(country_by_id)
```
## List cities
```v
cities := tfgrid.cities_list()?
println(cities)
```
## Get cities by substring in name
```v
cities_by_name_substring := tfgrid.cities_by_name_substring("hent")?
println(cities_by_name_substring)
```
## Get city by ID
```v
city_by_id := tfgrid.city_by_id(65)?
println(city_by_id)
```
## Get city by country_id
```v
cities_by_country_id := tfgrid.cities_by_country_id(65)?
println(cities_by_country_id)
```
.

View File

@@ -0,0 +1,194 @@
```vlang
mut tfgrid := tfgriddb.tfgrid_new() ?
entities := tfgrid.entity_list() ?
println(entities)
entity := tfgrid.entity_get_by_id(1) ?
print(entity)
twins := tfgrid.twin_list() ?
println(twins)
twin := tfgrid.twin_get_by_id(1) ?
print(twin)
nodes := tfgrid.nodes_list() ?
println(nodes)
node := tfgrid.nodes_get_by_id(1) ?
print(node)
farms := tfgrid.farms_list() ?
println(farms)
farm := tfgrid.farm_get_by_id(1) ?
print(farm)
nodes_by_resources := tfgrid.nodes_list_by_resource(1, 1, 500, 1) ?
println(nodes_by_resources)
countries := tfgrid.countries_list() ?
println(countries)
// Search for country belgium
countries_by_name_substring := tfgrid.countries_by_name_substring('elgium') ?
println(countries_by_name_substring)
country_by_id := tfgrid.country_by_id(65) ?
println(country_by_id)
cities := tfgrid.cities_list() ?
println(cities)
// Search for cities with substring "hent"
cities_by_name_substring := tfgrid.cities_by_name_substring('hent') ?
println(cities_by_name_substring)
city_by_id := tfgrid.city_by_id(65) ?
println(city_by_id)
cities_by_country_id := tfgrid.cities_by_country_id(65) ?
println(cities_by_country_id)
```
>TODO: explain more, make sure code in the vgrid repo works
## Example: nodes by capacity
```v
import tfgriddb
import os
fn get_nodes_by_capacity(sru u64, cru u64, hru u64, mru u64)? {
mut tfgrid := tfgriddb.tfgrid_new() ?
mut nodes_by_capacity := tfgrid.nodes_list_by_resource(sru,cru,hru,mru)?
println(nodes_by_capacity)
}
fn main(){
//Default value used in intializing the resources
mut default_val := '0'.u64()
mut sru := default_val
mut cru := default_val
mut hru := default_val
mut mru := default_val
if "--help" in os.args {
println("This method to get nodes by city or country or both \n
--sru nodes selected should have a minumum value of sru (ssd resource unit) equal to this (optional) \n
--cru nodes selected should have a minumum value of cru (core resource unit) equal to this (optional) \n
--hru nodes selected should have a minumum value of hru (hd resource unit) equal to this (optional) \n
--mru nodes selected should have a minumum value of mru (memory resource unit) equal to this (optional) ")
return
}
if "--sru" in os.args {
mut index_val := os.args.index("--sru")
sru = os.args[index_val+1].u64()
}
if "--cru" in os.args {
mut index_val := os.args.index("--cru")
cru = os.args[index_val+1].u64()
}
if "--hru" in os.args {
mut index_val := os.args.index("--hru")
hru = os.args[index_val+1].u64()
}
if "--mru" in os.args {
mut index_val := os.args.index("--mru")
mru = os.args[index_val+1].u64()
}
get_nodes_by_capacity(sru, cru, hru, mru) or { return }
}
```
## Example: nodes by city/country
```v
import tfgriddb
import os
fn get_nodes_by_city_country(geo_location tfgriddb.GeoLocation) ? {
mut tfgrid := tfgriddb.tfgrid_new() ?
mut nodes_by_country_city := tfgrid.nodes_by_country_city(geo_location)?
println(nodes_by_country_city)
}
fn main(){
mut geo_location := tfgriddb.GeoLocation{}
mut city_name := ""
mut country_name := ""
if "--help" in os.args {
println("This method to get nodes by city or country or both \n
--city name of the city (optional) \n
--country name of the country (optional) ")
return
}
if "--city" in os.args {
mut index_val:=os.args.index("--city")
city_name = os.args[index_val+1]
geo_location.city_name = city_name
}
if "--country" in os.args {
mut index_val:=os.args.index("--country")
country_name = os.args[index_val+1]
geo_location.country_name = country_name
}
if city_name == "" && country_name == ""{
println("Please specify a city or country name")
return
}
get_nodes_by_city_country(geo_location) or {return }
}
```
## Example: nodes by location
```v
import tfgriddb
import os
fn get_nodes_by_location(latitude string,longitude string) ? {
mut tfgrid := tfgriddb.tfgrid_new() ?
mut nodes_by_location := tfgrid.nodes_by_location(latitude,longitude)?
println(nodes_by_location)
}
fn main(){
mut latitude:=""
mut longitude:=""
if "--help" in os.args {
println("This method to get nodes by location including latitude and longitude \n
--latitude value (required) \n
--longitude value (required) ")
return
}
if "--latitude" in os.args {
mut index_val:=os.args.index("--latitude")
latitude = os.args[index_val+1]
}else{
println("--latitude is required")
return
}
if "--longitude" in os.args {
mut index_val:=os.args.index("--longitude")
longitude = os.args[index_val+1]
}else{
println("--longitude is required")
return
}
get_nodes_by_location(latitude,longitude) or {return }
}
```
.

View File

@@ -0,0 +1,148 @@
Info on TFChain is indexed over GraphQL and is available for queries.
- [Devnet GraphQL](https://graphql.dev.grid.tf/graphql)
- [Qanet GraphQL](https://graphql.qa.grid.tf/graphql)
- [Testnet GraphQL](https://graphql.test.grid.tf/graphql)
- [Mainnet GraphQL](https://graphql.grid.tf/graphql)
## getting lots of nodes
```graphql
query MyQuery {
nodes(orderBy: nodeId_ASC, limit: 5000, where: {
cru_gt: "2", hru_gt: "500000000", mru_gt: "50000000", sru_gt: "1000000000",
deletedAt_eq: null
})
{
twinId
city
certificationType
country
created
createdById
cru
farmId
hru
id
uptime
version
mru
sru
nodeId
interfaces {
ips
name
node {
city
country
cru
hru
sru
mru
}
}
location {
latitude
longitude
}
publicConfig {
domain
gw4
gw6
ipv4
ipv6
}
deletedById
}
}
```
## finding gateways
gateway typically needs to be a node with public ipv4 or ipv6 and a domain configured otherwise it won't be able to create `NameContracts`
```graphql
query MyQuery {
nodes {
nodeId
publicConfig {
domain
ipv4
}
}
}
```
## finding farms with public IPs
```graphql
query MyQuery {
farms {
farmId
name
publicIPs {
ip
}
}
}
```
## finding nodes on a specific farm
```graphql
query MyQuery {
nodes(where: {farmId_eq: 1}) {
twinId
}
}
```
## finding nodes with country
```graphql
query MyQuery {
nodes(where: {country_eq: "BE"}) {
twinId
}
}
```
## finding nodes with capacity
```graphql
query MyQuery {
nodes() {
cru,
hru,
mru,
sru,
}
}
```
the cru/... are in bytes !
## filtering nodes with capacity
```graphql
query MyQuery {
nodes(where: {cru_gt: "2", hru_gt: "500000000", mru_gt: "50000000", sru_gt: "1000000000"}) {
nodeId
cru
hru
mru
sru
}
}
```
the cru/... are in bytes !
> NOTE: most of this is available on our [explorer portal](explorer_home).

View File

@@ -0,0 +1,6 @@
# Graphql
> TODO: more docs
> TODO: intro

View File

@@ -0,0 +1,9 @@
- [**Home**](@threefold:threefold_home)
- [**Manual 3 Home**](@manual3_home_new)
-----------
**explorer examples**
<!-- - [Grapqhl Examples](@explorer_graphql_examples) -->
- [V Explorer Client](@explorer_api)
- [V Explorer API Examples](@explorer_api_examples)

View File

@@ -0,0 +1,158 @@
# TF Grid DB client
is written in vlang see https://vlang.io/
source see https://github.com/threefoldtech/vgrid/tree/main/tfgriddb
## Prerequisites
- install vlang
to install client do
```
v install https://github.com/threefoldtech/vgrid
```
## Usage
By default the client has a local cache which makes sure you are not hitting the graphql backend all the time.
Caching happens in redis (if started on your local machine).
```v
#import explorer client
import threefoldtech.vgrid.explorer
// Create a new instance of the client
mut explorer := explorer.get(.test)
//TO MAKE SURE CACHE IS EMPTY DO FOLLOWING
explorer.cache_drop_all()?
// mut r := explorer.twin_list()?
mut r := explorer.nodes_list()?
println(r)
```
## List entities
```v
entities := tfgrid.entity_list()?
println(entities)
```
## Get Entity by ID
```v
entity := tfgrid.entity_get_by_id(1) ?
print(entity)
```
## List twins
```v
twins := tfgrid.twin_list()?
println(twins)
```
## Get Twin by ID
```v
twin := tfgrid.twin_get_by_id(1) ?
print(twin)
```
## List nodes
```v
nodes := tfgrid.nodes_list()?
println(nodes)
```
## Get Node by ID
```v
node := tfgrid.nodes_get_by_id(1) ?
print(node)
```
## Get Nodes by resource values
```v
sru := 150
cru := 2
hru := 3000
mru := 5
nodes_by_resources := tfgrid.nodes_list_by_resource(sru, cru, hru, mru)?
println(nodes_by_resources)
```
## List farms
```v
farms := tfgrid.farms_list()?
println(farms)
```
## Get farm by ID
```v
farm := tfgrid.farm_get_by_id(1) ?
print(farm)
```
## List countries
```v
countries := tfgrid.countries_list()?
println(countries)
```
## Get country by substring in name
```v
countries_by_name_substring := tfgrid.countries_by_name_substring("elgium")?
println(countries_by_name_substring)
```
## Get country by ID
```v
country_by_id := tfgrid.country_by_id(65)?
println(country_by_id)
```
## List cities
```v
cities := tfgrid.cities_list()?
println(cities)
```
## Get cities by substring in name
```v
cities_by_name_substring := tfgrid.cities_by_name_substring("hent")?
println(cities_by_name_substring)
```
## Get city by ID
```v
city_by_id := tfgrid.city_by_id(65)?
println(city_by_id)
```
## Get city by country_id
```v
cities_by_country_id := tfgrid.cities_by_country_id(65)?
println(cities_by_country_id)
```
.

View File

@@ -0,0 +1,3 @@
```rest
https://gridproxy.test.grid.tf/nodes/1
```

View File

@@ -0,0 +1,8 @@
- [**Home**](@threefold:threefold_home)
- [**Manual 3 Home**](@manual3_home_new)
-----------
**Grid Proxy**
- [Grid Proxy](@grid_proxy)
- [Grid Proxy Examples](@grid_proxy_examples)

View File

@@ -0,0 +1,9 @@
# Supported Flists
|flist|entrypoint|env vars|
|:--:|:--:|--|
|[Alpine](https://hub.grid.tf/tf-official-apps/threefoldtech-alpine-3.flist.md)|`/entrypoint.sh`|`SSH_KEY`|
|[Ubuntu](https://hub.grid.tf/tf-official-apps/threefoldtech-ubuntu-22.04.flist.md)|`/init.sh`|`SSH_KEY`|
|[CentOS](https://hub.grid.tf/tf-official-apps/threefoldtech-centos-8.flist.md)|`/entrypoint.sh`|`SSH_KEY`|
|[K3s](https://hub.grid.tf/tf-official-apps/threefoldtech-k3s-latest.flist.md)|`/sbin/zinit init`|- `SSH_KEY` <br/>- `K3S_TOKEN` <br/>- `K3S_DATA_DIR`<br/>- `K3S_FLANNEL_IFACE`<br/>- `K3S_NODE_NAME`<br/> - `K3S_URL` `https://${masterIp}:6443`|

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

View File

@@ -0,0 +1,25 @@
![ ](./img/iac_.png)
# Infrastructure As Code
Infrastructure as code is the process of managing and provisioning computer data centers through machine-readable definition files, rather than physical hardware configuration or interactive configuration tools.
## Advantages
1. Faster speed and consistency: The goal of IaC is to make things faster by eliminating manual processes and eliminating the slack in the process. A code-based approach makes it easier to get more done in less time. No need to wait on the IT Admin to manually complete the task at hand before he can get to the next one. This also means that you can iterate quickly and more often. Consistency is another vital benefit of IaC. You do not need to worry about tasks not being completed because it is a weekend or because your admin is focused on something else. Also, you can implement changes globally while keeping the same version of the software, etc.
2. Efficient software development lifecycle: IaC shifts the power into the developers hands. As the infrastructure provisioning becomes more reliable and consistent, developers can start focusing on application development more. Also, they can script once and use that code multiple times, thus, saving time and effort while keeping complete control.
3. Reduced management overhead: In a data center world there was a need to have admins to govern and manage storage, networking, compute and other layers of hardware and middleware. IaC eliminates a need for these multiple roles. Those admins can now focus on identifying the next exciting technology they want to implement.
## Our main tool = Terraform
Is an opensource IAC tool, fully integrated with ThreeFold Cloud software.
## Links
- [What you need to know](@grid3_developer_basics)
- [Terraform](@grid3_terraform_home)
- [TypeScript Client](@grid3_javascript_home)
- [GraphQL Client](@graphql)
- [Grid Proxy REST API](@grid_proxy)
*more info: wikipedia, [cloudbolt](https://www.cloudbolt.io/blog/3-advantages-and-challenges-of-infrastructure-as-code-iac/),[stackpath(https://blog.stackpath.com/infrastructure-as-code-explainer/)*