Signed-off-by: Anya Harter <aharter@xxxxxxxxxx> --- data/org.libvirt.Connect.xml | 7 +++++++ src/connect.c | 30 ++++++++++++++++++++++++++++++ tests/test_connect.py | 4 ++++ tests/xmldata.py | 12 ++++++++++++ 4 files changed, 53 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 7014a09..f690bab 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -148,6 +148,13 @@ <arg name="flags" type="u" direction="in"/> <arg name="sysinfo" type="s" direction="out"/> </method> + <method name="InterfaceDefineXML"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDefineXML"/> + <arg name="xml" type="s" direction="in"/> + <arg name="flags" type="u" direction="in"/> + <arg name="interface" type="o" direction="out"/> + </method> <method name="ListDomains"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectListAllDomains"/> diff --git a/src/connect.c b/src/connect.c index 3dc434d..304a56f 100644 --- a/src/connect.c +++ b/src/connect.c @@ -735,6 +735,35 @@ virtDBusConnectGetSysinfo(GVariant *inArgs, *outArgs = g_variant_new("(s)", sysinfo); } +static void +virtDBusConnectInterfaceDefineXML(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(virInterface) interface = NULL; + g_autofree gchar *path = NULL; + const gchar *xml; + guint flags; + + g_variant_get(inArgs, "(&su)", &xml, &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + interface = virInterfaceDefineXML(connect->connection, xml, flags); + if (!interface) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirInterface(interface, connect->interfacePath); + + *outArgs = g_variant_new("(o)", path); +} + static void virtDBusConnectListDomains(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -1766,6 +1795,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "GetCPUModelNames", virtDBusConnectGetCPUModelNames }, { "GetDomainCapabilities", virtDBusConnectGetDomainCapabilities }, { "GetSysinfo", virtDBusConnectGetSysinfo }, + { "InterfaceDefineXML", virtDBusConnectInterfaceDefineXML }, { "ListDomains", virtDBusConnectListDomains }, { "ListNetworks", virtDBusConnectListNetworks }, { "ListNodeDevices", virtDBusConnectListNodeDevices }, diff --git a/tests/test_connect.py b/tests/test_connect.py index 2299b8a..d21b366 100755 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -84,6 +84,10 @@ class TestConnect(libvirttest.BaseTestClass): sysinfo = self.connect.GetSysinfo(0) assert isinstance(sysinfo, dbus.String) + def test_connect_interface_define_xml(self): + path = self.connect.InterfaceDefineXML(xmldata.minimal_interface_xml, 0) + assert isinstance(path, dbus.ObjectPath) + def test_connect_list_networks(self): networks = self.connect.ListNetworks(0) assert isinstance(networks, dbus.Array) diff --git a/tests/xmldata.py b/tests/xmldata.py index 25bb089..a70bac1 100644 --- a/tests/xmldata.py +++ b/tests/xmldata.py @@ -12,6 +12,18 @@ minimal_domain_xml = ''' </domain> ''' +minimal_interface_xml = ''' +<interface type='ethernet' name='test-iface'> + <start mode='onboot'/> + <mac address='11:22:33:44:55:66'/> + <mtu size='1492'/> + <protocol family='ipv4'> + <ip address='192.168.15.5' prefix='24'/> + <route gateway='192.168.15.1'/> + </protocol> +</interface> +''' + minimal_network_xml = ''' <network> <name>bar</name> -- 2.17.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list