From 644fd6f1bb48e2343e6883fe82152494ed00469a Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 22 May 2025 21:13:00 +0200 Subject: [PATCH] Add backend SMBios support --- .../src/libvirt_lib_structures/domain.rs | 36 +++++++++++++++++++ .../src/libvirt_rest_structures/vm.rs | 22 ++++++++++++ 2 files changed, 58 insertions(+) diff --git a/virtweb_backend/src/libvirt_lib_structures/domain.rs b/virtweb_backend/src/libvirt_lib_structures/domain.rs index 7aab273..c5ff6c2 100644 --- a/virtweb_backend/src/libvirt_lib_structures/domain.rs +++ b/virtweb_backend/src/libvirt_lib_structures/domain.rs @@ -26,6 +26,7 @@ pub struct OSXML { pub firmware: String, pub r#type: OSTypeXML, pub loader: Option, + pub smbios: Option, } /// OS Type information @@ -48,6 +49,14 @@ pub struct OSLoaderXML { pub secure: String, } +/// SMBIOS System information +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[serde(rename = "smbios")] +pub struct OSSMBiosXML { + #[serde(rename = "@mode")] + pub mode: String, +} + /// Hypervisor features #[derive(serde::Serialize, serde::Deserialize, Clone, Default, Debug)] #[serde(rename = "features")] @@ -305,6 +314,29 @@ pub struct DomainCPUXML { pub topology: Option, } +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[serde(rename = "entry")] +pub struct OEMStringEntryXML { + #[serde(rename = "$text")] + pub content: String, +} + +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[serde(rename = "oemStrings")] +pub struct OEMStringsXML { + #[serde(rename = "entry")] + pub entries: Vec, +} + +#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] +#[serde(rename = "sysinfo")] +pub struct SysInfoXML { + #[serde(rename = "@type")] + pub r#type: String, + #[serde(rename = "oemStrings")] + pub oem_strings: Option, +} + /// Domain information, see https://libvirt.org/formatdomain.html #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[serde(rename = "domain")] @@ -335,6 +367,10 @@ pub struct DomainXML { /// CPU information pub cpu: DomainCPUXML, + /// SMBios strings + pub sysinfo: Option, + + /// Behavior when guest state change pub on_poweroff: String, pub on_reboot: String, pub on_crash: String, diff --git a/virtweb_backend/src/libvirt_rest_structures/vm.rs b/virtweb_backend/src/libvirt_rest_structures/vm.rs index 76555af..fda8181 100644 --- a/virtweb_backend/src/libvirt_rest_structures/vm.rs +++ b/virtweb_backend/src/libvirt_rest_structures/vm.rs @@ -83,6 +83,8 @@ pub struct VMInfo { pub networks: Vec, /// Add a TPM v2.0 module pub tpm_module: bool, + /// Strings injected as OEM Strings in SMBios configuration + pub oem_strings: Vec, } impl VMInfo { @@ -329,6 +331,9 @@ impl VMInfo { BootType::UEFISecureBoot => "yes".to_string(), }, }), + smbios: Some(OSSMBiosXML { + mode: "sysinfo".to_string(), + }), }, features: FeaturesXML { acpi: ACPIXML {} }, @@ -385,6 +390,17 @@ impl VMInfo { }), }, + sysinfo: Some(SysInfoXML { + r#type: "smbios".to_string(), + oem_strings: Some(OEMStringsXML { + entries: self + .oem_strings + .iter() + .map(|s| OEMStringEntryXML { content: s.clone() }) + .collect(), + }), + }), + on_poweroff: "destroy".to_string(), on_reboot: "restart".to_string(), on_crash: "destroy".to_string(), @@ -476,6 +492,12 @@ impl VMInfo { .collect::, _>>()?, tpm_module: domain.devices.tpm.is_some(), + + oem_strings: domain + .sysinfo + .and_then(|s| s.oem_strings) + .map(|s| s.entries.iter().map(|o| o.content.to_string()).collect()) + .unwrap_or_default(), }) } }