[dbus PATCH 1/6] Implement Setter for Autostart property for Domain interface

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx>
---
 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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux