[libvirt] [dbus PATCH 0/6] More methods for Domain Interface

Katerina Koukiou (6): Implement Setter for Autostart property for Domain interface Implement SchedulerType property for Domain Interface Introduce virtDBusDomainMemoryStatTypeToString helper function Implement MemoryStats for Domain Interface Implement AttachDevice method for Domain Interface Implement DetachDevice method for Domain Interface data/org.libvirt.Domain.xml | 28 +++++++- src/domain.c | 166 +++++++++++++++++++++++++++++++++++++++++++- test/test_domain.py | 10 +++ 3 files changed, 201 insertions(+), 3 deletions(-) -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 5 +++-- src/domain.c | 22 +++++++++++++++++++++- test/test_domain.py | 7 +++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index 78378bb..b8ee5b8 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -7,9 +7,10 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainIsActive"/> </property> - <property name="Autostart" type="b" access="read"> + <property name="Autostart" type="b" access="readwrite"> <annotation name="org.gtk.GDBus.DocString" - value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetAutostart"/> + value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetAutostart and + https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetAutostart"/> </property> <property name="Id" type="u" access="read"> <annotation name="org.gtk.GDBus.DocString" diff --git a/src/domain.c b/src/domain.c index 14f07fc..82682ef 100644 --- a/src/domain.c +++ b/src/domain.c @@ -218,6 +218,26 @@ virtDBusDomainGetUUID(const gchar *objectPath, *value = g_variant_new("s", uuid); } +static void +virtDBusDomainSetAutostart(GVariant *value, + const gchar *objectPath, + gpointer userData, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virDomain) domain = NULL; + gboolean autostart; + + g_variant_get(value, "b", &autostart); + + domain = virtDBusDomainGetVirDomain(connect, objectPath, error); + if (!domain) + return; + + if (virDomainSetAutostart(domain, autostart) < 0) + return virtDBusUtilSetLastVirtError(error); +} + static void virtDBusDomainCreate(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -492,7 +512,7 @@ virtDBusDomainUndefine(GVariant *inArgs, static virtDBusGDBusPropertyTable virtDBusDomainPropertyTable[] = { { "Active", virtDBusDomainGetActive, NULL }, - { "Autostart", virtDBusDomainGetAutostart, NULL }, + { "Autostart", virtDBusDomainGetAutostart, virtDBusDomainSetAutostart }, { "Id", virtDBusDomainGetId, NULL }, { "Name", virtDBusDomainGetName, NULL }, { "OSType", virtDBusDomainGetOsType, NULL }, diff --git a/test/test_domain.py b/test/test_domain.py index 952bf59..7fa9aad 100755 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -37,6 +37,13 @@ class TestDomain(libvirttest.BaseTestClass): raise e domain.Undefine(0) + def test_domain_autostart(self): + _, domain = self.domain() + autostart_expected = True + domain.Set('org.libvirt.Domain', 'Autostart', autostart_expected, dbus_interface=dbus.PROPERTIES_IFACE) + autostart_current = domain.Get('org.libvirt.Domain', 'Autostart', dbus_interface=dbus.PROPERTIES_IFACE) + assert autostart_current == dbus.Boolean(autostart_expected) + def test_resume(self): def domain_resumed(path, _event): assert isinstance(path, dbus.ObjectPath) -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 4 ++++ src/domain.c | 23 +++++++++++++++++++++++ test/test_domain.py | 3 +++ 3 files changed, 30 insertions(+) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index b8ee5b8..dbeafce 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -28,6 +28,10 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainIsPersistent"/> </property> + <property name="SchedulerType" type="si" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetSchedulerType"/> + </property> <property name="State" type="s" access="read"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetState"/> diff --git a/src/domain.c b/src/domain.c index 82682ef..f775fd4 100644 --- a/src/domain.c +++ b/src/domain.c @@ -149,6 +149,28 @@ virtDBusDomainGetPersistent(const gchar *objectPath, *value = g_variant_new("b", !!persistent); } +static void +virtDBusDomainGetSchedulerType(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virDomain) domain = NULL; + g_autofree gchar *schedtype = NULL; + gint nparams; + + domain = virtDBusDomainGetVirDomain(connect, objectPath, error); + if (!domain) + return; + + schedtype = virDomainGetSchedulerType(domain, &nparams); + if (!schedtype) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("(si)", schedtype, nparams); +} + static void virtDBusDomainGetState(const gchar *objectPath, gpointer userData, @@ -517,6 +539,7 @@ static virtDBusGDBusPropertyTable virtDBusDomainPropertyTable[] = { { "Name", virtDBusDomainGetName, NULL }, { "OSType", virtDBusDomainGetOsType, NULL }, { "Persistent", virtDBusDomainGetPersistent, NULL }, + { "SchedulerType", virtDBusDomainGetSchedulerType, NULL}, { "State", virtDBusDomainGetState, NULL }, { "UUID", virtDBusDomainGetUUID, NULL }, { 0 } diff --git a/test/test_domain.py b/test/test_domain.py index 7fa9aad..a7cf962 100755 --- a/test/test_domain.py +++ b/test/test_domain.py @@ -16,6 +16,9 @@ class TestDomain(libvirttest.BaseTestClass): assert isinstance(props['Name'], dbus.String) assert isinstance(props['OSType'], dbus.String) assert isinstance(props['Persistent'], dbus.Boolean) + assert any([isinstance(props['SchedulerType'], dbus.Struct), + isinstance(props['SchedulerType'][0], dbus.String), + isinstance(props['SchedulerType'][1], dbus.Int32)]) assert isinstance(props['State'], dbus.String) assert isinstance(props['UUID'], dbus.String) -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- src/domain.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/domain.c b/src/domain.c index f775fd4..9b3de57 100644 --- a/src/domain.c +++ b/src/domain.c @@ -3,6 +3,20 @@ #include <libvirt/libvirt.h> +VIRT_DBUS_ENUM_DECL(virtDBusDomainMemoryStat) +VIRT_DBUS_ENUM_IMPL(virtDBusDomainMemoryStat, + VIR_DOMAIN_MEMORY_STAT_LAST, + "swap_in", + "swap_out", + "major_fault", + "minor_fault", + "unused", + "available", + "actual_baloon", + "rss", + "usable", + "last_update") + static virDomainPtr virtDBusDomainGetVirDomain(virtDBusConnect *connect, const gchar *objectPath, -- 2.15.0

This method is not tested for now since the test driver doesn't support this API. Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 7 ++++++ src/domain.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index dbeafce..6795d30 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -69,6 +69,13 @@ <arg name="flags" type="u" direction="in"/> <arg name="xml" type="s" direction="out"/> </method> + <method name="MemoryStats"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainMemoryStats"/> + <arg name="nr_stats" type="u" direction="in"/> + <arg name="flags" type="u" direction="in"/> + <arg name="stats" type="a{st}" direction="out"/> + </method> <method name="Reboot"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainReboot"/> diff --git a/src/domain.c b/src/domain.c index 9b3de57..0893f96 100644 --- a/src/domain.c +++ b/src/domain.c @@ -17,6 +17,29 @@ VIRT_DBUS_ENUM_IMPL(virtDBusDomainMemoryStat, "usable", "last_update") +static const gchar * +virtDBusDomainMemoryStatToString(gint tag) +{ + const gchar *str = virtDBusDomainMemoryStatTypeToString(tag); + return str ? str : "unknown"; +} + +static GVariant * +virtDBusDomainMemoryStatsToGVariant(virDomainMemoryStatPtr stats, + gint nr_stats) +{ + GVariantBuilder builder; + + g_variant_builder_init(&builder, G_VARIANT_TYPE("a{st}")); + + for (gint i = 0; i < nr_stats; i++) + g_variant_builder_add(&builder, "{st}", + virtDBusDomainMemoryStatToString(stats[i].tag), + stats[i].val); + + return g_variant_builder_end(&builder); +} + static virDomainPtr virtDBusDomainGetVirDomain(virtDBusConnect *connect, const gchar *objectPath, @@ -412,6 +435,39 @@ virtDBusDomainGetXMLDesc(GVariant *inArgs, *outArgs = g_variant_new("(s)", xml); } +static void +virtDBusDomainMemoryStats(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; + g_autofree virDomainMemoryStatPtr stats = NULL; + guint max_stats; + gint nr_stats; + guint flags; + GVariant *gstats; + + g_variant_get(inArgs, "(uu)", &max_stats, &flags); + + domain = virtDBusDomainGetVirDomain(connect, objectPath, error); + if (!domain) + return; + + stats = g_new0(virDomainMemoryStatStruct, max_stats); + nr_stats = virDomainMemoryStats(domain, stats, max_stats, flags); + if (nr_stats == -1) + return virtDBusUtilSetLastVirtError(error); + + gstats = virtDBusDomainMemoryStatsToGVariant(stats, nr_stats); + + *outArgs = g_variant_new_tuple(&gstats, 1); +} + static void virtDBusDomainReboot(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -565,6 +621,7 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = { { "GetStats", virtDBusDomainGetStats }, { "GetVcpus", virtDBusDomainGetVcpus }, { "GetXMLDesc", virtDBusDomainGetXMLDesc }, + { "MemoryStats", virtDBusDomainMemoryStats }, { "Reboot", virtDBusDomainReboot }, { "Reset", virtDBusDomainReset }, { "Resume", virtDBusDomainResume }, -- 2.15.0

This method is not tested for now since the test driver doesn't suport this API. Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 6 ++++++ src/domain.c | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index 6795d30..b620939 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -40,6 +40,12 @@ <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetUUIDString"/> </property> + <method name="AttachDevice"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainAttachDeviceFlags"/> + <arg name="xml" type="s" direction="in"/> + <arg name="flags" type="u" direction="in"/> + </method> <method name="Create"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainCreateWithFlags"/> diff --git a/src/domain.c b/src/domain.c index 0893f96..d246d45 100644 --- a/src/domain.c +++ b/src/domain.c @@ -297,6 +297,30 @@ virtDBusDomainSetAutostart(GVariant *value, return virtDBusUtilSetLastVirtError(error); } +static void +virtDBusDomainAttachDevice(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virDomain) domain = NULL; + const gchar *xml; + guint flags; + + g_variant_get(inArgs, "(&su)", &xml, &flags); + + domain = virtDBusDomainGetVirDomain(connect, objectPath, error); + if (!domain) + return; + + if (virDomainAttachDeviceFlags(domain, xml, flags) == -1) + return virtDBusUtilSetLastVirtError(error); +} + static void virtDBusDomainCreate(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -616,6 +640,7 @@ static virtDBusGDBusPropertyTable virtDBusDomainPropertyTable[] = { }; static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = { + { "AttachDevice", virtDBusDomainAttachDevice }, { "Create", virtDBusDomainCreate }, { "Destroy", virtDBusDomainDestroy }, { "GetStats", virtDBusDomainGetStats }, -- 2.15.0

This method is not tested for now since the test driver doesn't suport this API. Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Domain.xml | 6 ++++++ src/domain.c | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml index b620939..83e37bc 100644 --- a/data/org.libvirt.Domain.xml +++ b/data/org.libvirt.Domain.xml @@ -56,6 +56,12 @@ value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainDestroyFlags"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="DetachDevice"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainDetachDeviceFlags"/> + <arg name="xml" type="s" direction="in"/> + <arg name="flags" type="u" direction="in"/> + </method> <method name="GetStats"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainListGetStats"/> diff --git a/src/domain.c b/src/domain.c index d246d45..ed50c68 100644 --- a/src/domain.c +++ b/src/domain.c @@ -367,6 +367,30 @@ virtDBusDomainDestroy(GVariant *inArgs, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusDomainDetachDevice(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virDomain) domain = NULL; + const gchar *xml; + guint flags; + + g_variant_get(inArgs, "(&su)", &xml, &flags); + + domain = virtDBusDomainGetVirDomain(connect, objectPath, error); + if (!domain) + return; + + if (virDomainDetachDeviceFlags(domain, xml, flags) == -1) + return virtDBusUtilSetLastVirtError(error); +} + G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainStatsRecordPtr, virDomainStatsRecordListFree); static void @@ -643,6 +667,7 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = { { "AttachDevice", virtDBusDomainAttachDevice }, { "Create", virtDBusDomainCreate }, { "Destroy", virtDBusDomainDestroy }, + { "DetachDevice", virtDBusDomainDetachDevice }, { "GetStats", virtDBusDomainGetStats }, { "GetVcpus", virtDBusDomainGetVcpus }, { "GetXMLDesc", virtDBusDomainGetXMLDesc }, -- 2.15.0
participants (1)
-
Katerina Koukiou