Can get the list of groups
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-11-02 17:44:10 +01:00
parent 55b49699eb
commit c908d00c62
5 changed files with 47 additions and 6 deletions

View File

@ -10,6 +10,9 @@ use crate::utils::files_utils::convert_size_unit_to_mb;
use lazy_regex::regex;
use num::Integer;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Eq, Hash)]
pub struct VMGroupId(pub String);
#[derive(serde::Serialize, serde::Deserialize)]
pub enum BootType {
UEFI,
@ -61,7 +64,7 @@ pub struct VMInfo {
pub description: Option<String>,
/// Group associated with the VM (VirtWeb specific field)
#[serde(skip_serializing_if = "Option::is_none")]
pub group: Option<String>,
pub group: Option<VMGroupId>,
pub boot_type: BootType,
pub architecture: VMArchitecture,
/// VM allocated memory, in megabytes
@ -109,7 +112,7 @@ impl VMInfo {
}
if let Some(group) = &self.group {
if !regex!("^[a-zA-Z0-9]+$").is_match(group) {
if !regex!("^[a-zA-Z0-9]+$").is_match(&group.0) {
return Err(StructureExtraction("VM group name is invalid!").into());
}
}
@ -294,7 +297,7 @@ impl VMInfo {
metadata: Some(DomainMetadataXML {
virtweb: DomainMetadataVirtWebXML {
ns: "https://virtweb.communiquons.org".to_string(),
group: self.group.clone(),
group: self.group.clone().map(|g| g.0),
},
}),
os: OSXML {
@ -384,7 +387,13 @@ impl VMInfo {
genid: domain.genid.map(XMLUuid),
title: domain.title,
description: domain.description,
group: domain.metadata.clone().unwrap_or_default().virtweb.group,
group: domain
.metadata
.clone()
.unwrap_or_default()
.virtweb
.group
.map(VMGroupId),
boot_type: match domain.os.loader {
None => BootType::UEFI,
Some(l) => match l.secure.as_str() {