...
This commit is contained in:
41
lib/threefold/grid4/cloudslices/cloudbox.v
Normal file
41
lib/threefold/grid4/cloudslices/cloudbox.v
Normal file
@@ -0,0 +1,41 @@
|
||||
module cloudslices
|
||||
|
||||
import time
|
||||
|
||||
pub struct CloudBox {
|
||||
pub mut:
|
||||
amount int
|
||||
description string
|
||||
storage_gb f64
|
||||
passmark int
|
||||
vcores int
|
||||
mem_gb f64
|
||||
price_range []f64 = [0.0, 0.0]
|
||||
price_simulation f64
|
||||
ssd_nr int
|
||||
}
|
||||
|
||||
pub struct AIBox {
|
||||
pub mut:
|
||||
amount int
|
||||
gpu_brand string
|
||||
gpu_version string
|
||||
description string
|
||||
storage_gb f64
|
||||
passmark int
|
||||
vcores int
|
||||
mem_gb f64
|
||||
mem_gb_gpu f64
|
||||
price_range []f64 = [0.0, 0.0]
|
||||
price_simulation f64
|
||||
hdd_nr int
|
||||
ssd_nr int
|
||||
}
|
||||
|
||||
pub struct StorageBox {
|
||||
pub mut:
|
||||
amount int
|
||||
description string
|
||||
price_range []f64 = [0.0, 0.0]
|
||||
price_simulation f64
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
module cloudslices
|
||||
|
||||
import time
|
||||
|
||||
pub struct Node {
|
||||
pub mut:
|
||||
id int
|
||||
name string
|
||||
cost f64
|
||||
deliverytime time.Time
|
||||
description string
|
||||
cpu_brand string
|
||||
cpu_version string
|
||||
inca_reward int
|
||||
image string
|
||||
mem string
|
||||
hdd string
|
||||
ssd string
|
||||
url string
|
||||
reputation int
|
||||
uptime int // 0..100
|
||||
continent string
|
||||
country string
|
||||
passmark int
|
||||
cloudbox []CloudBox
|
||||
aibox []AIBox
|
||||
storagebox []StorageBox
|
||||
vendor string
|
||||
grant NodeGrant
|
||||
}
|
||||
|
||||
pub struct NodeGrant {
|
||||
pub mut:
|
||||
grant_month_usd string
|
||||
grant_month_inca string
|
||||
grant_max_nrnodes int
|
||||
}
|
||||
|
||||
pub struct CloudBox {
|
||||
pub mut:
|
||||
amount int
|
||||
description string
|
||||
storage_gb f64
|
||||
passmark int
|
||||
vcores int
|
||||
mem_gb f64
|
||||
price_range []f64 = [0.0, 0.0]
|
||||
price_simulation f64
|
||||
ssd_nr int
|
||||
}
|
||||
|
||||
pub struct AIBox {
|
||||
pub mut:
|
||||
amount int
|
||||
gpu_brand string
|
||||
gpu_version string
|
||||
description string
|
||||
storage_gb f64
|
||||
passmark int
|
||||
vcores int
|
||||
mem_gb f64
|
||||
mem_gb_gpu f64
|
||||
price_range []f64 = [0.0, 0.0]
|
||||
price_simulation f64
|
||||
hdd_nr int
|
||||
ssd_nr int
|
||||
}
|
||||
|
||||
pub struct StorageBox {
|
||||
pub mut:
|
||||
amount int
|
||||
description string
|
||||
price_range []f64 = [0.0, 0.0]
|
||||
price_simulation f64
|
||||
}
|
||||
|
||||
fn (mut n Node) validate_percentage(v int) ! {
|
||||
if v < 0 || v > 100 {
|
||||
return error('Value must be between 0 and 100')
|
||||
}
|
||||
}
|
||||
|
||||
pub fn preprocess_value(v string) string {
|
||||
// Implement the preprocessing logic here
|
||||
return v
|
||||
}
|
||||
|
||||
pub fn (mut n Node) preprocess_location(v string) ! {
|
||||
n.continent = preprocess_value(v)
|
||||
n.country = preprocess_value(v)
|
||||
}
|
||||
|
||||
// pub fn (mut n Node) parse_deliverytime(v string) ! {
|
||||
// n.deliverytime = time.parse(v, 'YYYY-MM-DD')!
|
||||
// }
|
||||
@@ -2,74 +2,64 @@ module cloudslices
|
||||
|
||||
import time
|
||||
|
||||
// NodeTotal represents the aggregated data for a node, including hardware specifications, pricing, and location details.
|
||||
pub struct NodeTotal {
|
||||
pub mut:
|
||||
id int
|
||||
name string
|
||||
cost f64
|
||||
deliverytime time.Time
|
||||
description string
|
||||
cpu_brand string
|
||||
cpu_version string
|
||||
inca_reward int
|
||||
image string
|
||||
mem string
|
||||
hdd string
|
||||
ssd string
|
||||
url string
|
||||
reputation int
|
||||
uptime int
|
||||
continent string
|
||||
country string
|
||||
|
||||
storage_gb f64
|
||||
mem_gb f64
|
||||
mem_gb_gpu f64
|
||||
price_simulation f64
|
||||
passmark int
|
||||
vcores int
|
||||
pub mut:
|
||||
id int // Unique identifier for the node
|
||||
cost f64 // Total cost of the node
|
||||
deliverytime time.Time // Expected delivery time
|
||||
inca_reward int // Incentive reward for the node
|
||||
reputation int // Reputation score of the node
|
||||
uptime int // Uptime percentage
|
||||
price_simulation f64 // Simulated price for the node
|
||||
info NodeInfo // Descriptive information about the node
|
||||
capacity NodeCapacity // Hardware capacity details
|
||||
}
|
||||
|
||||
// node_total calculates the total values for storage, memory, price simulation, passmark, and vcores by summing up the contributions from different types of boxes.
|
||||
pub fn (n Node) node_total() NodeTotal {
|
||||
mut total := NodeTotal{
|
||||
id: n.id
|
||||
name: n.name
|
||||
cost: n.cost
|
||||
deliverytime: n.deliverytime
|
||||
description: n.description
|
||||
cpu_brand: n.cpu_brand
|
||||
cpu_version: n.cpu_version
|
||||
inca_reward: n.inca_reward
|
||||
image: n.image
|
||||
mem: n.mem
|
||||
hdd: n.hdd
|
||||
ssd: n.ssd
|
||||
url: n.url
|
||||
reputation: n.reputation
|
||||
uptime: n.uptime
|
||||
continent: n.continent
|
||||
country: n.country
|
||||
}
|
||||
for box in n.cloudbox {
|
||||
total.storage_gb += box.storage_gb * f64(box.amount)
|
||||
total.mem_gb += box.mem_gb * f64(box.amount)
|
||||
total.price_simulation += box.price_simulation * f64(box.amount)
|
||||
total.passmark += box.passmark * box.amount
|
||||
total.vcores += box.vcores * box.amount
|
||||
}
|
||||
mut total := NodeTotal{
|
||||
id: n.id
|
||||
cost: n.cost
|
||||
deliverytime: n.deliverytime
|
||||
inca_reward: n.inca_reward
|
||||
reputation: n.reputation
|
||||
uptime: n.uptime
|
||||
info: NodeInfo{
|
||||
name: n.name
|
||||
description: n.description
|
||||
cpu_brand: n.cpu_brand
|
||||
cpu_version: n.cpu_version
|
||||
image: n.image
|
||||
mem: n.mem
|
||||
hdd: n.hdd
|
||||
ssd: n.ssd
|
||||
url: n.url
|
||||
continent: n.continent
|
||||
country: n.country
|
||||
},
|
||||
capacity: NodeCapacity{}
|
||||
}
|
||||
for box in n.cloudbox {
|
||||
total.capacity.storage_gb += box.storage_gb * f64(box.amount)
|
||||
total.capacity.mem_gb += box.mem_gb * f64(box.amount)
|
||||
total.price_simulation += box.price_simulation * f64(box.amount)
|
||||
total.capacity.passmark += box.passmark * box.amount
|
||||
total.capacity.vcores += box.vcores * box.amount
|
||||
}
|
||||
|
||||
for box in n.aibox {
|
||||
total.storage_gb += box.storage_gb * f64(box.amount)
|
||||
total.mem_gb += box.mem_gb * f64(box.amount)
|
||||
total.mem_gb_gpu += box.mem_gb_gpu * f64(box.amount)
|
||||
total.price_simulation += box.price_simulation * f64(box.amount)
|
||||
total.passmark += box.passmark * box.amount
|
||||
total.vcores += box.vcores * box.amount
|
||||
}
|
||||
for box in n.aibox {
|
||||
total.capacity.storage_gb += box.storage_gb * f64(box.amount)
|
||||
total.capacity.mem_gb += box.mem_gb * f64(box.amount)
|
||||
total.capacity.mem_gb_gpu += box.mem_gb_gpu * f64(box.amount)
|
||||
total.price_simulation += box.price_simulation * f64(box.amount)
|
||||
total.capacity.passmark += box.passmark * box.amount
|
||||
total.capacity.vcores += box.vcores * box.amount
|
||||
}
|
||||
|
||||
for box in n.storagebox {
|
||||
total.price_simulation += box.price_simulation * f64(box.amount)
|
||||
}
|
||||
for box in n.storagebox {
|
||||
total.price_simulation += box.price_simulation * f64(box.amount)
|
||||
}
|
||||
|
||||
return total
|
||||
return total
|
||||
}
|
||||
|
||||
73
lib/threefold/grid4/cloudslices/model_node.v
Normal file
73
lib/threefold/grid4/cloudslices/model_node.v
Normal file
@@ -0,0 +1,73 @@
|
||||
module cloudslices
|
||||
|
||||
import time
|
||||
|
||||
pub struct Node {
|
||||
pub mut:
|
||||
id int
|
||||
cost f64
|
||||
deliverytime time.Time
|
||||
inca_reward int
|
||||
reputation int
|
||||
uptime int // 0..100
|
||||
cloudbox []CloudBox
|
||||
aibox []AIBox
|
||||
storagebox []StorageBox
|
||||
vendor string
|
||||
grant NodeGrant
|
||||
info NodeInfo // Descriptive information about the node
|
||||
capacity NodeCapacity // Hardware capacity details
|
||||
}
|
||||
|
||||
|
||||
// NodeInfo represents the descriptive information about a node.
|
||||
pub struct NodeInfo {
|
||||
pub mut:
|
||||
cpu_brand string // Brand of the CPU
|
||||
cpu_version string // Version of the CPU
|
||||
mem string // Memory specification
|
||||
hdd string // HDD specification
|
||||
ssd string // SSD specification
|
||||
url string // URL for more information
|
||||
continent string // Continent where the node is located
|
||||
country string // Country where the node is located
|
||||
}
|
||||
|
||||
// NodeCapacity represents the hardware capacity details of a node.
|
||||
pub struct NodeCapacity {
|
||||
pub mut:
|
||||
storage_gb f64 // Total storage in gigabytes
|
||||
mem_gb f64 // Total memory in gigabytes
|
||||
mem_gb_gpu f64 // Total GPU memory in gigabytes
|
||||
passmark int // Passmark score for the node
|
||||
vcores int // Total virtual cores
|
||||
}
|
||||
|
||||
|
||||
pub struct NodeGrant {
|
||||
pub mut:
|
||||
grant_month_usd string
|
||||
grant_month_inca string
|
||||
grant_max_nrnodes int
|
||||
}
|
||||
|
||||
|
||||
fn (mut n Node) validate_percentage(v int) ! {
|
||||
if v < 0 || v > 100 {
|
||||
return error('Value must be between 0 and 100')
|
||||
}
|
||||
}
|
||||
|
||||
pub fn preprocess_value(v string) string {
|
||||
// Implement the preprocessing logic here
|
||||
return v
|
||||
}
|
||||
|
||||
pub fn (mut n Node) preprocess_location(v string) ! {
|
||||
n.info.continent = preprocess_value(v)
|
||||
n.info.country = preprocess_value(v)
|
||||
}
|
||||
|
||||
// pub fn (mut n Node) parse_deliverytime(v string) ! {
|
||||
// n.deliverytime = time.parse(v, 'YYYY-MM-DD')!
|
||||
// }
|
||||
12
lib/threefold/grid4/cloudslices/model_node_template.v
Normal file
12
lib/threefold/grid4/cloudslices/model_node_template.v
Normal file
@@ -0,0 +1,12 @@
|
||||
module cloudslices
|
||||
|
||||
import time
|
||||
|
||||
pub struct NodeTemplate {
|
||||
Node
|
||||
pub mut:
|
||||
name string
|
||||
description string // Description of the node
|
||||
image_url string // Image url associated with the node
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user