Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
---
data/org.libvirt.Domain.xml | 9 +++++++++
src/domain.c | 41 +++++++++++++++++++++++++++++++++++++++++
tests/test_domain.py | 6 ++++++
3 files changed, 56 insertions(+)
diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml
index 168820b..5557030 100644
--- a/data/org.libvirt.Domain.xml
+++ b/data/org.libvirt.Domain.xml
@@ -245,6 +245,15 @@
<arg name="flags" type="u" direction="in"/>
<arg name="memoryParameters" type="a{sv}"
direction="out"/>
</method>
+ <method name="GetMetadata">
+ <annotation name="org.gtk.GDBus.DocString"
+ value="See
https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetMetadata
+ Empty string can be used to pass a NULL as @uri argument."/>
+ <arg name="type" type="s" direction="in"/>
+ <arg name="uri" type="s" direction="in"/>
+ <arg name="flags" type="u" direction="in"/>
+ <arg name="metadata" type="s"
direction="out"/>
+ </method>
<method name="GetSchedulerParameters">
<annotation name="org.gtk.GDBus.DocString"
value="See
https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetSchedule...
diff --git a/src/domain.c b/src/domain.c
index 05ea680..4cd6a4f 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -1402,6 +1402,46 @@ virtDBusDomainGetMemoryParameters(GVariant *inArgs,
*outArgs = g_variant_new_tuple(&grecords, 1);
}
+static void
+virtDBusDomainGetMetadata(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(virDomain) domain = NULL;
+ const gchar *typeStr;
+ gint type;
+ const gchar *uri;
+ guint flags;
+ g_autofree gchar *ret = NULL;
+
+ g_variant_get(inArgs, "(&s&su)", &typeStr, &uri,
&flags);
+ if (g_str_equal(uri, ""))
+ uri = NULL;
+
+ domain = virtDBusDomainGetVirDomain(connect, objectPath, error);
+ if (!domain)
+ return;
+
+ type = virtDBusDomainMetadataTypeFromString(typeStr);
+ if (type < 0) {
+ g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT,
+ "Can't get valid virDomainMetadataType from string
'%s'.",
+ typeStr);
+ return;
+ }
+
+ ret = virDomainGetMetadata(domain, type, uri, flags);
+ if (!ret)
+ return virtDBusUtilSetLastVirtError(error);
+
+ *outArgs = g_variant_new("(s)", ret);
+}
+
static void
virtDBusDomainGetSchedulerParameters(GVariant *inArgs,
GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -2416,6 +2456,7 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = {
{ "GetJobInfo", virtDBusDomainGetJobInfo },
{ "GetJobStats", virtDBusDomainGetJobStats },
{ "GetMemoryParameters", virtDBusDomainGetMemoryParameters },
+ { "GetMetadata", virtDBusDomainGetMetadata },
{ "GetSchedulerParameters", virtDBusDomainGetSchedulerParameters },
{ "GetStats", virtDBusDomainGetStats },
{ "GetTime", virtDBusDomainGetTime },
diff --git a/tests/test_domain.py b/tests/test_domain.py
index f2ae215..d0cebcd 100755
--- a/tests/test_domain.py
+++ b/tests/test_domain.py
@@ -63,6 +63,12 @@ class TestDomain(libvirttest.BaseTestClass):
self.main_loop()
+ def test_domain_metadata(self):
+ obj, domain = self.domain()
+ description_expected = "This is the Test domain"
+ domain.SetMetadata('description', description_expected, "",
"", 0)
+ assert description_expected == domain.GetMetadata('description',
"", 0)
+
def test_resume(self):
def domain_resumed(path, _event):
assert isinstance(path, dbus.ObjectPath)
--
2.15.0