[libvirt] [dbus PATCH 10/10] Implement Create method for Network Interface

Katerina Koukiou kkoukiou at redhat.com
Thu Apr 5 13:29:34 UTC 2018


Signed-off-by: Katerina Koukiou <kkoukiou at redhat.com>
---
 data/org.libvirt.Network.xml |  4 ++++
 src/network.c                | 21 +++++++++++++++++++++
 test/test_network.py         | 14 ++++++++++++++
 3 files changed, 39 insertions(+)

diff --git a/data/org.libvirt.Network.xml b/data/org.libvirt.Network.xml
index 8a8eef7..0505e7a 100644
--- a/data/org.libvirt.Network.xml
+++ b/data/org.libvirt.Network.xml
@@ -19,6 +19,10 @@
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetUUIDString"/>
     </property>
+    <method name="Create">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkCreate"/>
+    </method>
     <method name="Destroy">
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-network.html#virDomainDestroy"/>
diff --git a/src/network.c b/src/network.c
index c911880..1d749e4 100644
--- a/src/network.c
+++ b/src/network.c
@@ -107,6 +107,26 @@ virtDBusNetworkGetUUID(const gchar *objectPath,
     *value = g_variant_new("s", uuid);
 }
 
+static void
+virtDBusNetworkCreate(GVariant *inArgs G_GNUC_UNUSED,
+                      GUnixFDList *inFDs G_GNUC_UNUSED,
+                      const gchar *objectPath,
+                      gpointer userData,
+                      GVariant **outArgs G_GNUC_UNUSED,
+                      GUnixFDList **outFDs G_GNUC_UNUSED,
+                      GError **error)
+{
+    virtDBusConnect *connect = userData;
+    g_autoptr(virNetwork) network = NULL;
+
+    network = virtDBusNetworkGetVirNetwork(connect, objectPath, error);
+    if (!network)
+        return;
+
+    if (virNetworkCreate(network) < 0)
+        virtDBusUtilSetLastVirtError(error);
+}
+
 static void
 virtDBusNetworkDestroy(GVariant *inArgs G_GNUC_UNUSED,
                        GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -156,6 +176,7 @@ static virtDBusGDBusPropertyTable virtDBusNetworkPropertyTable[] = {
 };
 
 static virtDBusGDBusMethodTable virtDBusNetworkMethodTable[] = {
+    { "Create", virtDBusNetworkCreate },
     { "Destroy", virtDBusNetworkDestroy },
     { "Undefine", virtDBusNetworkUndefine },
     { 0 }
diff --git a/test/test_network.py b/test/test_network.py
index f61e73d..17d4555 100755
--- a/test/test_network.py
+++ b/test/test_network.py
@@ -17,6 +17,20 @@ class TestNetwork(libvirttest.BaseTestClass):
         assert isinstance(props['Name'], dbus.String)
         assert isinstance(props['UUID'], dbus.String)
 
+    def test_network_create(self):
+        def domain_started(path, _event):
+            assert isinstance(path, dbus.ObjectPath)
+            self.loop.quit()
+
+        self.connect.connect_to_signal('NetworkEvent', domain_started, arg1='Started')
+
+        _,test_network = self.test_network()
+        interface_obj = dbus.Interface(test_network, 'org.libvirt.Network')
+        interface_obj.Destroy()
+        interface_obj.Create()
+
+        self.main_loop()
+
     def test_network_destroy(self):
         def network_stopped(path, _event):
             assert isinstance(path, dbus.ObjectPath)
-- 
2.15.0




More information about the libvir-list mailing list