Add backend SMBios support
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pierre HUBERT 2025-05-22 21:13:00 +02:00
parent 94ee8f8c78
commit 644fd6f1bb
2 changed files with 58 additions and 0 deletions

View File

@ -26,6 +26,7 @@ pub struct OSXML {
pub firmware: String, pub firmware: String,
pub r#type: OSTypeXML, pub r#type: OSTypeXML,
pub loader: Option<OSLoaderXML>, pub loader: Option<OSLoaderXML>,
pub smbios: Option<OSSMBiosXML>,
} }
/// OS Type information /// OS Type information
@ -48,6 +49,14 @@ pub struct OSLoaderXML {
pub secure: String, 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 /// Hypervisor features
#[derive(serde::Serialize, serde::Deserialize, Clone, Default, Debug)] #[derive(serde::Serialize, serde::Deserialize, Clone, Default, Debug)]
#[serde(rename = "features")] #[serde(rename = "features")]
@ -305,6 +314,29 @@ pub struct DomainCPUXML {
pub topology: Option<DomainCPUTopology>, pub topology: Option<DomainCPUTopology>,
} }
#[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<OEMStringEntryXML>,
}
#[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<OEMStringsXML>,
}
/// Domain information, see https://libvirt.org/formatdomain.html /// Domain information, see https://libvirt.org/formatdomain.html
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename = "domain")] #[serde(rename = "domain")]
@ -335,6 +367,10 @@ pub struct DomainXML {
/// CPU information /// CPU information
pub cpu: DomainCPUXML, pub cpu: DomainCPUXML,
/// SMBios strings
pub sysinfo: Option<SysInfoXML>,
/// Behavior when guest state change
pub on_poweroff: String, pub on_poweroff: String,
pub on_reboot: String, pub on_reboot: String,
pub on_crash: String, pub on_crash: String,

View File

@ -83,6 +83,8 @@ pub struct VMInfo {
pub networks: Vec<Network>, pub networks: Vec<Network>,
/// Add a TPM v2.0 module /// Add a TPM v2.0 module
pub tpm_module: bool, pub tpm_module: bool,
/// Strings injected as OEM Strings in SMBios configuration
pub oem_strings: Vec<String>,
} }
impl VMInfo { impl VMInfo {
@ -329,6 +331,9 @@ impl VMInfo {
BootType::UEFISecureBoot => "yes".to_string(), BootType::UEFISecureBoot => "yes".to_string(),
}, },
}), }),
smbios: Some(OSSMBiosXML {
mode: "sysinfo".to_string(),
}),
}, },
features: FeaturesXML { acpi: ACPIXML {} }, 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_poweroff: "destroy".to_string(),
on_reboot: "restart".to_string(), on_reboot: "restart".to_string(),
on_crash: "destroy".to_string(), on_crash: "destroy".to_string(),
@ -476,6 +492,12 @@ impl VMInfo {
.collect::<Result<Vec<_>, _>>()?, .collect::<Result<Vec<_>, _>>()?,
tpm_module: domain.devices.tpm.is_some(), 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(),
}) })
} }
} }