move rhai wrappers of models from rhailib
This commit is contained in:
16
heromodels/src/models/grid4/mod.rs
Normal file
16
heromodels/src/models/grid4/mod.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
pub mod node;
|
||||
|
||||
pub use node::{
|
||||
Node,
|
||||
DeviceInfo,
|
||||
StorageDevice,
|
||||
MemoryDevice,
|
||||
CPUDevice,
|
||||
GPUDevice,
|
||||
NetworkDevice,
|
||||
NodeCapacity,
|
||||
ComputeSlice,
|
||||
StorageSlice,
|
||||
PricingPolicy,
|
||||
SLAPolicy,
|
||||
};
|
265
heromodels/src/models/grid4/node.rs
Normal file
265
heromodels/src/models/grid4/node.rs
Normal file
@@ -0,0 +1,265 @@
|
||||
use heromodels_core::BaseModelData;
|
||||
use heromodels_derive::model;
|
||||
use rhai::CustomType;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Storage device information
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, CustomType)]
|
||||
pub struct StorageDevice {
|
||||
/// can be used in node
|
||||
pub id: String,
|
||||
/// Size of the storage device in gigabytes
|
||||
pub size_gb: f64,
|
||||
/// Description of the storage device
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
/// Memory device information
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, CustomType)]
|
||||
pub struct MemoryDevice {
|
||||
/// can be used in node
|
||||
pub id: String,
|
||||
/// Size of the memory device in gigabytes
|
||||
pub size_gb: f64,
|
||||
/// Description of the memory device
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
/// CPU device information
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, CustomType)]
|
||||
pub struct CPUDevice {
|
||||
/// can be used in node
|
||||
pub id: String,
|
||||
/// Number of CPU cores
|
||||
pub cores: i32,
|
||||
/// Passmark score
|
||||
pub passmark: i32,
|
||||
/// Description of the CPU
|
||||
pub description: String,
|
||||
/// Brand of the CPU
|
||||
pub cpu_brand: String,
|
||||
/// Version of the CPU
|
||||
pub cpu_version: String,
|
||||
}
|
||||
|
||||
/// GPU device information
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, CustomType)]
|
||||
pub struct GPUDevice {
|
||||
/// can be used in node
|
||||
pub id: String,
|
||||
/// Number of GPU cores
|
||||
pub cores: i32,
|
||||
/// Size of the GPU memory in gigabytes
|
||||
pub memory_gb: f64,
|
||||
/// Description of the GPU
|
||||
pub description: String,
|
||||
pub gpu_brand: String,
|
||||
pub gpu_version: String,
|
||||
}
|
||||
|
||||
/// Network device information
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, CustomType)]
|
||||
pub struct NetworkDevice {
|
||||
/// can be used in node
|
||||
pub id: String,
|
||||
/// Network speed in Mbps
|
||||
pub speed_mbps: i32,
|
||||
/// Description of the network device
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
/// Aggregated device info for a node
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, CustomType)]
|
||||
pub struct DeviceInfo {
|
||||
pub vendor: String,
|
||||
pub storage: Vec<StorageDevice>,
|
||||
pub memory: Vec<MemoryDevice>,
|
||||
pub cpu: Vec<CPUDevice>,
|
||||
pub gpu: Vec<GPUDevice>,
|
||||
pub network: Vec<NetworkDevice>,
|
||||
}
|
||||
|
||||
/// NodeCapacity represents the hardware capacity details of a node.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, CustomType)]
|
||||
pub struct NodeCapacity {
|
||||
/// Total storage in gigabytes
|
||||
pub storage_gb: f64,
|
||||
/// Total memory in gigabytes
|
||||
pub mem_gb: f64,
|
||||
/// Total GPU memory in gigabytes
|
||||
pub mem_gb_gpu: f64,
|
||||
/// Passmark score for the node
|
||||
pub passmark: i32,
|
||||
/// Total virtual cores
|
||||
pub vcores: i32,
|
||||
}
|
||||
|
||||
/// Pricing policy for slices (minimal version until full spec available)
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, CustomType)]
|
||||
pub struct PricingPolicy {
|
||||
/// Human friendly policy name (e.g. "fixed", "market")
|
||||
pub name: String,
|
||||
/// Optional free-form details as JSON-encoded string
|
||||
pub details: Option<String>,
|
||||
}
|
||||
|
||||
/// SLA policy for slices (minimal version until full spec available)
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, CustomType)]
|
||||
pub struct SLAPolicy {
|
||||
/// Uptime in percentage (0..100)
|
||||
pub uptime: f32,
|
||||
/// Max response time in ms
|
||||
pub max_response_time_ms: u32,
|
||||
}
|
||||
|
||||
/// Compute slice (typically represents a base unit of compute)
|
||||
#[model]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, CustomType)]
|
||||
pub struct ComputeSlice {
|
||||
pub base_data: BaseModelData,
|
||||
/// the node in the grid, there is an object describing the node
|
||||
#[index]
|
||||
pub nodeid: u32,
|
||||
/// the id of the slice in the node
|
||||
#[index]
|
||||
pub id: i32,
|
||||
pub mem_gb: f64,
|
||||
pub storage_gb: f64,
|
||||
pub passmark: i32,
|
||||
pub vcores: i32,
|
||||
pub cpu_oversubscription: i32,
|
||||
pub storage_oversubscription: i32,
|
||||
/// Min/max allowed price range for validation
|
||||
#[serde(default)]
|
||||
pub price_range: Vec<f64>,
|
||||
/// nr of GPU's see node to know what GPU's are
|
||||
pub gpus: u8,
|
||||
/// price per slice (even if the grouped one)
|
||||
pub price_cc: f64,
|
||||
pub pricing_policy: PricingPolicy,
|
||||
pub sla_policy: SLAPolicy,
|
||||
}
|
||||
|
||||
impl ComputeSlice {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
base_data: BaseModelData::new(),
|
||||
nodeid: 0,
|
||||
id: 0,
|
||||
mem_gb: 0.0,
|
||||
storage_gb: 0.0,
|
||||
passmark: 0,
|
||||
vcores: 0,
|
||||
cpu_oversubscription: 0,
|
||||
storage_oversubscription: 0,
|
||||
price_range: vec![0.0, 0.0],
|
||||
gpus: 0,
|
||||
price_cc: 0.0,
|
||||
pricing_policy: PricingPolicy::default(),
|
||||
sla_policy: SLAPolicy::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn nodeid(mut self, nodeid: u32) -> Self { self.nodeid = nodeid; self }
|
||||
pub fn slice_id(mut self, id: i32) -> Self { self.id = id; self }
|
||||
pub fn mem_gb(mut self, v: f64) -> Self { self.mem_gb = v; self }
|
||||
pub fn storage_gb(mut self, v: f64) -> Self { self.storage_gb = v; self }
|
||||
pub fn passmark(mut self, v: i32) -> Self { self.passmark = v; self }
|
||||
pub fn vcores(mut self, v: i32) -> Self { self.vcores = v; self }
|
||||
pub fn cpu_oversubscription(mut self, v: i32) -> Self { self.cpu_oversubscription = v; self }
|
||||
pub fn storage_oversubscription(mut self, v: i32) -> Self { self.storage_oversubscription = v; self }
|
||||
pub fn price_range(mut self, min_max: Vec<f64>) -> Self { self.price_range = min_max; self }
|
||||
pub fn gpus(mut self, v: u8) -> Self { self.gpus = v; self }
|
||||
pub fn price_cc(mut self, v: f64) -> Self { self.price_cc = v; self }
|
||||
pub fn pricing_policy(mut self, p: PricingPolicy) -> Self { self.pricing_policy = p; self }
|
||||
pub fn sla_policy(mut self, p: SLAPolicy) -> Self { self.sla_policy = p; self }
|
||||
}
|
||||
|
||||
/// Storage slice (typically 1GB of storage)
|
||||
#[model]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, CustomType)]
|
||||
pub struct StorageSlice {
|
||||
pub base_data: BaseModelData,
|
||||
/// the node in the grid
|
||||
#[index]
|
||||
pub nodeid: u32,
|
||||
/// the id of the slice in the node, are tracked in the node itself
|
||||
#[index]
|
||||
pub id: i32,
|
||||
/// price per slice (even if the grouped one)
|
||||
pub price_cc: f64,
|
||||
pub pricing_policy: PricingPolicy,
|
||||
pub sla_policy: SLAPolicy,
|
||||
}
|
||||
|
||||
impl StorageSlice {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
base_data: BaseModelData::new(),
|
||||
nodeid: 0,
|
||||
id: 0,
|
||||
price_cc: 0.0,
|
||||
pricing_policy: PricingPolicy::default(),
|
||||
sla_policy: SLAPolicy::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn nodeid(mut self, nodeid: u32) -> Self { self.nodeid = nodeid; self }
|
||||
pub fn slice_id(mut self, id: i32) -> Self { self.id = id; self }
|
||||
pub fn price_cc(mut self, v: f64) -> Self { self.price_cc = v; self }
|
||||
pub fn pricing_policy(mut self, p: PricingPolicy) -> Self { self.pricing_policy = p; self }
|
||||
pub fn sla_policy(mut self, p: SLAPolicy) -> Self { self.sla_policy = p; self }
|
||||
}
|
||||
|
||||
/// Grid4 Node model
|
||||
#[model]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default, CustomType)]
|
||||
pub struct Node {
|
||||
pub base_data: BaseModelData,
|
||||
/// Link to node group
|
||||
#[index]
|
||||
pub nodegroupid: i32,
|
||||
/// Uptime percentage 0..100
|
||||
pub uptime: i32,
|
||||
pub computeslices: Vec<ComputeSlice>,
|
||||
pub storageslices: Vec<StorageSlice>,
|
||||
pub devices: DeviceInfo,
|
||||
/// 2 letter code
|
||||
#[index]
|
||||
pub country: String,
|
||||
/// Hardware capacity details
|
||||
pub capacity: NodeCapacity,
|
||||
/// lets keep it simple and compatible
|
||||
pub provisiontime: u32,
|
||||
}
|
||||
|
||||
impl Node {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
base_data: BaseModelData::new(),
|
||||
nodegroupid: 0,
|
||||
uptime: 0,
|
||||
computeslices: Vec::new(),
|
||||
storageslices: Vec::new(),
|
||||
devices: DeviceInfo::default(),
|
||||
country: String::new(),
|
||||
capacity: NodeCapacity::default(),
|
||||
provisiontime: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn nodegroupid(mut self, v: i32) -> Self { self.nodegroupid = v; self }
|
||||
pub fn uptime(mut self, v: i32) -> Self { self.uptime = v; self }
|
||||
pub fn add_compute_slice(mut self, s: ComputeSlice) -> Self { self.computeslices.push(s); self }
|
||||
pub fn add_storage_slice(mut self, s: StorageSlice) -> Self { self.storageslices.push(s); self }
|
||||
pub fn devices(mut self, d: DeviceInfo) -> Self { self.devices = d; self }
|
||||
pub fn country(mut self, c: impl ToString) -> Self { self.country = c.to_string(); self }
|
||||
pub fn capacity(mut self, c: NodeCapacity) -> Self { self.capacity = c; self }
|
||||
pub fn provisiontime(mut self, t: u32) -> Self { self.provisiontime = t; self }
|
||||
|
||||
/// Placeholder for capacity recalculation out of the devices on the Node
|
||||
pub fn recalc_capacity(mut self) -> Self {
|
||||
// TODO: calculate NodeCapacity out of the devices on the Node
|
||||
self
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user