[Kimchi-devel] [PATCH 5/7] Change VMTemplate._get_disks_xml() to use the common get_disk_xml()

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


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

diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
index 915f826..45f49c7 100644
--- a/src/kimchi/vmtemplate.py
+++ b/src/kimchi/vmtemplate.py
@@ -153,24 +153,22 @@ class VMTemplate(object):
         return xml
 
     def _get_disks_xml(self, vm_uuid):
-        storage_path = self._get_storage_path()
         ret = ""
+        storage_path = self._get_storage_path()
+        storage_type = self._get_storage_type()
+
         for i, disk in enumerate(self.info['disks']):
-            index = disk.get('index', i)
-            volume = "%s-%s.img" % (vm_uuid, index)
-            src = os.path.join(storage_path, volume)
-            dev = "%s%s" % (self._bus_to_dev[self.info['disk_bus']],
-                            string.lowercase[index])
-            fmt = 'raw' if self._get_storage_type() in ['logical'] else 'qcow2'
-            params = {'src': src, 'dev': dev, 'bus': self.info['disk_bus'],
-                      'type': fmt}
-            ret += """
-            <disk type='file' device='disk'>
-              <driver name='qemu' type='%(type)s' cache='none'/>
-              <source file='%(src)s' />
-              <target dev='%(dev)s' bus='%(bus)s' />
-            </disk>
-            """ % params
+            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]
+
         return ret
 
     def _get_graphics_xml(self, params):
-- 
1.9.3




More information about the Kimchi-devel mailing list