From f7854d0a8417106d2dbb9cdfed684c9aa4010604 Mon Sep 17 00:00:00 2001 From: Cole Robinson Date: Sun, 16 Jun 2019 16:47:22 -0400 Subject: [PATCH] virt-xml: Use VIR_DOMAIN_XML_SECURE Otherwise we will lose data when editing VMs --- virt-xml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/virt-xml b/virt-xml index 4bcd145c6..5ed470f45 100755 --- a/virt-xml +++ b/virt-xml @@ -59,6 +59,13 @@ def set_os_variant(options, guest): guest.set_os_name(osdata.name) +def get_xmldesc(domain, inactive=False): + flags = libvirt.VIR_DOMAIN_XML_SECURE + if inactive: + flags |= libvirt.VIR_DOMAIN_XML_INACTIVE + return domain.XMLDesc(flags) + + def get_domain_and_guest(conn, domstr): try: int(domstr) @@ -87,11 +94,11 @@ def get_domain_and_guest(conn, domstr): state = domain.info()[0] active_xmlobj = None - inactive_xmlobj = virtinst.Guest(conn, parsexml=domain.XMLDesc(0)) + inactive_xmlobj = virtinst.Guest(conn, parsexml=get_xmldesc(domain)) if state != libvirt.VIR_DOMAIN_SHUTOFF: active_xmlobj = inactive_xmlobj inactive_xmlobj = virtinst.Guest(conn, - parsexml=domain.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE)) + parsexml=get_xmldesc(domain, inactive=True)) return (domain, inactive_xmlobj, active_xmlobj)