Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 40 ++++++++++++++++++++++++++++++++++++++++ tests/test_connect.py | 12 ++++++++++++ 3 files changed, 58 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index a235872..9207295 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -145,6 +145,12 @@ <arg name="flags" type="u" direction="in"/> <arg name="networks" type="ao" direction="out"/> </method> + <method name="ListStoragePools"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virConnectListAllStoragePools"/> + <arg name="flags" type="u" direction="in"/> + <arg name="storagePools" type="ao" direction="out"/> + </method> <method name="NetworkCreateXML"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkCreateXML"/> diff --git a/src/connect.c b/src/connect.c index e838e98..858db43 100644 --- a/src/connect.c +++ b/src/connect.c @@ -709,6 +709,45 @@ virtDBusConnectListNetworks(GVariant *inArgs, *outArgs = g_variant_new_tuple(&gnetworks, 1); } +static void +virtDBusConnectListStoragePools(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePoolPtr) storagePools = NULL; + guint flags; + GVariantBuilder builder; + GVariant *gstoragePools; + + g_variant_get(inArgs, "(u)", &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + if (virConnectListAllStoragePools(connect->connection, &storagePools, + flags) < 0) { + return virtDBusUtilSetLastVirtError(error); + } + + g_variant_builder_init(&builder, G_VARIANT_TYPE("ao")); + + for (gint i = 0; storagePools[i]; i++) { + g_autofree gchar *path = NULL; + path = virtDBusUtilBusPathForVirStoragePool(storagePools[i], + connect->storagePoolPath); + + g_variant_builder_add(&builder, "o", path); + } + + gstoragePools = g_variant_builder_end(&builder); + *outArgs = g_variant_new_tuple(&gstoragePools, 1); +} + static void virtDBusConnectNetworkCreateXML(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -1082,6 +1121,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "GetSysinfo", virtDBusConnectGetSysinfo }, { "ListDomains", virtDBusConnectListDomains }, { "ListNetworks", virtDBusConnectListNetworks }, + { "ListStoragePools", virtDBusConnectListStoragePools }, { "NetworkCreateXML", virtDBusConnectNetworkCreateXML }, { "NetworkDefineXML", virtDBusConnectNetworkDefineXML }, { "NetworkLookupByName", virtDBusConnectNetworkLookupByName }, diff --git a/tests/test_connect.py b/tests/test_connect.py index 3eeecb9..d8f05e8 100755 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -126,6 +126,18 @@ class TestConnect(libvirttest.BaseTestClass): arch = "x86_64" assert isinstance(self.connect.GetCPUModelNames(arch, 0), dbus.Array) + def test_connect_list_storage_pools(self): + storage_pools = self.connect.ListStoragePools(0) + assert isinstance(storage_pools, dbus.Array) + assert len(storage_pools) == 1 + + for path in storage_pools: + assert isinstance(path, dbus.ObjectPath) + storage_pool = self.bus.get_object('org.libvirt', path) + + # ensure the path exists by calling Introspect on it + storage_pool.Introspect(dbus_interface=dbus.INTROSPECTABLE_IFACE) + def test_connect_network_create_xml(self): def network_started(path, event): if event != libvirttest.NetworkEvent.STARTED: -- 2.15.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list