[Kimchi-devel] [PATCH 6/7] Change VMTemplate._get_disks_xml() to handle all type of disks

Aline Manera alinefm at linux.vnet.ibm.com
Fri Oct 31 17:22:25 UTC 2014


Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
 src/kimchi/vmtemplate.py | 53 ++++++++++++++++++++++++++----------------------
 1 file changed, 29 insertions(+), 24 deletions(-)

diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
index 45f49c7..7f7a907 100644
--- a/src/kimchi/vmtemplate.py
+++ b/src/kimchi/vmtemplate.py
@@ -153,23 +153,37 @@ class VMTemplate(object):
         return xml
 
     def _get_disks_xml(self, vm_uuid):
-        ret = ""
-        storage_path = self._get_storage_path()
+        # Current implementation just allows to create disk in one single
+        # storage pool, so we cannot mix the types (scsi volumes vs img file)
         storage_type = self._get_storage_type()
+        storage_path = self._get_storage_path()
 
-        for i, disk in enumerate(self.info['disks']):
-            params = {}
-            params['type'] = 'disk'
-            params['disk'] = 'file'
-            params['index'] = disk.get('index', i)
-            params['bus'] = self.info['disk_bus']
-            volume = "%s-%s.img" % (vm_uuid, params['index'])
-            params['path'] = os.path.join(storage_path, volume)
-            params['format'] = 'raw' if storage_type in ['logical'] \
-                               else 'qcow2'
-            ret += get_disk_xml(params)[1]
+        base_disk_params = {'type': 'disk', 'disk': 'file',
+                            'bus': self.info['disk_bus'], 'format': 'qcow2'}
+        logical_disk_params = {'format': 'raw'}
+        iscsi_disk_params = {'disk': 'block', 'format': 'raw'}
 
-        return ret
+        scsi_disk = 'volume' if self.fc_host_support else 'block'
+        scsi_disk_params = {'disk': scsi_disk, 'type': 'lun',
+                            'format': 'raw', 'bus': 'scsi'}
+
+        disks_xml = ''
+        pool_name = pool_name_from_uri(self.info['storagepool'])
+        for index, disk in enumerate(self.info['disks']):
+            params = dict(base_disk_params)
+            params.update(locals().get('%s_disk_params' % storage_type, {}))
+            params['index'] = index
+
+            volume = disk.get('volume')
+            if volume is not None:
+                params['path'] = self._get_volume_path(pool_name, volume)
+            else:
+                volume = "%s-%s.img" % (vm_uuid, params['index'])
+                params['path'] = os.path.join(storage_path, volume)
+
+            disks_xml += get_disk_xml(params)[1]
+
+        return disks_xml
 
     def _get_graphics_xml(self, params):
         graphics_xml = """
@@ -334,16 +348,7 @@ class VMTemplate(object):
         graphics = kwargs.get('graphics')
         params['graphics'] = self._get_graphics_xml(graphics)
         params['cpu_info'] = self._get_cpu_xml()
-
-        # Current implementation just allows to create disk in one single
-        # storage pool, so we cannot mix the types (scsi volumes vs img file)
-        storage_type = self._get_storage_type()
-        if storage_type == "iscsi":
-            params['disks'] = self._get_iscsi_disks_xml()
-        elif storage_type == "scsi":
-            params['disks'] = self._get_scsi_disks_xml()
-        else:
-            params['disks'] = self._get_disks_xml(vm_uuid)
+        params['disks'] = self._get_disks_xml(vm_uuid)
 
         qemu_stream_dns = kwargs.get('qemu_stream_dns', False)
         libvirt_stream_protocols = kwargs.get('libvirt_stream_protocols', [])
-- 
1.9.3




More information about the Kimchi-devel mailing list