[dbus PATCH v2 06/17] Implement Name property for StorageVol Interface

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

 



Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx>
Reviewed-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 data/org.libvirt.StorageVol.xml |  5 +++++
 src/storagevol.c                | 44 +++++++++++++++++++++++++++++++++++++++++
 tests/test_storage.py           | 11 +++++++++++
 3 files changed, 60 insertions(+)

diff --git a/data/org.libvirt.StorageVol.xml b/data/org.libvirt.StorageVol.xml
index c72c847..3110b4f 100644
--- a/data/org.libvirt.StorageVol.xml
+++ b/data/org.libvirt.StorageVol.xml
@@ -3,5 +3,10 @@
 
 <node name="/org/libvirt/storagevol">
   <interface name="org.libvirt.StorageVol">
+    <property name="Name" type="s" access="read">
+      <annotation name="org.gtk.GDBus.DocString"
+          value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetName"/>
+      <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/>
+    </property>
   </interface>
 </node>
diff --git a/src/storagevol.c b/src/storagevol.c
index 0097a7f..12ebef1 100644
--- a/src/storagevol.c
+++ b/src/storagevol.c
@@ -3,7 +3,51 @@
 
 #include <libvirt/libvirt.h>
 
+static virStorageVolPtr
+virtDBusStorageVolGetVirStorageVol(virtDBusConnect *connect,
+                                   const gchar *objectPath,
+                                   GError **error)
+{
+    virStorageVolPtr storageVol;
+
+    if (virtDBusConnectOpen(connect, error) < 0)
+        return NULL;
+
+    storageVol = virtDBusUtilVirStorageVolFromBusPath(connect->connection,
+                                                      objectPath,
+                                                      connect->storageVolPath);
+    if (!storageVol) {
+        virtDBusUtilSetLastVirtError(error);
+        return NULL;
+    }
+
+    return storageVol;
+}
+
+static void
+virtDBusStorageVolGetName(const gchar *objectPath,
+                          gpointer userData,
+                          GVariant **value,
+                          GError **error)
+{
+    virtDBusConnect *connect = userData;
+    g_autoptr(virStorageVol) storageVol = NULL;
+    const gchar *name;
+
+    storageVol = virtDBusStorageVolGetVirStorageVol(connect, objectPath,
+                                                    error);
+    if (!storageVol)
+        return;
+
+    name = virStorageVolGetName(storageVol);
+    if (!name)
+        return virtDBusUtilSetLastVirtError(error);
+
+    *value = g_variant_new("s", name);
+}
+
 static virtDBusGDBusPropertyTable virtDBusStorageVolPropertyTable[] = {
+    { "Name", virtDBusStorageVolGetName, NULL },
     { 0 }
 };
 
diff --git a/tests/test_storage.py b/tests/test_storage.py
index 2aefd74..c93b800 100755
--- a/tests/test_storage.py
+++ b/tests/test_storage.py
@@ -2,6 +2,7 @@
 
 import dbus
 import libvirttest
+import pytest
 
 class TestStoragePool(libvirttest.BaseTestClass):
     def test_storage_pool_autostart(self):
@@ -130,5 +131,15 @@ class TestStoragePool(libvirttest.BaseTestClass):
         assert isinstance(storage_volume_create, dbus.ObjectPath)
 
 
+@pytest.mark.usefixtures('storage_volume_create')
+class TestStorageVolume(libvirttest.BaseTestClass):
+    def test_storage_vol_properties_type(self):
+        _, obj = self.get_test_storage_volume()
+
+        props = obj.GetAll('org.libvirt.StorageVol',
+                           dbus_interface=dbus.PROPERTIES_IFACE)
+        assert isinstance(props['Name'], dbus.String)
+
+
 if __name__ == '__main__':
     libvirttest.run()
-- 
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