Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
---
data/org.libvirt.Connect.xml | 6 ++++++
src/connect.c | 29 +++++++++++++++++++++++++++++
test/test_connect.py | 26 ++++++++++++++++++++++++++
3 files changed, 61 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index 715aeef..5f5c5fe 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="NetworkCreateXML">
+ <annotation name="org.gtk.GDBus.DocString"
+ value="See
https://libvirt.org/html/libvirt-libvirt-network.html#virNetworkCreateXML...
+ <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#virNetworkLookupByN...
diff --git a/src/connect.c b/src/connect.c
index 9931c8f..759b9fb 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -330,6 +330,34 @@ virtDBusConnectListNetworks(GVariant *inArgs,
*outArgs = g_variant_new_tuple(&gnetworks, 1);
}
+static void
+virtDBusConnectNetworkCreateXML(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 = virNetworkCreateXML(connect->connection, xml);
+ if (!network)
+ return virtDBusUtilSetLastVirtError(error);
+
+ path = virtDBusUtilBusPathForVirNetwork(network, connect->domainPath);
+
+ *outArgs = g_variant_new("(o)", path);
+}
+
static void
virtDBusNetworkLookupByName(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -399,6 +427,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
{ "DomainLookupByName", virtDBusDomainLookupByName },
{ "DomainLookupByUUID", virtDBusDomainLookupByUUID },
{ "ListNetworks", virtDBusConnectListNetworks },
+ { "NetworkCreateXML", virtDBusConnectNetworkCreateXML },
{ "NetworkLookupByName", virtDBusNetworkLookupByName },
{ "NetworkLookupByUUID", virtDBusNetworkLookupByUUID },
{ 0 }
diff --git a/test/test_connect.py b/test/test_connect.py
index 394f812..e3b493b 100755
--- a/test/test_connect.py
+++ b/test/test_connect.py
@@ -16,6 +16,20 @@ class TestConnect(libvirttest.BaseTestClass):
</domain>
'''
+ minimal_network_xml = '''
+ <network>
+ <name>bar</name>
+ <uuid>004b96e12d78c30f5aa5f03c87d21e69</uuid>
+ <bridge name='brdefault'/>
+ <forward dev='eth0'/>
+ <ip address='192.168.122.1' netmask='255.255.255.0'>
+ <dhcp>
+ <range start='192.168.122.128' end='192.168.122.253'/>
+ </dhcp>
+ </ip>
+ </network>
+ '''
+
def test_list_domains(self):
domains = self.connect.ListDomains(0)
assert isinstance(domains, dbus.Array)
@@ -86,6 +100,18 @@ class TestConnect(libvirttest.BaseTestClass):
# ensure the path exists by calling Introspect on it
network.Introspect(dbus_interface=dbus.INTROSPECTABLE_IFACE)
+ def test_connect_network_create_xml(self):
+ def network_started(path, _event):
+ assert isinstance(path, dbus.ObjectPath)
+ self.loop.quit()
+
+ self.connect.connect_to_signal('NetworkEvent', network_started,
arg1='Started')
+
+ path = self.connect.NetworkCreateXML(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