Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
---
data/org.libvirt.Connect.xml | 6 ++++++
src/connect.c | 29 +++++++++++++++++++++++++++++
test/test_connect.py | 12 ++++++++++++
3 files changed, 47 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index 8260a63..7c31f89 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -26,6 +26,12 @@
<arg name="xml" type="s" direction="in"/>
<arg name="domain" type="o" direction="out"/>
</method>
+ <method name="DomainLookupByID">
+ <annotation name="org.gtk.GDBus.DocString"
+ value="See
https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainLookupByID&...
+ <arg name="id" type="u" direction="in"/>
+ <arg name="domain" type="o" direction="out"/>
+ </method>
<signal name="DomainCrashed">
<annotation name="org.gtk.GDBus.DocString"
value="See
https://libvirt.org/html/libvirt-libvirt-domain.html#VIR_DOMAIN_EVENT_CRA...
diff --git a/src/connect.c b/src/connect.c
index 8898e6d..47ab2f8 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -195,6 +195,34 @@ virtDBusConnectDefineXML(GVariant *inArgs,
*outArgs = g_variant_new("(o)", path);
}
+static void
+virtDBusDomainLookupByID(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(virDomain) domain = NULL;
+ g_autofree gchar *path = NULL;
+ guint id;
+
+ g_variant_get(inArgs, "(u)", &id);
+
+ if (!virtDBusConnectOpen(connect, NULL))
+ return;
+
+ domain = virDomainLookupByID(connect->connection, id);
+ if (!domain)
+ return virtDBusUtilSetLastVirtError(error);
+
+ path = virtDBusUtilBusPathForVirDomain(domain, connect->domainPath);
+
+ *outArgs = g_variant_new("(o)", path);
+}
+
static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = {
{ "Version", virtDBusConnectGetVersion, NULL },
{ NULL, NULL, NULL }
@@ -204,6 +232,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
{ "ListDomains", virtDBusConnectListDomains },
{ "CreateXML", virtDBusConnectCreateXML },
{ "DefineXML", virtDBusConnectDefineXML },
+ { "DomainLookupByID", virtDBusDomainLookupByID },
{ NULL, NULL }
};
diff --git a/test/test_connect.py b/test/test_connect.py
index 01d4d41..d6c2ab9 100755
--- a/test/test_connect.py
+++ b/test/test_connect.py
@@ -54,6 +54,18 @@ class TestConnect(libvirttest.BaseTestClass):
self.main_loop()
+ @pytest.mark.parametrize("lookup_method_name,lookup_item", [
+ ("DomainLookupByID", 'Id'),
+ ])
+ def test_connect_lookup_by_id(self, lookup_method_name, lookup_item):
+ """Parameterized test for all LookupBy* API calls of Connect
interface
+ """
+ original_path = self.connect.ListDomains(0)[0]
+ obj, _ = self.domain()
+ props = obj.GetAll('org.libvirt.Domain',
dbus_interface=dbus.PROPERTIES_IFACE)
+ path = getattr(self.connect, lookup_method_name)(props[lookup_item])
+ assert original_path == path
+
@pytest.mark.parametrize("property_name,expected_type", [
("Version", dbus.UInt64),
])
--
2.15.0