Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx> --- data/org.libvirt.StoragePool.xml | 7 +++++++ src/storagepool.c | 34 ++++++++++++++++++++++++++++++++++ tests/libvirttest.py | 17 +++++++++++++++++ tests/test_storage.py | 4 ++++ 4 files changed, 62 insertions(+) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index 764c9c1..51d65ab 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -68,6 +68,13 @@ value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolRefresh"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="StorageVolCreateXML"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolCreateXML"/> + <arg name="xml" type="s" direction="in"/> + <arg name="flags" type="u" direction="in"/> + <arg name="storageVol" type="o" direction="out"/> + </method> <method name="Undefine"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolUndefine"/> diff --git a/src/storagepool.c b/src/storagepool.c index 11e356c..c3fd0bf 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -368,6 +368,39 @@ virtDBusStoragePoolRefresh(GVariant *inArgs, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusStoragePoolStorageVolCreateXML(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePool) storagePool = NULL; + g_autoptr(virStorageVol) storageVol = NULL; + gchar *xml; + guint flags; + g_autofree gchar *path = NULL; + + g_variant_get(inArgs, "(&su)", &xml, &flags); + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + storageVol = virStorageVolCreateXML(storagePool, xml, flags); + if (!storageVol) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirStorageVol(storageVol, + connect->storageVolPath); + + *outArgs = g_variant_new("(o)", path); +} + static void virtDBusStoragePoolUndefine(GVariant *inArgs G_GNUC_UNUSED, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -408,6 +441,7 @@ static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = { { "GetXMLDesc", virtDBusStoragePoolGetXMLDesc }, { "ListStorageVolumes", virtDBusStoragePoolListAllVolumes }, { "Refresh", virtDBusStoragePoolRefresh }, + { "StorageVolCreateXML", virtDBusStoragePoolStorageVolCreateXML }, { "Undefine", virtDBusStoragePoolUndefine }, { 0 } }; diff --git a/tests/libvirttest.py b/tests/libvirttest.py index 3cd02ef..f65251a 100644 --- a/tests/libvirttest.py +++ b/tests/libvirttest.py @@ -100,6 +100,23 @@ class BaseTestClass(): obj = self.bus.get_object('org.libvirt', path) return path, obj + def test_storage_vol(self): + minimal_storage_vol_xml = ''' + <volume> + <name>sparse.img</name> + <capacity unit="G">2</capacity> + <target> + <path>/var/lib/virt/images/sparse.img</path> + </target> + </volume> + ''' + _, test_storage_pool = self.test_storage_pool() + interface_obj = dbus.Interface(test_storage_pool, + 'org.libvirt.StoragePool') + path = interface_obj.StorageVolCreateXML(minimal_storage_vol_xml, 0) + obj = self.bus.get_object('org.libvirt', path) + return path, obj + class DomainEvent(IntEnum): DEFINED = 0 diff --git a/tests/test_storage.py b/tests/test_storage.py index 79e0c16..1cd1249 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -126,6 +126,10 @@ class TestStoragePool(libvirttest.BaseTestClass): self.main_loop() + def test_storage_pool_volume_create(self): + path, _ = self.test_storage_vol() + assert isinstance(path, dbus.ObjectPath) + if __name__ == '__main__': libvirttest.run() -- 2.15.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list