[dbus PATCH v2 17/17] Implement StorageVolCreateXMLFrom method for StoragePool 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.StoragePool.xml |  9 +++++++++
 src/storagepool.c                | 41 ++++++++++++++++++++++++++++++++++++++++
 tests/test_storage.py            | 22 +++++++++++++++++++++
 3 files changed, 72 insertions(+)

diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml
index 161ade5..0a324e6 100644
--- a/data/org.libvirt.StoragePool.xml
+++ b/data/org.libvirt.StoragePool.xml
@@ -75,6 +75,15 @@
       <arg name="flags" type="u" direction="in"/>
       <arg name="storageVol" type="o" direction="out"/>
     </method>
+    <method name="StorageVolCreateXMLFrom">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolCreateXMLFrom
+               Call with @key argument set to the key of the storage volume to be cloned."/>
+      <arg name="xml" type="s" direction="in"/>
+      <arg name="key" type="s" direction="in"/>
+      <arg name="flags" type="u" direction="in"/>
+      <arg name="storageVol" type="o" direction="out"/>
+    </method>
     <method name="StorageVolLookupByName">
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolLookupByName"/>
diff --git a/src/storagepool.c b/src/storagepool.c
index ee2862b..6eb6f27 100644
--- a/src/storagepool.c
+++ b/src/storagepool.c
@@ -400,6 +400,46 @@ virtDBusStoragePoolStorageVolCreateXML(GVariant *inArgs,
     *outArgs = g_variant_new("(o)", path);
 }
 
+static void
+virtDBusStoragePoolStorageVolCreateXMLFrom(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(virStoragePool) storagePool = NULL;
+    g_autoptr(virStorageVol) storageVol = NULL;
+    g_autoptr(virStorageVol) storageVolOld = NULL;
+    const gchar *key;
+    const gchar *xml;
+    guint flags;
+    g_autofree gchar *path = NULL;
+
+    g_variant_get(inArgs, "(&s&su)", &xml, &key, &flags);
+
+    storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath,
+                                                       error);
+    if (!storagePool)
+        return;
+
+    storageVolOld = virStorageVolLookupByKey(connect->connection, key);
+    if (!storageVolOld)
+        return virtDBusUtilSetLastVirtError(error);
+
+    storageVol = virStorageVolCreateXMLFrom(storagePool, xml, storageVolOld,
+                                            flags);
+    if (!storageVol)
+        return virtDBusUtilSetLastVirtError(error);
+
+    path = virtDBusUtilBusPathForVirStorageVol(storageVol,
+                                               connect->storageVolPath);
+
+    *outArgs = g_variant_new("(o)", path);
+}
+
 static void
 virtDBusStoragePoolStorageVolLookupByName(GVariant *inArgs,
                                           GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -474,6 +514,7 @@ static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = {
     { "ListStorageVolumes", virtDBusStoragePoolListStorageVolumes },
     { "Refresh", virtDBusStoragePoolRefresh },
     { "StorageVolCreateXML", virtDBusStoragePoolStorageVolCreateXML },
+    { "StorageVolCreateXMLFrom", virtDBusStoragePoolStorageVolCreateXMLFrom },
     { "StorageVolLookupByName", virtDBusStoragePoolStorageVolLookupByName },
     { "Undefine", virtDBusStoragePoolUndefine },
     { 0 }
diff --git a/tests/test_storage.py b/tests/test_storage.py
index ae06007..63ecf91 100755
--- a/tests/test_storage.py
+++ b/tests/test_storage.py
@@ -130,6 +130,28 @@ class TestStoragePool(libvirttest.BaseTestClass):
     def test_storage_pool_volume_create(self, storage_volume_create):
         assert isinstance(storage_volume_create, dbus.ObjectPath)
 
+    @pytest.mark.usefixtures('storage_volume_create')
+    def test_storage_pool_volume_create_xml_from(self):
+        minimal_storage_vol_clone_xml = '''
+        <volume>
+          <name>clone.img</name>
+          <capacity unit="G">1</capacity>
+        </volume>
+        '''
+        _, test_storage_vol = self.get_test_storage_volume()
+        props = test_storage_vol.GetAll('org.libvirt.StorageVol',
+                                        dbus_interface=dbus.PROPERTIES_IFACE)
+        test_storage_vol_key = str(props['Key'])
+
+        _, test_storage_pool = self.get_test_storage_pool()
+        storage_pool_iface = dbus.Interface(test_storage_pool,
+                                            'org.libvirt.StoragePool')
+
+        new_vol_path = storage_pool_iface.StorageVolCreateXMLFrom(minimal_storage_vol_clone_xml,
+                                                                  test_storage_vol_key,
+                                                                  0)
+        assert isinstance(new_vol_path, dbus.ObjectPath)
+
 
 @pytest.mark.usefixtures('storage_volume_create')
 class TestStorageVolume(libvirttest.BaseTestClass):
-- 
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