Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
---
data/org.libvirt.Connect.xml | 5 +++++
src/connect.c | 24 ++++++++++++++++++++++++
tests/test_connect.py | 4 ++++
3 files changed, 33 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index e5c18bd..c642aff 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -173,6 +173,11 @@
<arg name="flags" type="u" direction="in"/>
<arg name="cpuStats" type="a{st}"
direction="out"/>
</method>
+ <method name="NodeGetFreeMemory">
+ <annotation name="org.gtk.GDBus.DocString"
+ value="See
https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetFreeMemory&q...
+ <arg name="freemem" type="t" 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 6d0243f..b161925 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -882,6 +882,29 @@ virtDBusConnectNodeGetCPUStats(GVariant *inArgs,
*outArgs = g_variant_new_tuple(&gret, 1);
}
+static void
+virtDBusConnectNodeGetFreeMemory(GVariant *inArgs G_GNUC_UNUSED,
+ 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;
+ guint64 freemem;
+
+ if (!virtDBusConnectOpen(connect, error))
+ return;
+
+ freemem = virNodeGetFreeMemory(connect->connection);
+ if (freemem == 0)
+ return virtDBusUtilSetLastVirtError(error);
+
+ *outArgs = g_variant_new("(t)", freemem);
+}
+
static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = {
{ "Encrypted", virtDBusConnectGetEncrypted, NULL },
{ "Hostname", virtDBusConnectGetHostname, NULL },
@@ -914,6 +937,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
{ "NetworkLookupByName", virtDBusConnectNetworkLookupByName },
{ "NetworkLookupByUUID", virtDBusConnectNetworkLookupByUUID },
{ "NodeGetCPUStats", virtDBusConnectNodeGetCPUStats },
+ { "NodeGetFreeMemory", virtDBusConnectNodeGetFreeMemory },
{ 0 }
};
diff --git a/tests/test_connect.py b/tests/test_connect.py
index 1383cc0..7b9ad0d 100755
--- a/tests/test_connect.py
+++ b/tests/test_connect.py
@@ -160,6 +160,10 @@ class TestConnect(libvirttest.BaseTestClass):
stats = self.connect.NodeGetCPUStats(0, 0)
assert isinstance(stats, dbus.Dictionary)
+ def test_connect_node_get_free_memory(self):
+ free_mem = self.connect.NodeGetFreeMemory()
+ assert isinstance(free_mem, dbus.UInt64)
+
if __name__ == '__main__':
libvirttest.run()
--
2.15.0