aboutsummaryrefslogtreecommitdiff
path: root/src/waifu.rs
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2022-04-20 13:08:28 -0400
committerCara Salter <cara@devcara.com>2022-04-20 13:08:28 -0400
commit6b995785c780dd47cb0e02821001f446cf4ec211 (patch)
tree2bbe9147151056527468c1dcf70b6b98140ccb40 /src/waifu.rs
parent5978befd317189f1f18dddbab3db7ddd0061c236 (diff)
downloadsolarlib-6b995785c780dd47cb0e02821001f446cf4ec211.tar.gz
solarlib-6b995785c780dd47cb0e02821001f446cf4ec211.zip
house: Allow for the introduction of new VMs
Templates the XML and creates the disk images
Diffstat (limited to 'src/waifu.rs')
-rw-r--r--src/waifu.rs52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/waifu.rs b/src/waifu.rs
index 55ff4ed..da9653f 100644
--- a/src/waifu.rs
+++ b/src/waifu.rs
@@ -15,6 +15,12 @@ impl From<u64> for Memory {
Self(u)
}
}
+
+impl Memory {
+ pub fn count(&self) -> u64 {
+ self.0
+ }
+}
/**
* Defines the number of vCPUs a waifu has
*/
@@ -27,6 +33,11 @@ impl From<u64> for CpuCount {
}
}
+impl CpuCount {
+ pub fn count(&self) -> u64 {
+ self.0
+ }
+}
/**
* Represents a virtual machine, that's active on some server
*
@@ -59,6 +70,47 @@ impl PartialEq for Waifu {
}
}
+impl TryFrom<Domain> for Waifu {
+ type Error = 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)?
+ .into_iter()
+ .map(|iface| iface.addrs.clone())
+ .filter(|addrs| addrs.get(0).is_some())
+ .map(|addrs| addrs.get(0).unwrap().clone().addr)
+ .collect();
+
+ if addr.get(0).is_none() {
+ Some(String::from("localhost"))
+ } else {
+ Some(addr.swap_remove(0))
+ }
+ } else {
+ None
+ };
+
+ Ok(Self {
+ name: d.get_name()?,
+ host: c.get_hostname()?,
+ addr,
+ uuid: d.get_uuid_string()?,
+ mem: d.get_max_memory()?.into(),
+ cpu_count: d.get_max_vcpus()?.into(),
+ })
+ }
+}
+
+
impl TryFrom<&Domain> for Waifu {
type Error = Error;