[dbus PATCH v2 3/4] Implement DomainLookupByName method for Connect Interface

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx>
---
 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 7c31f89..fd673c8 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="DomainLookupByName">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainLookupByName"/>
+      <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_CRASHED"/>
diff --git a/src/connect.c b/src/connect.c
index 47ab2f8..b94360f 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 },
     { "DomainLookupByID", virtDBusDomainLookupByID },
+    { "DomainLookupByName", virtDBusDomainLookupByName },
     { NULL, NULL }
 };
 
diff --git a/test/test_connect.py b/test/test_connect.py
index d6c2ab9..8a0f8ba 100755
--- a/test/test_connect.py
+++ b/test/test_connect.py
@@ -56,6 +56,7 @@ class TestConnect(libvirttest.BaseTestClass):
 
     @pytest.mark.parametrize("lookup_method_name,lookup_item", [
         ("DomainLookupByID", 'Id'),
+        ("DomainLookupByName", '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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux