#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Debug)] pub struct DomainXMLUuid(pub uuid::Uuid); impl DomainXMLUuid { pub fn parse_from_str(s: &str) -> anyhow::Result { Ok(Self(uuid::Uuid::parse_str(s)?)) } pub fn as_string(&self) -> String { self.0.to_string() } pub fn is_valid(&self) -> bool { self.0.get_version_num() == 4 } } /// OS information #[derive(serde::Serialize, serde::Deserialize)] #[serde(rename = "os")] pub struct OSXML { #[serde(rename(serialize = "@firmware"), default)] pub firmware: String, pub r#type: OSTypeXML, pub loader: Option, } /// OS Type information #[derive(serde::Serialize, serde::Deserialize)] #[serde(rename = "os")] pub struct OSTypeXML { #[serde(rename(serialize = "@arch"))] pub arch: String, #[serde(rename = "$value")] pub body: String, } /// OS Loader information #[derive(serde::Serialize, serde::Deserialize)] #[serde(rename = "loader")] pub struct OSLoaderXML { #[serde(rename(serialize = "@secure"))] pub secure: String, } /// Hypervisor features #[derive(serde::Serialize, serde::Deserialize, Default)] #[serde(rename = "features")] pub struct FeaturesXML { pub acpi: ACPIXML, } /// ACPI feature #[derive(serde::Serialize, serde::Deserialize, Default)] #[serde(rename = "acpi")] pub struct ACPIXML {} /// Devices information #[derive(serde::Serialize, serde::Deserialize)] #[serde(rename = "devices")] pub struct DevicesXML { #[serde(skip_serializing_if = "Option::is_none")] pub graphics: Option, } /// Screen information #[derive(serde::Serialize, serde::Deserialize)] #[serde(rename = "graphics")] pub struct GraphicsXML { #[serde(rename(serialize = "@type"))] pub r#type: String, #[serde(rename(serialize = "@socket"))] pub socket: String, } /// Domain RAM information #[derive(serde::Serialize, serde::Deserialize)] #[serde(rename = "memory")] pub struct DomainMemoryXML { #[serde(rename(serialize = "@unit"))] pub unit: String, #[serde(rename = "$value")] pub memory: usize, } /// Domain information, see https://libvirt.org/formatdomain.html #[derive(serde::Serialize, serde::Deserialize)] #[serde(rename = "domain")] pub struct DomainXML { /// Domain type (kvm) #[serde(rename(serialize = "@type"))] pub r#type: String, pub name: String, pub uuid: Option, pub genid: Option, pub title: Option, pub description: Option, pub os: OSXML, #[serde(default)] pub features: FeaturesXML, pub devices: DevicesXML, /// The maximum allocation of memory for the guest at boot time pub memory: DomainMemoryXML, pub on_poweroff: String, pub on_reboot: String, pub on_crash: String, } /// Domain state #[derive(serde::Serialize, Debug, Copy, Clone)] pub enum DomainState { NoState, Running, Blocked, Paused, Shutdown, Shutoff, Crashed, PowerManagementSuspended, Other, }