[Kimchi-devel] [PATCHv6 5/7] Create volume based on backing store image

lvroyce at linux.vnet.ibm.com lvroyce at linux.vnet.ibm.com
Wed Aug 6 09:03:46 UTC 2014


From: Royce Lv <lvroyce at linux.vnet.ibm.com>

Creating volume base on backing store so that we can create
vm from this cow volume. Also change volume xml generation method
to lxml.

Signed-off-by: Royce Lv <lvroyce at linux.vnet.ibm.com>
---
 src/kimchi/i18n.py       |  1 +
 src/kimchi/model/vms.py  |  1 +
 src/kimchi/vmtemplate.py | 32 +++++++++++++++++++-------------
 3 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/src/kimchi/i18n.py b/src/kimchi/i18n.py
index 9e79ee2..0e3b978 100644
--- a/src/kimchi/i18n.py
+++ b/src/kimchi/i18n.py
@@ -129,6 +129,7 @@ messages = {
     "KCHTMPL0021E": _("Unable to delete template due error: %(err)s"),
     "KCHTMPL0022E": _("Disk size must be greater than 1GB."),
     "KCHTMPL0023E": _("Template base image must be a valid local image file"),
+    "KCHTMPL0024E": _("Cannot identify base image %(path)s format"),
 
     "KCHPOOL0001E": _("Storage pool %(name)s already exists"),
     "KCHPOOL0002E": _("Storage pool %(name)s does not exist"),
diff --git a/src/kimchi/model/vms.py b/src/kimchi/model/vms.py
index a0e69b2..95abe68 100644
--- a/src/kimchi/model/vms.py
+++ b/src/kimchi/model/vms.py
@@ -204,6 +204,7 @@ class VMsModel(object):
         # the user from UI or manually.
         vol_list = []
         if t._get_storage_type() in ["iscsi", "scsi"]:
+        # FIXME: iscsi and scsi storage work with base image needs to be fixed.
             vol_list = []
         else:
             vol_list = t.fork_vm_storage(vm_uuid)
diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
index 09bed6a..47982ad 100644
--- a/src/kimchi/vmtemplate.py
+++ b/src/kimchi/vmtemplate.py
@@ -287,22 +287,28 @@ drive=drive-%(bus)s0-1-0,id=%(bus)s0-1-0'/>
 
             info = {'name': volume,
                     'capacity': d['size'],
-                    'type': 'disk',
                     'format': fmt,
                     'path': '%s/%s' % (storage_path, volume)}
-
             info['allocation'] = 0 if fmt == 'qcow2' else info['capacity']
-            info['xml'] = """
-            <volume>
-              <name>%(name)s</name>
-              <allocation unit="G">%(allocation)s</allocation>
-              <capacity unit="G">%(capacity)s</capacity>
-              <target>
-                <format type='%(format)s'/>
-                <path>%(path)s</path>
-              </target>
-            </volume>
-            """ % info
+
+            if 'base' in d:
+                info['base'] = dict()
+                base_fmt = probe_img_info(d['base'])['format']
+                if base_fmt is None:
+                    raise InvalidParameter("KCHTMPL0024E", {'path': d['base']})
+                info['base']['path'] = d['base']
+                info['base']['format'] = base_fmt
+
+            v_tree = E.volume(E.name(info['name']))
+            v_tree.append(E.allocation(str(info['allocation']), unit='G'))
+            v_tree.append(E.capacity(str(info['capacity']), unit='G'))
+            target = E.target(
+                E.format(type=info['format']), E.path(info['path']))
+            if 'base' in d:
+                v_tree.append(E.backingStore(
+                    E.path(info['base']['path']), E.format(type=info['base']['format'])))
+            v_tree.append(target)
+            info['xml'] = etree.tostring(v_tree)
             ret.append(info)
         return ret
 
-- 
1.8.3.2




More information about the Kimchi-devel mailing list