diff options
author | Cara Salter <cara@devcara.com> | 2022-04-20 13:08:28 -0400 |
---|---|---|
committer | Cara Salter <cara@devcara.com> | 2022-04-20 13:08:28 -0400 |
commit | 6b995785c780dd47cb0e02821001f446cf4ec211 (patch) | |
tree | 2bbe9147151056527468c1dcf70b6b98140ccb40 /src/waifu.rs | |
parent | 5978befd317189f1f18dddbab3db7ddd0061c236 (diff) | |
download | solarlib-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.rs | 52 |
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; |