Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
---
data/org.libvirt.StoragePool.xml | 6 ++++++
src/storagepool.c | 44 ++++++++++++++++++++++++++++++++++++++++
tests/test_storage.py | 8 ++++++++
3 files changed, 58 insertions(+)
diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml
index e9d6b0e..764c9c1 100644
--- a/data/org.libvirt.StoragePool.xml
+++ b/data/org.libvirt.StoragePool.xml
@@ -57,6 +57,12 @@
<arg name="flags" type="u" direction="in"/>
<arg name="xml" type="s" direction="out"/>
</method>
+ <method name="ListStorageVolumes">
+ <annotation name="org.gtk.GDBus.DocString"
+ value="See
https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolListA...
+ <arg name="flags" type="u" direction="in"/>
+ <arg name="storageVols" type="ao"
direction="out"/>
+ </method>
<method name="Refresh">
<annotation name="org.gtk.GDBus.DocString"
value="See
https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolRefre...
diff --git a/src/storagepool.c b/src/storagepool.c
index 0da732f..11e356c 100644
--- a/src/storagepool.c
+++ b/src/storagepool.c
@@ -301,6 +301,49 @@ virtDBusStoragePoolGetXMLDesc(GVariant *inArgs,
*outArgs = g_variant_new("(s)", xml);
}
+static void
+virtDBusStoragePoolListAllVolumes(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(virStorageVolPtr) storageVols = NULL;
+ g_autofree gchar *xml = NULL;
+ guint flags;
+ gint nVols;
+ GVariantBuilder builder;
+ GVariant *gstorageVols;
+
+ g_variant_get(inArgs, "(u)", &flags);
+
+ storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath,
+ error);
+ if (!storagePool)
+ return;
+
+ nVols = virStoragePoolListAllVolumes(storagePool, &storageVols, flags);
+ if (nVols < 0)
+ return virtDBusUtilSetLastVirtError(error);
+
+ g_variant_builder_init(&builder, G_VARIANT_TYPE("ao"));
+
+ for (gint i = 0; i< nVols; i++) {
+ g_autofree gchar *path = NULL;
+ path = virtDBusUtilBusPathForVirStorageVol(storageVols[i],
+ connect->storageVolPath);
+
+ g_variant_builder_add(&builder, "o", path);
+ }
+
+ gstorageVols = g_variant_builder_end(&builder);
+ *outArgs = g_variant_new_tuple(&gstorageVols, 1);
+}
+
static void
virtDBusStoragePoolRefresh(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -363,6 +406,7 @@ static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = {
{ "Destroy", virtDBusStoragePoolDestroy },
{ "GetInfo", virtDBusStoragePoolGetInfo },
{ "GetXMLDesc", virtDBusStoragePoolGetXMLDesc },
+ { "ListStorageVolumes", virtDBusStoragePoolListAllVolumes },
{ "Refresh", virtDBusStoragePoolRefresh },
{ "Undefine", virtDBusStoragePoolUndefine },
{ 0 }
diff --git a/tests/test_storage.py b/tests/test_storage.py
index b9e7090..79e0c16 100755
--- a/tests/test_storage.py
+++ b/tests/test_storage.py
@@ -79,6 +79,14 @@ class TestStoragePool(libvirttest.BaseTestClass):
info = interface_obj.GetXMLDesc(0)
assert isinstance(info, dbus.String)
+ def test_storage_pool_list_storage_volumes(self):
+ _, test_storage_pool = self.test_storage_pool()
+ interface_obj = dbus.Interface(test_storage_pool,
+ 'org.libvirt.StoragePool')
+ storage_vols = interface_obj.ListStorageVolumes(0)
+ assert isinstance(storage_vols, dbus.Array)
+ assert len(storage_vols) == 0
+
def test_storage_pool_properties_type(self):
_, obj = self.test_storage_pool()
--
2.15.0