181 lines
3.8 KiB
Rust
181 lines
3.8 KiB
Rust
use std::sync::Arc;
|
|
|
|
use derive_new::new;
|
|
use harmony_types::net::MacAddress;
|
|
|
|
pub type HostGroup = Vec<PhysicalHost>;
|
|
pub type SwitchGroup = Vec<Switch>;
|
|
pub type FirewallGroup = Vec<PhysicalHost>;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct PhysicalHost {
|
|
pub category: HostCategory,
|
|
pub network: Vec<NetworkInterface>,
|
|
pub management: Arc<dyn ManagementInterface>,
|
|
pub storage: Vec<Storage>,
|
|
pub labels: Vec<Label>,
|
|
pub memory_size: Option<u64>,
|
|
pub cpu_count: Option<u64>,
|
|
}
|
|
|
|
impl PhysicalHost {
|
|
pub fn empty(category: HostCategory) -> Self {
|
|
Self {
|
|
category,
|
|
network: vec![],
|
|
storage: vec![],
|
|
labels: vec![],
|
|
management: Arc::new(ManualManagementInterface {}),
|
|
memory_size: None,
|
|
cpu_count: None,
|
|
}
|
|
}
|
|
|
|
pub fn cluster_mac(&self) -> MacAddress {
|
|
self.network
|
|
.get(0)
|
|
.expect("Cluster physical host should have a network interface")
|
|
.mac_address
|
|
.clone()
|
|
}
|
|
|
|
pub fn cpu(mut self, cpu_count: Option<u64>) -> Self {
|
|
self.cpu_count = cpu_count;
|
|
self
|
|
}
|
|
|
|
pub fn memory_size(mut self, memory_size: Option<u64>) -> Self {
|
|
self.memory_size = memory_size;
|
|
self
|
|
}
|
|
|
|
pub fn storage(
|
|
mut self,
|
|
connection: StorageConnectionType,
|
|
kind: StorageKind,
|
|
size: u64,
|
|
serial: String,
|
|
) -> Self {
|
|
self.storage.push(Storage {
|
|
connection,
|
|
kind,
|
|
size,
|
|
serial,
|
|
});
|
|
self
|
|
}
|
|
|
|
pub fn mac_address(mut self, mac_address: MacAddress) -> Self {
|
|
self.network.push(NetworkInterface {
|
|
name: None,
|
|
mac_address,
|
|
speed: None,
|
|
});
|
|
self
|
|
}
|
|
|
|
pub fn label(mut self, name: String, value: String) -> Self {
|
|
self.labels.push(Label {
|
|
_name: name,
|
|
_value: value,
|
|
});
|
|
self
|
|
}
|
|
|
|
pub fn management(mut self, management: Arc<dyn ManagementInterface>) -> Self {
|
|
self.management = management;
|
|
self
|
|
}
|
|
}
|
|
|
|
#[derive(new)]
|
|
pub struct ManualManagementInterface;
|
|
|
|
impl ManagementInterface for ManualManagementInterface {
|
|
fn boot_to_pxe(&self) {
|
|
todo!()
|
|
}
|
|
|
|
fn get_supported_protocol_names(&self) -> String {
|
|
todo!()
|
|
}
|
|
}
|
|
|
|
pub trait ManagementInterface: Send + Sync {
|
|
fn boot_to_pxe(&self);
|
|
fn get_supported_protocol_names(&self) -> String;
|
|
}
|
|
|
|
impl std::fmt::Debug for dyn ManagementInterface {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
f.write_fmt(format_args!(
|
|
"ManagementInterface protocols : {}",
|
|
self.get_supported_protocol_names(),
|
|
))
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub enum HostCategory {
|
|
Server,
|
|
Firewall,
|
|
Switch,
|
|
}
|
|
|
|
#[derive(Debug, new, Clone)]
|
|
pub struct NetworkInterface {
|
|
pub name: Option<String>,
|
|
pub mac_address: MacAddress,
|
|
pub speed: Option<u64>,
|
|
}
|
|
|
|
#[derive(Debug, new, Clone)]
|
|
pub enum StorageConnectionType {
|
|
Sata3g,
|
|
Sata6g,
|
|
Sas6g,
|
|
Sas12g,
|
|
PCIE,
|
|
}
|
|
#[derive(Debug, Clone)]
|
|
pub enum StorageKind {
|
|
SSD,
|
|
NVME,
|
|
HDD,
|
|
}
|
|
#[derive(Debug, new, Clone)]
|
|
pub struct Storage {
|
|
pub connection: StorageConnectionType,
|
|
pub kind: StorageKind,
|
|
pub size: u64,
|
|
pub serial: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Switch {
|
|
_interface: Vec<NetworkInterface>,
|
|
_management_interface: NetworkInterface,
|
|
}
|
|
|
|
#[derive(Debug, new, Clone)]
|
|
pub struct Label {
|
|
_name: String,
|
|
_value: String,
|
|
}
|
|
pub type Address = String;
|
|
|
|
#[derive(new, Debug)]
|
|
pub struct Location {
|
|
pub address: Address,
|
|
pub name: String,
|
|
}
|
|
|
|
impl Location {
|
|
pub fn test_building() -> Location {
|
|
Self {
|
|
address: String::new(),
|
|
name: String::new(),
|
|
}
|
|
}
|
|
}
|