Mercurial > hg > Members > anatofuz > ie-virsh
changeset 44:9d5cb6b2046e
fix emit xml
author | AnaTofuZ <anatofuz@gmail.com> |
---|---|
date | Sun, 22 Nov 2020 18:05:42 +0900 |
parents | 98138c3f00f0 |
children | 91aea67d88fb |
files | src/xml.rs |
diffstat | 1 files changed, 32 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/src/xml.rs Sun Nov 22 17:50:18 2020 +0900 +++ b/src/xml.rs Sun Nov 22 18:05:42 2020 +0900 @@ -108,6 +108,7 @@ pub fn backing(&mut self, backing_file: &str) -> &mut Builder { self.backing_file = backing_file.to_string(); + self.is_backing = true; self } @@ -198,37 +199,6 @@ writer.write_event(Event::Empty(elem)).ok(); } - // use template qcow2 - Ok(Event::End(ref e)) if ((e.name() == b"disk") && self.is_backing) => { - let mut backing_store_start = BytesStart::borrowed_name(b"backingStore"); - backing_store_start.push_attribute(("type", "file")); - backing_store_start.push_attribute(("index", "3")); - writer - .write_event(Event::Empty(backing_store_start)) - .unwrap(); - - writer.write(b"\n").unwrap(); - - let mut format_elem = BytesStart::borrowed_name(b"format"); - format_elem.push_attribute(("type", "qcow2")); - writer.write_event(Event::Empty(format_elem)).unwrap(); - writer.write(b"\n").unwrap(); - - let mut backing_sorce = BytesStart::borrowed_name(b"sorce"); - let backing_file: &str = &self.backing_file; - backing_sorce.push_attribute(("file", backing_file)); - writer.write_event(Event::Empty(backing_sorce)).unwrap(); - writer.write(b"\n").unwrap(); - - let backing_store_end = BytesEnd::borrowed(b"backingStore"); - writer.write_event(Event::End(backing_store_end)).unwrap(); - writer.write(b"\n").unwrap(); - - let disk_end = BytesEnd::borrowed(b"disk"); - writer.write_event(Event::End(disk_end)).unwrap(); - writer.write(b"\n").unwrap(); - } - // replace qcow2 file Ok(Event::Empty(ref e)) if (e.name() == b"source") => { let mut elem = e.clone(); @@ -241,6 +211,37 @@ elem.push_attribute(("file", qcow2_path)); } writer.write_event(Event::Empty(elem)).ok(); + + // use template qcow2 + if self.is_backing { + let mut backing_store_start = BytesStart::borrowed_name(b"backingStore"); + backing_store_start.push_attribute(("type", "file")); + backing_store_start.push_attribute(("index", "3")); + writer + .write_event(Event::Empty(backing_store_start)) + .unwrap(); + + writer.write(b"\n").unwrap(); + + let mut format_elem = BytesStart::borrowed_name(b"format"); + format_elem.push_attribute(("type", "qcow2")); + writer.write_event(Event::Empty(format_elem)).unwrap(); + writer.write(b"\n").unwrap(); + + let mut backing_sorce = BytesStart::borrowed_name(b"sorce"); + let backing_file: &str = &self.backing_file; + backing_sorce.push_attribute(("file", backing_file)); + writer.write_event(Event::Empty(backing_sorce)).unwrap(); + writer.write(b"\n").unwrap(); + + let backing_store_end = BytesEnd::borrowed(b"backingStore"); + writer.write_event(Event::End(backing_store_end)).unwrap(); + writer.write(b"\n").unwrap(); + + let disk_end = BytesEnd::borrowed(b"disk"); + writer.write_event(Event::End(disk_end)).unwrap(); + writer.write(b"\n").unwrap(); + } } Ok(Event::Text(ref e)) if e.escaped() == IE_VIRSH_TEMPLATE_VM_NAME.as_bytes() => {