Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
Reviewed-by: Ján Tomko <jtomko(a)redhat.com>
---
data/org.libvirt.Connect.xml | 6 ++++++
src/connect.c | 30 ++++++++++++++++++++++++++++++
tests/test_connect.py | 15 +++++++++++++++
3 files changed, 51 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index f41acd2..d3871b3 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -308,6 +308,12 @@
<arg name="uuid" type="s" direction="in"/>
<arg name="storagePool" type="o"
direction="out"/>
</method>
+ <method name="StorageVolLookupByKey">
+ <annotation name="org.gtk.GDBus.DocString"
+ value="See
https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolLookup...
+ <arg name="key" type="s" direction="in"/>
+ <arg name="storageVol" type="o"
direction="out"/>
+ </method>
<signal name="DomainEvent">
<annotation name="org.gtk.GDBus.DocString"
value="See
https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEven...
diff --git a/src/connect.c b/src/connect.c
index 1090e3e..ff9d91a 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -1544,6 +1544,35 @@ virtDBusConnectStoragePoolLookupByUUID(GVariant *inArgs,
*outArgs = g_variant_new("(o)", path);
}
+static void
+virtDBusConnectStorageVolLookupByKey(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(virStorageVol) storageVol = NULL;
+ g_autofree gchar *path = NULL;
+ const gchar *key;
+
+ g_variant_get(inArgs, "(&s)", &key);
+
+ if (!virtDBusConnectOpen(connect, error))
+ return;
+
+ storageVol = virStorageVolLookupByKey(connect->connection, key);
+ if (!storageVol)
+ return virtDBusUtilSetLastVirtError(error);
+
+ path = virtDBusUtilBusPathForVirStorageVol(storageVol,
+ connect->storageVolPath);
+
+ *outArgs = g_variant_new("(o)", path);
+}
+
static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = {
{ "Encrypted", virtDBusConnectGetEncrypted, NULL },
{ "Hostname", virtDBusConnectGetHostname, NULL },
@@ -1597,6 +1626,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
{ "StoragePoolDefineXML", virtDBusConnectStoragePoolDefineXML },
{ "StoragePoolLookupByName", virtDBusConnectStoragePoolLookupByName },
{ "StoragePoolLookupByUUID", virtDBusConnectStoragePoolLookupByUUID },
+ { "StorageVolLookupByKey", virtDBusConnectStorageVolLookupByKey },
{ 0 }
};
diff --git a/tests/test_connect.py b/tests/test_connect.py
index ec3f551..5182769 100755
--- a/tests/test_connect.py
+++ b/tests/test_connect.py
@@ -212,6 +212,21 @@ class TestConnect(libvirttest.BaseTestClass):
path = getattr(self.connect, lookup_method_name)(prop)
assert original_path == path
+ @pytest.mark.usefixtures("storage_volume_create")
+ @pytest.mark.parametrize("lookup_method_name,lookup_item", [
+ ("StorageVolLookupByKey", 'Key'),
+ ])
+ def test_connect_storage_vol_lookup_by_property(self,
+ lookup_method_name,
+ lookup_item):
+ """Parameterized test for all StorageVolLookupBy* API calls of
Connect interface
+ """
+ original_path, obj = self.get_test_storage_volume()
+ prop = obj.Get('org.libvirt.StorageVol', lookup_item,
+ dbus_interface=dbus.PROPERTIES_IFACE)
+ path = getattr(self.connect, lookup_method_name)(prop)
+ assert original_path == path
+
if __name__ == '__main__':
libvirttest.run()
--
2.15.0