aboutsummaryrefslogtreecommitdiff
path: root/src/waifu.rs
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2022-04-19 12:46:15 -0400
committerCara Salter <cara@devcara.com>2022-04-19 12:46:15 -0400
commit53256aacaa8a8ec5728334afc20ba2945f829b69 (patch)
treea69ffbcd88124e6578fe8192458f7e37290a04a3 /src/waifu.rs
parent71d31463e019b5c5d6bea382eb490d53e7c0cea7 (diff)
downloadsolarlib-53256aacaa8a8ec5728334afc20ba2945f829b69.tar.gz
solarlib-53256aacaa8a8ec5728334afc20ba2945f829b69.zip
Unitype and tests
Diffstat (limited to 'src/waifu.rs')
-rw-r--r--src/waifu.rs49
1 files changed, 41 insertions, 8 deletions
diff --git a/src/waifu.rs b/src/waifu.rs
index a7dfba8..50bad19 100644
--- a/src/waifu.rs
+++ b/src/waifu.rs
@@ -4,7 +4,28 @@ use serde::{Serialize, Deserialize};
use crate::errors::Error;
-type Fqdn = String;
+/**
+ * Defines the amount of memory a waifu has
+ */
+#[derive(Debug, Serialize, Deserialize)]
+pub struct Memory(u64);
+
+impl From<u64> for Memory {
+ fn from(u: u64) -> Self {
+ Self(u)
+ }
+}
+/**
+ * Defines the number of vCPUs a waifu has
+ */
+#[derive(Debug, Serialize, Deserialize)]
+pub struct CpuCount(u64);
+
+impl From<u64> for CpuCount {
+ fn from(u: u64) -> Self {
+ Self(u)
+ }
+}
/**
* Represents a virtual machine, that's active on some server
@@ -17,27 +38,38 @@ pub struct Waifu {
pub name: String,
/// The physical machine where this one lives
- pub host: Fqdn,
+ pub host: String,
+
+ /// The UUID
+ pub uuid: String,
/// The network address where this machine can be reached
pub addr: Option<String>,
/// The amount of RAM (in MB) assigned to this machine
- pub mem: u64,
+ pub mem: Memory,
/// The amount of vCPUs assigned to this machine
- pub cpu_count: u64,
+ pub cpu_count: CpuCount,
}
-impl TryFrom<Domain> for Waifu {
+impl PartialEq for Waifu {
+ fn eq(&self, other: &Self) -> bool {
+ self.uuid == other.uuid
+ }
+}
+
+impl TryFrom<&Domain> for Waifu {
type Error = Error;
- fn try_from(d: Domain) -> Result<Self, Self::Error> {
+ fn try_from(d: &Domain) -> Result<Self, Self::Error> {
let c = d.get_connect()?;
// This... feels wrong
//
// I know it probably works
+ //
+ // Based on code by Cadey in waifud
let addr: Option<String> = if d.is_active()? {
let mut addr: Vec<String> = d
.interface_addresses(virt::domain::VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE, 0)?
@@ -60,8 +92,9 @@ impl TryFrom<Domain> for Waifu {
name: d.get_name()?,
host: c.get_hostname()?,
addr,
- mem: d.get_max_memory()?,
- cpu_count: d.get_max_vcpus()?,
+ uuid: d.get_uuid_string()?,
+ mem: d.get_max_memory()?.into(),
+ cpu_count: d.get_max_vcpus()?.into(),
})
}
}