Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
---
data/org.libvirt.Connect.xml | 6 ++++++
src/connect.c | 29 +++++++++++++++++++++++++++++
test/test_connect.py | 1 +
3 files changed, 36 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index 53f996b..c99f700 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -32,6 +32,12 @@
<arg name="id" type="u" direction="in"/>
<arg name="domain" type="o" direction="out"/>
</method>
+ <method name="LookupByName">
+ <annotation name="org.gtk.GDBus.DocString"
+ value="See
https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainLookupByNam...
+ <arg name="name" type="s" 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 f1177d2..5952ff3 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -223,6 +223,34 @@ virtDBusDomainLookupByID(GVariant *inArgs,
*outArgs = g_variant_new("(o)", path);
}
+static void
+virtDBusDomainLookupByName(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;
+ const gchar *name;
+
+ g_variant_get(inArgs, "(s)", &name);
+
+ if (!virtDBusConnectOpen(connect, NULL))
+ return;
+
+ domain = virDomainLookupByName(connect->connection, name);
+ 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 }
@@ -233,6 +261,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
{ "CreateXML", virtDBusConnectCreateXML },
{ "DefineXML", virtDBusConnectDefineXML },
{ "LookupByID", virtDBusDomainLookupByID },
+ { "LookupByName", virtDBusDomainLookupByName },
{ NULL, NULL }
};
diff --git a/test/test_connect.py b/test/test_connect.py
index ea6fdde..a7a6a91 100755
--- a/test/test_connect.py
+++ b/test/test_connect.py
@@ -55,6 +55,7 @@ class TestConnect(libvirttest.BaseTestClass):
@pytest.mark.parametrize("lookup_method_name,lookup_item", [
("LookupByID", 'Id'),
+ ("LookupByName", 'Name'),
])
def test_connect_lookup_by_id(self, lookup_method_name, lookup_item):
"""Parameterized test for all LookupBy* API calls of Connect
interface
--
2.15.0