Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
---
data/org.libvirt.NodeDevice.xml | 5 +++++
src/nodedev.c | 37 +++++++++++++++++++++++++++++++++++++
tests/test_nodedev.py | 6 ++++++
3 files changed, 48 insertions(+)
diff --git a/data/org.libvirt.NodeDevice.xml b/data/org.libvirt.NodeDevice.xml
index 1185bca..bf85958 100644
--- a/data/org.libvirt.NodeDevice.xml
+++ b/data/org.libvirt.NodeDevice.xml
@@ -28,5 +28,10 @@
<arg name="flags" type="u" direction="in"/>
<arg name="xml" type="s" direction="out"/>
</method>
+ <method name="ListCaps">
+ <annotation name="org.gtk.GDBus.DocString"
+ value="See
https://libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceListCa...
+ <arg name="names" type="as" direction="out"/>
+ </method>
</interface>
</node>
diff --git a/src/nodedev.c b/src/nodedev.c
index e61242d..01fcd35 100644
--- a/src/nodedev.c
+++ b/src/nodedev.c
@@ -137,6 +137,42 @@ virtDBusNodeDeviceGetXMLDesc(GVariant *inArgs,
*outArgs = g_variant_new("(s)", xml);
}
+static void
+virtDBusNodeDeviceListCaps(GVariant *inArgs G_GNUC_UNUSED,
+ GUnixFDList *inFDs G_GNUC_UNUSED,
+ const gchar *objectPath,
+ gpointer userData,
+ GVariant **outArgs,
+ GUnixFDList **outFDs G_GNUC_UNUSED,
+ GError **error)
+{
+ virtDBusConnect *connect = userData;
+ g_autoptr(virNodeDevice) dev = NULL;
+ g_autoptr(virtDBusCharArray) caps = NULL;
+ gint ncaps;
+ GVariant *gret;
+ GVariantBuilder builder;
+
+ dev = virtDBusNodeDeviceGetVirNodeDevice(connect, objectPath, error);
+ if (!dev)
+ return;
+
+ if ((ncaps = virNodeDeviceNumOfCaps(dev)) < 0)
+ return virtDBusUtilSetLastVirtError(error);
+
+ caps = g_new0(char *, ncaps + 1);
+
+ if ((ncaps = virNodeDeviceListCaps(dev, caps, ncaps)) < 0)
+ return virtDBusUtilSetLastVirtError(error);
+
+ g_variant_builder_init(&builder, G_VARIANT_TYPE("as"));
+ for (gint i = 0; i < ncaps; i++)
+ g_variant_builder_add(&builder, "s", caps[i]);
+ gret = g_variant_builder_end(&builder);
+
+ *outArgs = g_variant_new_tuple(&gret, 1);
+}
+
static virtDBusGDBusPropertyTable virtDBusNodeDevicePropertyTable[] = {
{ "Name", virtDBusNodeDeviceGetName, NULL },
{ "Parent", virtDBusNodeDeviceGetParent, NULL },
@@ -147,6 +183,7 @@ static virtDBusGDBusMethodTable virtDBusNodeDeviceMethodTable[] = {
{ "Destroy", virtDBusNodeDeviceDestroy },
{ "Detach", virtDBusNodeDeviceDetach },
{ "GetXMLDesc", virtDBusNodeDeviceGetXMLDesc },
+ { "ListCaps", virtDBusNodeDeviceListCaps },
{ 0 }
};
diff --git a/tests/test_nodedev.py b/tests/test_nodedev.py
index 64c97b2..6aa6211 100755
--- a/tests/test_nodedev.py
+++ b/tests/test_nodedev.py
@@ -32,6 +32,12 @@ class TestNodeDevice(libvirttest.BaseTestClass):
interface_obj = dbus.Interface(obj, 'org.libvirt.NodeDevice')
assert isinstance(interface_obj.GetXMLDesc(0), dbus.String)
+ def test_node_device_list_caps(self):
+ test_node_device_path = self.node_device_create()
+ obj = self.bus.get_object('org.libvirt', test_node_device_path)
+ interface_obj = dbus.Interface(obj, 'org.libvirt.NodeDevice')
+ assert isinstance(interface_obj.ListCaps(), dbus.Array)
+
def test_node_device_properties_type(self):
""" Ensure correct return type for NodeDevice properties
"""
--
2.15.0