[libvirt] [dbus PATCH 18/19] Implement setter for Autostart property for StoragePool Interface

Katerina Koukiou kkoukiou at redhat.com
Mon May 7 14:40:59 UTC 2018


Signed-off-by: Katerina Koukiou <kkoukiou at redhat.com>
---
 data/org.libvirt.StoragePool.xml |  5 +++--
 src/storagepool.c                | 24 +++++++++++++++++++++++-
 tests/test_storage.py            | 13 +++++++++++++
 3 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml
index 8ebab33..9d59818 100644
--- a/data/org.libvirt.StoragePool.xml
+++ b/data/org.libvirt.StoragePool.xml
@@ -8,9 +8,10 @@
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolIsActive"/>
     </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-storage.html#virStoragePoolGetAutostart"/>
+          value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolGetAutostart
+                 https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolSetAutostart"/>
     </property>
     <property name="Name" type="s" access="read">
       <annotation name="org.gtk.GDBus.DocString"
diff --git a/src/storagepool.c b/src/storagepool.c
index aa0e280..a40db14 100644
--- a/src/storagepool.c
+++ b/src/storagepool.c
@@ -132,6 +132,27 @@ virtDBusStoragePoolGetUUID(const gchar *objectPath,
     *value = g_variant_new("s", uuid);
 }
 
+static void
+virtDBusStoragePoolSetAutostart(GVariant *value,
+                                const gchar *objectPath,
+                                gpointer userData,
+                                GError **error)
+{
+    virtDBusConnect *connect = userData;
+    g_autoptr(virStoragePool) storagePool = NULL;
+    gboolean autostart;
+
+    g_variant_get(value, "b", &autostart);
+
+    storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath,
+                                                       error);
+    if (!storagePool)
+        return;
+
+    if (virStoragePoolSetAutostart(storagePool, autostart) < 0)
+        virtDBusUtilSetLastVirtError(error);
+}
+
 static void
 virtDBusStoragePoolBuild(GVariant *inArgs,
                          GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -306,7 +327,8 @@ virtDBusStoragePoolRefresh(GVariant *inArgs,
 
 static virtDBusGDBusPropertyTable virtDBusStoragePoolPropertyTable[] = {
     { "Active", virtDBusStoragePoolGetActive, NULL },
-    { "Autostart", virtDBusStoragePoolGetAutostart, NULL },
+    { "Autostart", virtDBusStoragePoolGetAutostart,
+                   virtDBusStoragePoolSetAutostart },
     { "Name", virtDBusStoragePoolGetName, NULL },
     { "Persistent", virtDBusStoragePoolGetPersistent, NULL },
     { "UUID", virtDBusStoragePoolGetUUID, NULL },
diff --git a/tests/test_storage.py b/tests/test_storage.py
index b872c3d..2d87e08 100755
--- a/tests/test_storage.py
+++ b/tests/test_storage.py
@@ -4,6 +4,19 @@ import dbus
 import libvirttest
 
 class TestStoragePool(libvirttest.BaseTestClass):
+    def test_storage_pool_autostart(self):
+        _, test_storage_pool = self.test_storage_pool()
+        interface_obj = dbus.Interface(test_storage_pool,
+                                       'org.libvirt.StoragePool')
+        autostart_expected = True
+        interface_obj.Set('org.libvirt.StoragePool', 'Autostart',
+                          autostart_expected,
+                          dbus_interface=dbus.PROPERTIES_IFACE)
+        autostart_current = interface_obj.Get('org.libvirt.StoragePool',
+                                              'Autostart',
+                                              dbus_interface=dbus.PROPERTIES_IFACE)
+        assert autostart_current == dbus.Boolean(autostart_expected)
+
     def test_storage_pool_build(self):
         _, test_storage_pool = self.test_storage_pool()
         interface_obj = dbus.Interface(test_storage_pool,
-- 
2.15.0




More information about the libvir-list mailing list