[libvirt] [dbus PATCH v2 08/17] Implement GetXMLDesc method for Interface Interface

Anya Harter aharter at redhat.com
Fri Jul 20 18:34:52 UTC 2018


Signed-off-by: Anya Harter <aharter at redhat.com>
---
 data/org.libvirt.Interface.xml |  6 ++++++
 src/interface.c                | 28 ++++++++++++++++++++++++++++
 tests/test_interface.py        |  4 ++++
 3 files changed, 38 insertions(+)

diff --git a/data/org.libvirt.Interface.xml b/data/org.libvirt.Interface.xml
index 4534b97..dc03258 100644
--- a/data/org.libvirt.Interface.xml
+++ b/data/org.libvirt.Interface.xml
@@ -13,6 +13,12 @@
         value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDestroy"/>
       <arg name="flags" type="u" direction="in"/>
     </method>
+    <method name="GetXMLDesc">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetXMLDesc"/>
+      <arg name="flags" type="u" direction="in"/>
+      <arg name="xml" type="s" direction="out"/>
+    </method>
     <method name="Undefine">
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceUndefine"/>
diff --git a/src/interface.c b/src/interface.c
index a2d1cef..fcec623 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -70,6 +70,33 @@ virtDBusInterfaceDestroy(GVariant *inArgs,
         virtDBusUtilSetLastVirtError(error);
 }
 
+static void
+virtDBusInterfaceGetXMLDesc(GVariant *inArgs,
+                            GUnixFDList *inFDs G_GNUC_UNUSED,
+                            const gchar *objectPath,
+                            gpointer userData,
+                            GVariant **outArgs,
+                            GUnixFDList **outFDs G_GNUC_UNUSED,
+                            GError **error)
+{
+    virtDBusConnect *connect = userData;
+    g_autoptr(virInterface) interface = NULL;
+    g_autofree gchar *xml = NULL;
+    guint flags;
+
+    g_variant_get(inArgs, "(u)", &flags);
+
+    interface = virtDBusInterfaceGetVirInterface(connect, objectPath, error);
+    if (!interface)
+        return;
+
+    xml = virInterfaceGetXMLDesc(interface, flags);
+    if (!xml)
+        return virtDBusUtilSetLastVirtError(error);
+
+    *outArgs = g_variant_new("(s)", xml);
+}
+
 static void
 virtDBusInterfaceUndefine(GVariant *inArgs G_GNUC_UNUSED,
                           GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -97,6 +124,7 @@ static virtDBusGDBusPropertyTable virtDBusInterfacePropertyTable[] = {
 static virtDBusGDBusMethodTable virtDBusInterfaceMethodTable[] = {
     { "Create", virtDBusInterfaceCreate },
     { "Destroy", virtDBusInterfaceDestroy },
+    { "GetXMLDesc", virtDBusInterfaceGetXMLDesc },
     { "Undefine", virtDBusInterfaceUndefine },
     { 0 }
 };
diff --git a/tests/test_interface.py b/tests/test_interface.py
index 4a83672..0b5a943 100755
--- a/tests/test_interface.py
+++ b/tests/test_interface.py
@@ -21,5 +21,9 @@ class TestInterface(libvirttest.BaseTestClass):
         interface_obj.Destroy(0)
         interface_obj.Create(0)
 
+    def test_interface_get_xml_description(self):
+        _,interface_obj = self.interface_create()
+        assert isinstance(interface_obj.GetXMLDesc(0), dbus.String)
+
 if __name__ == '__main__':
     libvirttest.run()
-- 
2.17.1




More information about the libvir-list mailing list