From 84229eb3610b3819890d0bcb806d8c0bd362bd14 Mon Sep 17 00:00:00 2001 From: Erik Skultety Date: Thu, 18 May 2023 15:31:06 +0200 Subject: libvirt_wrapper: Add a helper to create volumes from XML Future patches will make it so that we create the resulting disk storage volume ourselves using customized UNIX permissions/ownership/mode which means we'll have to create the volume with libvirt using an XML. Signed-off-by: Erik Skultety --- lcitool/libvirt_wrapper.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lcitool/libvirt_wrapper.py b/lcitool/libvirt_wrapper.py index 7db954e..87154c6 100644 --- a/lcitool/libvirt_wrapper.py +++ b/lcitool/libvirt_wrapper.py @@ -176,6 +176,11 @@ class LibvirtStoragePoolObject(LibvirtAbstractObject): conn.storagePoolCreateXML(pool_xml) return conn.storagePoolLookupByName(name) + def _create_from_xml(self, name, xmlstr): + self.raw.createXML(xmlstr) + return LibvirtStorageVolObject(self, + self.raw.storageVolLookupByName(name)) + def create_volume(self, name, capacity, allocation=None, _format="qcow2", units='bytes', owner=None, group=None, mode=None,): @@ -217,7 +222,7 @@ class LibvirtStoragePoolObject(LibvirtAbstractObject): node_el.text = perm_var volume_xml = ET.tostring(root_el, encoding="UTF-8", method="xml") - self.raw.createXML(volume_xml.decode("UTF-8")) + return self._create_from_xml(name, volume_xml.decode("UTF-8")) class LibvirtStorageVolObject(LibvirtAbstractObject): -- cgit v1.1