[libvirt] [dbus PATCH v3 4/4] Implement NetworkLookupByName method for Connect interface

Katerina Koukiou kkoukiou at redhat.com
Thu Apr 5 10:40:20 UTC 2018


Signed-off-by: Katerina Koukiou <kkoukiou at redhat.com>
---
 data/org.libvirt.Connect.xml |  6 ++++++
 src/connect.c                | 29 +++++++++++++++++++++++++++++
 test/test_connect.py         | 11 +++++++++++
 3 files changed, 46 insertions(+)

diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index 94704ff..043ee32 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -50,6 +50,12 @@
       <arg name="flags" type="u" direction="in"/>
       <arg name="networks" type="ao" direction="out"/>
     </method>
+    <method name="NetworkLookupByName">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkLookupByName"/>
+      <arg name="name" type="s" direction="in"/>
+      <arg name="network" type="o" direction="out"/>
+    </method>
     <signal name="DomainEvent">
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEventCallback"/>
diff --git a/src/connect.c b/src/connect.c
index f9cd96c..d036753 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -320,6 +320,34 @@ virtDBusConnectListNetworks(GVariant *inArgs,
     *outArgs = g_variant_new_tuple(&gnetworks, 1);
 }
 
+static void
+virtDBusNetworkLookupByName(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(virNetwork) network = NULL;
+    g_autofree gchar *path = NULL;
+    const gchar *name;
+
+    g_variant_get(inArgs, "(s)", &name);
+
+    if (!virtDBusConnectOpen(connect, error))
+        return;
+
+    network = virNetworkLookupByName(connect->connection, name);
+    if (!network)
+        return virtDBusUtilSetLastVirtError(error);
+
+    path = virtDBusUtilBusPathForVirNetwork(network, connect->networkPath);
+
+    *outArgs = g_variant_new("(o)", path);
+}
+
 static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = {
     { "Version", virtDBusConnectGetVersion, NULL },
     { 0 }
@@ -333,6 +361,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
     { "DomainLookupByName", virtDBusDomainLookupByName },
     { "DomainLookupByUUID", virtDBusDomainLookupByUUID },
     { "ListNetworks", virtDBusConnectListNetworks },
+    { "NetworkLookupByName", virtDBusNetworkLookupByName },
     { 0 }
 };
 
diff --git a/test/test_connect.py b/test/test_connect.py
index 03f353f..440a496 100755
--- a/test/test_connect.py
+++ b/test/test_connect.py
@@ -86,6 +86,17 @@ class TestConnect(libvirttest.BaseTestClass):
             # ensure the path exists by calling Introspect on it
             network.Introspect(dbus_interface=dbus.INTROSPECTABLE_IFACE)
 
+    @pytest.mark.parametrize("lookup_method_name,lookup_item", [
+        ("NetworkLookupByName", 'Name'),
+    ])
+    def test_connect_network_lookup_by_property(self, lookup_method_name, lookup_item):
+        """Parameterized test for all NetworkLookupBy* API calls of Connect interface
+        """
+        original_path, obj = self.test_network()
+        prop = obj.Get('org.libvirt.Network', 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




More information about the libvir-list mailing list