Can assign a group to VMs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-11-02 17:31:05 +01:00
parent 91fe291341
commit 55b49699eb
4 changed files with 95 additions and 36 deletions

View File

@ -59,6 +59,9 @@ pub struct VMInfo {
pub genid: Option<XMLUuid>,
pub title: Option<String>,
pub description: Option<String>,
/// Group associated with the VM (VirtWeb specific field)
#[serde(skip_serializing_if = "Option::is_none")]
pub group: Option<String>,
pub boot_type: BootType,
pub architecture: VMArchitecture,
/// VM allocated memory, in megabytes
@ -79,7 +82,7 @@ pub struct VMInfo {
impl VMInfo {
/// Turn this VM into a domain
pub fn as_tomain(&self) -> anyhow::Result<DomainXML> {
pub fn as_domain(&self) -> anyhow::Result<DomainXML> {
if !regex!("^[a-zA-Z0-9]+$").is_match(&self.name) {
return Err(StructureExtraction("VM name is invalid!").into());
}
@ -105,6 +108,12 @@ impl VMInfo {
}
}
if let Some(group) = &self.group {
if !regex!("^[a-zA-Z0-9]+$").is_match(group) {
return Err(StructureExtraction("VM group name is invalid!").into());
}
}
if self.memory < constants::MIN_VM_MEMORY || self.memory > constants::MAX_VM_MEMORY {
return Err(StructureExtraction("VM memory is invalid!").into());
}
@ -282,6 +291,12 @@ impl VMInfo {
title: self.title.clone(),
description: self.description.clone(),
metadata: Some(DomainMetadataXML {
virtweb: DomainMetadataVirtWebXML {
ns: "https://virtweb.communiquons.org".to_string(),
group: self.group.clone(),
},
}),
os: OSXML {
r#type: OSTypeXML {
arch: match self.architecture {
@ -369,6 +384,7 @@ impl VMInfo {
genid: domain.genid.map(XMLUuid),
title: domain.title,
description: domain.description,
group: domain.metadata.clone().unwrap_or_default().virtweb.group,
boot_type: match domain.os.loader {
None => BootType::UEFI,
Some(l) => match l.secure.as_str() {