Skip to content
This repository has been archived by the owner on Dec 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #505 from freeflowuniverse/development_runner_feat
Browse files Browse the repository at this point in the history
Development runner feat
  • Loading branch information
mariobassem authored Dec 24, 2024
2 parents 28ce22f + f41cf85 commit 41448fd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
6 changes: 3 additions & 3 deletions crystallib/threefold/gridproxy/model/filter.v
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,6 @@ pub fn (p &NodeFilter) to_map() map[string]string {
EmptyOption {}
bool {
m['ipv4'] = p.ipv4.str()
if p.ipv4 == true {
m['features'] = 'ipv4'
}
}
}
match p.ipv6 {
Expand Down Expand Up @@ -450,6 +447,9 @@ pub fn (p &NodeFilter) to_map() map[string]string {
m['available_for'] = p.available_for.str()
}
}
if p.features.len > 0 {
m['features'] = json.encode(p.features).all_after('[').all_before(']')
}
if p.farm_ids.len > 0 {
m['farm_ids'] = json.encode(p.farm_ids).all_after('[').all_before(']')
}
Expand Down
14 changes: 8 additions & 6 deletions crystallib/threefold/tfgrid3deployer/deployment.v
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,12 @@ fn (mut self TFDeployment) set_nodes() ! {
nodes := filter_nodes(
node_ids: node_ids
healthy: true
free_mru: u64(vm.requirements.memory) * 1024 * 1024 * 1024
free_mru: convert_to_gigabytes(u64(vm.requirements.memory))
total_cru: u64(vm.requirements.cpu)
free_ips: if vm.requirements.public_ip4 { u64(1) } else { none }
has_ipv6: if vm.requirements.public_ip6 { vm.requirements.public_ip6 } else { none }
status: 'up'
features: if vm.requirements.public_ip4 { [] } else { ['zmachine'] }
)!

if nodes.len == 0 {
Expand All @@ -119,7 +120,7 @@ fn (mut self TFDeployment) set_nodes() ! {
}

for mut zdb in self.zdbs {
size := u64(zdb.requirements.size) * 1024 * 1024 * 1024
size := convert_to_gigabytes(u64(zdb.requirements.size))
nodes := filter_nodes(
free_sru: size
status: 'up'
Expand All @@ -136,10 +137,11 @@ fn (mut self TFDeployment) set_nodes() ! {

for mut webname in self.webnames {
nodes := filter_nodes(
domain: true
status: 'up'
healthy: true
node_id: webname.requirements.node_id
domain: true
status: 'up'
healthy: true
node_id: webname.requirements.node_id
features: ['zmachine']
)!

if nodes.len == 0 {
Expand Down
46 changes: 23 additions & 23 deletions crystallib/threefold/tfgrid3deployer/deployment_setup.v
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ mut:
// - None
fn new_deployment_setup(network_specs NetworkSpecs, vms []VMachine, zdbs []ZDB, webnames []WebName, old_deployments map[u32]grid_models.Deployment, mut deployer grid.Deployer) !DeploymentSetup {
mut dls := DeploymentSetup{
deployer: deployer
deployer: deployer
network_handler: NetworkHandler{
deployer: deployer
deployer: deployer
network_name: network_specs.name
mycelium: network_specs.mycelium
ip_range: network_specs.ip_range
mycelium: network_specs.mycelium
ip_range: network_specs.ip_range
}
}

Expand Down Expand Up @@ -122,15 +122,15 @@ fn (mut self DeploymentSetup) setup_zdb_workloads(zdbs []ZDB) ! {

// Create the Zdb model with the size converted to bytes
zdb_model := grid_models.Zdb{
size: u64(req.size) * 1024 * 1024 * 1024 // Convert size from MB to bytes
mode: req.mode
public: req.public
size: convert_to_gigabytes(u64(req.size)) // Convert size from MB to bytes
mode: req.mode
public: req.public
password: req.password
}

// Generate a workload based on the Zdb model
zdb_workload := zdb_model.to_workload(
name: req.name
name: req.name
description: req.description
)

Expand Down Expand Up @@ -162,8 +162,8 @@ fn (mut self DeploymentSetup) setup_webname_workloads(webnames []WebName) ! {

gw := grid_models.GatewayNameProxy{
tls_passthrough: req.tls_passthrough
backends: [req.backend]
name: gw_name
backends: [req.backend]
name: gw_name
}

self.workloads[wn.node_id] << gw.to_workload(
Expand All @@ -190,39 +190,39 @@ fn (mut self DeploymentSetup) set_zmachine_workload(vmachine VMachine, public_ip
env_map['SSH_KEY'] = grid_client.ssh_key

zmachine_workload := grid_models.Zmachine{
network: grid_models.ZmachineNetwork{
network: grid_models.ZmachineNetwork{
interfaces: [
grid_models.ZNetworkInterface{
network: self.network_handler.network_name
ip: if vmachine.wireguard_ip.len > 0 {
ip: if vmachine.wireguard_ip.len > 0 {
used_ip_octets[vmachine.node_id] << vmachine.wireguard_ip.all_after_last('.').u8()
vmachine.wireguard_ip
} else {
self.assign_private_ip(vmachine.node_id, mut used_ip_octets)!
}
},
]
public_ip: public_ip_name
planetary: vmachine.requirements.planetary
mycelium: if mycelium := vmachine.requirements.mycelium {
public_ip: public_ip_name
planetary: vmachine.requirements.planetary
mycelium: if mycelium := vmachine.requirements.mycelium {
grid_models.MyceliumIP{
network: self.network_handler.network_name
network: self.network_handler.network_name
hex_seed: mycelium.hex_seed
}
} else {
none
}
}
size: vmachine.requirements.size
flist: vmachine.requirements.flist
entrypoint: vmachine.requirements.entrypoint
size: convert_to_gigabytes(u64(vmachine.requirements.size))
flist: vmachine.requirements.flist
entrypoint: vmachine.requirements.entrypoint
compute_capacity: grid_models.ComputeCapacity{
cpu: u8(vmachine.requirements.cpu)
memory: i64(vmachine.requirements.memory) * 1024 * 1024 * 1024
cpu: u8(vmachine.requirements.cpu)
memory: i64(convert_to_gigabytes(u64(vmachine.requirements.memory)))
}
env: env_map
env: env_map
}.to_workload(
name: vmachine.requirements.name
name: vmachine.requirements.name
description: vmachine.requirements.description
)

Expand Down
4 changes: 4 additions & 0 deletions crystallib/threefold/tfgrid3deployer/utils.v
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ pub fn filter_nodes(filter gridproxy_models.NodeFilter) ![]gridproxy_models.Node
nodes := gp_client.get_nodes(filter)!
return nodes
}

fn convert_to_gigabytes(bytes u64) u64 {
return bytes * 1024 * 1024 * 1024
}
1 change: 0 additions & 1 deletion crystallib/threefold/tfgrid3deployer/vmachine.v
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub mut:
public_ip4 bool
public_ip6 bool
planetary bool
size u64
mycelium ?Mycelium
flist string = 'https://hub.grid.tf/tf-official-vms/ubuntu-24.04-latest.flist'
entrypoint string = '/sbin/zinit init'
Expand Down

0 comments on commit 41448fd

Please sign in to comment.