Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
---
data/org.libvirt.Connect.xml | 7 +++++++
src/connect.c | 41 +++++++++++++++++++++++++++++++++++++++++
tests/test_connect.py | 4 ++++
3 files changed, 52 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index ee7bfdc..e5c18bd 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -166,6 +166,13 @@
<arg name="uuid" type="s" direction="in"/>
<arg name="network" type="o" direction="out"/>
</method>
+ <method name="NodeGetCPUStats">
+ <annotation name="org.gtk.GDBus.DocString"
+ value="See
https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetCPUStats&quo...
+ <arg name="cpuNum" type="i" direction="in"/>
+ <arg name="flags" type="u" direction="in"/>
+ <arg name="cpuStats" type="a{st}"
direction="out"/>
+ </method>
<signal name="DomainEvent">
<annotation name="org.gtk.GDBus.DocString"
value="See
https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEven...
diff --git a/src/connect.c b/src/connect.c
index 5e577e4..6d0243f 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -842,6 +842,46 @@ virtDBusConnectNetworkLookupByUUID(GVariant *inArgs,
*outArgs = g_variant_new("(o)", path);
}
+static void
+virtDBusConnectNodeGetCPUStats(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;
+ gint cpuNum;
+ guint flags;
+ g_autofree virNodeCPUStatsPtr stats = NULL;
+ gint count = 0;
+ gint ret;
+ GVariant *gret;
+ GVariantBuilder builder;
+
+ g_variant_get(inArgs, "(iu)", &cpuNum, &flags);
+
+ if (!virtDBusConnectOpen(connect, error))
+ return;
+
+ ret = virNodeGetCPUStats(connect->connection, cpuNum, NULL, &count, flags);
+ if (ret == 0 && count != 0) {
+ stats = g_new0(virNodeCPUStats, count);
+ if (virNodeGetCPUStats(connect->connection, cpuNum, stats,
+ &count, flags) < 0) {
+ return virtDBusUtilSetLastVirtError(error);
+ }
+ }
+
+ g_variant_builder_init(&builder, G_VARIANT_TYPE("a{st}"));
+ for (gint i = 0; i < count; i++)
+ g_variant_builder_add(&builder, "{st}", stats[i].field,
stats[i].value);
+ gret = g_variant_builder_end(&builder);
+
+ *outArgs = g_variant_new_tuple(&gret, 1);
+}
+
static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = {
{ "Encrypted", virtDBusConnectGetEncrypted, NULL },
{ "Hostname", virtDBusConnectGetHostname, NULL },
@@ -873,6 +913,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
{ "NetworkDefineXML", virtDBusConnectNetworkDefineXML },
{ "NetworkLookupByName", virtDBusConnectNetworkLookupByName },
{ "NetworkLookupByUUID", virtDBusConnectNetworkLookupByUUID },
+ { "NodeGetCPUStats", virtDBusConnectNodeGetCPUStats },
{ 0 }
};
diff --git a/tests/test_connect.py b/tests/test_connect.py
index 57f0658..1383cc0 100755
--- a/tests/test_connect.py
+++ b/tests/test_connect.py
@@ -156,6 +156,10 @@ class TestConnect(libvirttest.BaseTestClass):
path = getattr(self.connect, lookup_method_name)(prop)
assert original_path == path
+ def test_connect_node_get_cpu_stats(self):
+ stats = self.connect.NodeGetCPUStats(0, 0)
+ assert isinstance(stats, dbus.Dictionary)
+
if __name__ == '__main__':
libvirttest.run()
--
2.15.0