[virt-tools-list] [virt-manager PATCH 2/6] virtinst.storage: improve detection of disk type

Pavel Hrdina phrdina at redhat.com
Mon Mar 6 08:28:48 UTC 2017


Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 virtinst/diskbackend.py | 11 ++++++++++-
 virtinst/storage.py     | 23 ++++++++++++++---------
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/virtinst/diskbackend.py b/virtinst/diskbackend.py
index fb8ae7bb..f70f5b21 100644
--- a/virtinst/diskbackend.py
+++ b/virtinst/diskbackend.py
@@ -190,7 +190,7 @@ def path_is_url(path):
     return bool(re.match("[a-zA-Z]+(\+[a-zA-Z]+)?://.*", path))
 
 
-def _get_dev_type(path, vol_xml, vol_object, remote):
+def _get_dev_type(path, vol_xml, vol_object, pool_xml, remote):
     """
     Try to get device type for volume.
     """
@@ -214,6 +214,13 @@ def _get_dev_type(path, vol_xml, vol_object, remote):
         elif t == StorageVolume.TYPE_NETWORK:
             return "network"
 
+    if pool_xml:
+        t = pool_xml.get_disk_type()
+        if t == StorageVolume.TYPE_BLOCK:
+            return "block"
+        elif t == StorageVolume.TYPE_NETWORK:
+            return "network"
+
     if path:
         if path_is_url(path):
             return "network"
@@ -321,6 +328,7 @@ class _StorageCreator(_StorageBase):
     def get_dev_type(self):
         if not self._dev_type:
             self._dev_type = _get_dev_type(self._path, self._vol_install, None,
+                                           self.get_parent_pool_xml(),
                                            self._conn.is_remote())
         return self._dev_type
 
@@ -588,6 +596,7 @@ class StorageBackend(_StorageBase):
             if self._vol_object:
                 vol_xml = self.get_vol_xml()
             self._dev_type = _get_dev_type(self._path, vol_xml, self._vol_object,
+                                           self.get_parent_pool_xml(),
                                            self._conn.is_remote())
         return self._dev_type
 
diff --git a/virtinst/storage.py b/virtinst/storage.py
index 8f3f3ae8..cd74467a 100644
--- a/virtinst/storage.py
+++ b/virtinst/storage.py
@@ -477,6 +477,19 @@ class StoragePool(_StorageObject):
             StoragePool.TYPE_RBD, StoragePool.TYPE_SHEEPDOG,
             StoragePool.TYPE_ZFS]
 
+    def get_disk_type(self):
+        if (self.type == StoragePool.TYPE_DISK or
+            self.type == StoragePool.TYPE_LOGICAL or
+            self.type == StoragePool.TYPE_SCSI or
+            self.type == StoragePool.TYPE_MPATH or
+            self.type == StoragePool.TYPE_ZFS):
+            return StorageVolume.TYPE_BLOCK
+        if (self.type == StoragePool.TYPE_GLUSTER or
+            self.type == StoragePool.TYPE_RBD or
+            self.type == StoragePool.TYPE_ISCSI or
+            self.type == StoragePool.TYPE_SHEEPDOG):
+            return StorageVolume.TYPE_NETWORK
+        return StorageVolume.TYPE_FILE
 
     ##################
     # Build routines #
@@ -701,15 +714,7 @@ class StorageVolume(_StorageObject):
                 return self.TYPE_DIR
             elif self.type == "network":
                 return self.TYPE_NETWORK
-        if (self._pool_xml.type == StoragePool.TYPE_DISK or
-            self._pool_xml.type == StoragePool.TYPE_LOGICAL or
-            self._pool_xml.type == StoragePool.TYPE_ZFS):
-            return self.TYPE_BLOCK
-        if (self._pool_xml.type == StoragePool.TYPE_GLUSTER or
-            self._pool_xml.type == StoragePool.TYPE_RBD or
-            self._pool_xml.type == StoragePool.TYPE_SHEEPDOG):
-            return self.TYPE_NETWORK
-        return self.TYPE_FILE
+        return self._pool_xml.get_disk_type()
     file_type = property(_get_vol_type)
 
 
-- 
2.12.0




More information about the virt-tools-list mailing list