Define disks as vec instead of option
This commit is contained in:
parent
d93a2b857a
commit
a30f9720ca
@ -105,8 +105,20 @@ pub struct DefineDomainReq(pub DomainXML);
|
||||
impl Handler<DefineDomainReq> for LibVirtActor {
|
||||
type Result = anyhow::Result<DomainXMLUuid>;
|
||||
|
||||
fn handle(&mut self, msg: DefineDomainReq, _ctx: &mut Self::Context) -> Self::Result {
|
||||
let xml = serde_xml_rs::to_string(&msg.0)?;
|
||||
fn handle(&mut self, mut msg: DefineDomainReq, _ctx: &mut Self::Context) -> Self::Result {
|
||||
// A issue with the disks definition serialization needs them to be serialized aside
|
||||
let mut disks_xml = Vec::with_capacity(msg.0.devices.disks.len());
|
||||
for disk in msg.0.devices.disks {
|
||||
let disk_xml = serde_xml_rs::to_string(&disk)?;
|
||||
let start_offset = disk_xml.find("<disk").unwrap();
|
||||
disks_xml.push(disk_xml[start_offset..].to_string());
|
||||
}
|
||||
msg.0.devices.disks = vec![];
|
||||
|
||||
let mut xml = serde_xml_rs::to_string(&msg.0)?;
|
||||
let disks_xml = disks_xml.join("\n");
|
||||
xml = xml.replacen("<devices>", &format!("<devices>{disks_xml}"), 1);
|
||||
|
||||
log::debug!("Define domain:\n{}", xml);
|
||||
let domain = Domain::define_xml(&self.m, &xml)?;
|
||||
DomainXMLUuid::parse_from_str(&domain.get_uuid_string()?)
|
||||
|
@ -65,8 +65,8 @@ pub struct DevicesXML {
|
||||
pub graphics: Option<GraphicsXML>,
|
||||
|
||||
/// Disks (used for storage)
|
||||
#[serde(default, rename = "disk")]
|
||||
pub disks: Option<DiskXML>, // TODO : change to vec
|
||||
#[serde(default, rename = "disk", skip_serializing_if = "Vec::is_empty")]
|
||||
pub disks: Vec<DiskXML>,
|
||||
}
|
||||
|
||||
/// Screen information
|
||||
|
@ -191,7 +191,7 @@ impl VMInfo {
|
||||
|
||||
devices: DevicesXML {
|
||||
graphics: vnc_graphics,
|
||||
disks: disks.into_iter().next(),
|
||||
disks,
|
||||
},
|
||||
|
||||
memory: DomainMemoryXML {
|
||||
|
Loading…
Reference in New Issue
Block a user