[libvirt] [dbus PATCH 01/22] Implement StoragePoolCreateXML method for Connect Interface

Katerina Koukiou kkoukiou at redhat.com
Thu May 10 17:25:53 UTC 2018


Signed-off-by: Katerina Koukiou <kkoukiou at redhat.com>
---
 data/org.libvirt.Connect.xml |  7 +++++++
 src/connect.c                | 31 +++++++++++++++++++++++++++++++
 tests/test_connect.py        | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+)

diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index 243ef35..2f88d42 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -251,6 +251,13 @@
       <arg name="usageID" type="s" direction="in"/>
       <arg name="secret" type="o" direction="out"/>
     </method>
+    <method name="StoragePoolCreateXML">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolCreateXML"/>
+      <arg name="xml" type="s" direction="in"/>
+      <arg name="flags" type="u" direction="in"/>
+      <arg name="storagePool" type="o" direction="out"/>
+    </method>
     <method name="StoragePoolLookupByName">
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolLookupByName"/>
diff --git a/src/connect.c b/src/connect.c
index 0b33bc5..a6163d2 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -1276,6 +1276,36 @@ virtDBusConnectSecretLookupByUsage(GVariant *inArgs,
     *outArgs = g_variant_new("(o)", path);
 }
 
+static void
+virtDBusConnectStoragePoolCreateXML(GVariant *inArgs,
+                                    GUnixFDList *inFDs G_GNUC_UNUSED,
+                                    const gchar *objectPath G_GNUC_UNUSED,
+                                    gpointer userData,
+                                    GVariant **outArgs,
+                                    GUnixFDList **outFDs G_GNUC_UNUSED,
+                                    GError **error)
+{
+    virtDBusConnect *connect = userData;
+    g_autoptr(virStoragePool) storagePool = NULL;
+    g_autofree gchar *path = NULL;
+    gchar *xml;
+    guint flags;
+
+    g_variant_get(inArgs, "(&su)", &xml, &flags);
+
+    if (!virtDBusConnectOpen(connect, error))
+        return;
+
+    storagePool = virStoragePoolCreateXML(connect->connection, xml, flags);
+    if (!storagePool)
+        return virtDBusUtilSetLastVirtError(error);
+
+    path = virtDBusUtilBusPathForVirStoragePool(storagePool,
+                                                connect->storagePoolPath);
+
+    *outArgs = g_variant_new("(o)", path);
+}
+
 static void
 virtDBusConnectStoragePoolLookupByName(GVariant *inArgs,
                                        GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -1379,6 +1409,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
     { "SecretDefineXML", virtDBusConnectSecretDefineXML },
     { "SecretLookupByUUID", virtDBusConnectSecretLookupByUUID },
     { "SecretLookupByUsage", virtDBusConnectSecretLookupByUsage },
+    { "StoragePoolCreateXML", virtDBusConnectStoragePoolCreateXML },
     { "StoragePoolLookupByName", virtDBusConnectStoragePoolLookupByName },
     { "StoragePoolLookupByUUID", virtDBusConnectStoragePoolLookupByUUID },
     { 0 }
diff --git a/tests/test_connect.py b/tests/test_connect.py
index 8104a30..6e28b81 100755
--- a/tests/test_connect.py
+++ b/tests/test_connect.py
@@ -30,6 +30,24 @@ class TestConnect(libvirttest.BaseTestClass):
     </network>
     '''
 
+    minimal_storage_pool_xml = '''
+    <pool type='dir'>
+      <name>foo</name>
+      <uuid>35bb2ad9-388a-cdfe-461a-b8907f6e53fe</uuid>
+      <capacity>107374182400</capacity>
+      <allocation>0</allocation>
+      <available>107374182400</available>
+      <target>
+        <path>/foo</path>
+        <permissions>
+          <mode>0700</mode>
+          <owner>10736</owner>
+          <group>10736</group>
+        </permissions>
+      </target>
+    </pool>
+    '''
+
     def test_connect_domain_create_xml(self):
         def domain_started(path, event, detail):
             if event != libvirttest.DomainEvent.STARTED:
@@ -190,6 +208,21 @@ class TestConnect(libvirttest.BaseTestClass):
         info = self.connect.NodeGetCPUMap(0)
         assert isinstance(info, dbus.Array)
 
+    def test_connect_storage_pool_create_xml(self):
+        def storage_pool_started(path, event, _detail):
+            if event != libvirttest.StoragePoolEvent.STARTED:
+                return
+            assert isinstance(path, dbus.ObjectPath)
+            self.loop.quit()
+
+        self.connect.connect_to_signal('StoragePoolEvent', storage_pool_started)
+
+        path = self.connect.StoragePoolCreateXML(
+            self.minimal_storage_pool_xml, 0)
+        assert isinstance(path, dbus.ObjectPath)
+
+        self.main_loop()
+
     @pytest.mark.parametrize("lookup_method_name,lookup_item", [
         ("StoragePoolLookupByName", 'Name'),
         ("StoragePoolLookupByUUID", 'UUID'),
-- 
2.15.0




More information about the libvir-list mailing list