[dbus PATCH 4/5] Implement Name property for Network interface

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

 



This commit also introduces the virtDBusNetworkGetVirNetwork
static function which is needed for the virtDBusNetworkGetName.

Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx>
---
 data/org.libvirt.Network.xml |  4 ++++
 src/network.c                | 43 +++++++++++++++++++++++++++++++++++++++++++
 test/Makefile.am             |  3 ++-
 test/libvirttest.py          | 12 ++++++++++++
 4 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/data/org.libvirt.Network.xml b/data/org.libvirt.Network.xml
index 2b7c4f7..1215ac3 100644
--- a/data/org.libvirt.Network.xml
+++ b/data/org.libvirt.Network.xml
@@ -3,5 +3,9 @@
 
 <node name="/org/libvirt/network">
   <interface name="org.libvirt.Network">
+    <property name="Name" type="s" access="read">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetName"/>
+    </property>
   </interface>
 </node>
diff --git a/src/network.c b/src/network.c
index 0d0e992..fdfaaa7 100644
--- a/src/network.c
+++ b/src/network.c
@@ -3,7 +3,50 @@
 
 #include <libvirt/libvirt.h>
 
+static virNetworkPtr
+virtDBusNetworkGetVirNetwork(virtDBusConnect *connect,
+                             const gchar *objectPath,
+                             GError **error)
+{
+    virNetworkPtr network;
+
+    if (virtDBusConnectOpen(connect, error) < 0)
+        return NULL;
+
+    network = virtDBusUtilVirNetworkFromBusPath(connect->connection,
+                                                objectPath,
+                                                connect->networkPath);
+    if (!network) {
+        virtDBusUtilSetLastVirtError(error);
+        return NULL;
+    }
+
+    return network;
+}
+
+static void
+virtDBusNetworkGetName(const gchar *objectPath,
+                       gpointer userData,
+                       GVariant **value,
+                       GError **error)
+{
+    virtDBusConnect *connect = userData;
+    g_autoptr(virNetwork) network = NULL;
+    const gchar *name;
+
+    network = virtDBusNetworkGetVirNetwork(connect, objectPath, error);
+    if (!network)
+        return;
+
+    name = virNetworkGetName(network);
+    if (!name)
+        return virtDBusUtilSetLastVirtError(error);
+
+    *value = g_variant_new("s", name);
+}
+
 static virtDBusGDBusPropertyTable virtDBusNetworkPropertyTable[] = {
+    { "Name", virtDBusNetworkGetName, NULL },
     { 0 }
 };
 
diff --git a/test/Makefile.am b/test/Makefile.am
index acb2d33..089ade5 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -4,7 +4,8 @@ test_helpers = \
 
 test_programs = \
 	test_connect.py \
-	test_domain.py
+	test_domain.py \
+	test_network.py
 
 EXTRA_DIST = \
 	$(test_helpers) \
diff --git a/test/libvirttest.py b/test/libvirttest.py
index c4dc96f..ecd8aef 100644
--- a/test/libvirttest.py
+++ b/test/libvirttest.py
@@ -70,3 +70,15 @@ class BaseTestClass():
         path = self.connect.ListDomains(0)[0]
         obj = self.bus.get_object('org.libvirt', path)
         return obj, dbus.Interface(obj, 'org.libvirt.Domain')
+
+    def test_network(self):
+        """Fetch information for the test network from test driver
+
+        Returns:
+            (dbus.proxies.ProxyObject, dbus.proxies.ProxyObject):
+            Test Network Object, Local proxy for the test Network Object.
+
+        """
+        path = self.connect.ListNetworks(0)[0]
+        obj = self.bus.get_object('org.libvirt', path)
+        return path, obj
-- 
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