[libvirt] [dbus PATCH 5/9] Implement NetworkDefineXML method for Connect interface

Katerina Koukiou kkoukiou at redhat.com
Fri Apr 6 11:20:30 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         | 12 ++++++++++++
 3 files changed, 47 insertions(+)

diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index 5f5c5fe..e36b7f6 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -56,6 +56,12 @@
       <arg name="xml" type="s" direction="in"/>
       <arg name="network" type="o" direction="out"/>
     </method>
+    <method name="NetworkDefineXML">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkDefineXML"/>
+      <arg name="xml" type="s" direction="in"/>
+      <arg name="network" type="o" direction="out"/>
+    </method>
     <method name="NetworkLookupByName">
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkLookupByName"/>
diff --git a/src/connect.c b/src/connect.c
index 759b9fb..3a0e969 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -358,6 +358,34 @@ virtDBusConnectNetworkCreateXML(GVariant *inArgs,
     *outArgs = g_variant_new("(o)", path);
 }
 
+static void
+virtDBusConnectNetworkDefineXML(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;
+    gchar *xml;
+
+    g_variant_get(inArgs, "(&s)", &xml);
+
+    if (!virtDBusConnectOpen(connect, error))
+        return;
+
+    network = virNetworkDefineXML(connect->connection, xml);
+    if (!network)
+        return virtDBusUtilSetLastVirtError(error);
+
+    path = virtDBusUtilBusPathForVirNetwork(network, connect->networkPath);
+
+    *outArgs = g_variant_new("(o)", path);
+}
+
 static void
 virtDBusNetworkLookupByName(GVariant *inArgs,
                             GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -428,6 +456,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
     { "DomainLookupByUUID", virtDBusDomainLookupByUUID },
     { "ListNetworks", virtDBusConnectListNetworks },
     { "NetworkCreateXML", virtDBusConnectNetworkCreateXML },
+    { "NetworkDefineXML", virtDBusConnectNetworkDefineXML },
     { "NetworkLookupByName", virtDBusNetworkLookupByName },
     { "NetworkLookupByUUID", virtDBusNetworkLookupByUUID },
     { 0 }
diff --git a/test/test_connect.py b/test/test_connect.py
index e3b493b..c411eeb 100755
--- a/test/test_connect.py
+++ b/test/test_connect.py
@@ -112,6 +112,18 @@ class TestConnect(libvirttest.BaseTestClass):
 
         self.main_loop()
 
+    def test_connect_network_define_xml(self):
+        def network_defined(path, _event):
+            assert isinstance(path, dbus.ObjectPath)
+            self.loop.quit()
+
+        self.connect.connect_to_signal('NetworkEvent', network_defined, arg1='Defined')
+
+        path = self.connect.NetworkDefineXML(self.minimal_network_xml)
+        assert isinstance(path, dbus.ObjectPath)
+
+        self.main_loop()
+
     @pytest.mark.parametrize("lookup_method_name,lookup_item", [
         ("NetworkLookupByName", 'Name'),
         ("NetworkLookupByUUID", 'UUID'),
-- 
2.15.0




More information about the libvir-list mailing list