[Kimchi-devel] [PATCH] [Kimchi] Replace backing image by clone when using template based on existing img

Jose Ricardo Ziviani joserz at linux.vnet.ibm.com
Sat Apr 9 00:52:33 UTC 2016


 - This commit replaces the current backing image to a complete clone
   when using a template based on an existing template.

Signed-off-by: Jose Ricardo Ziviani <joserz at linux.vnet.ibm.com>
---
 model/templates.py | 17 ++++++++++++++++-
 vmtemplate.py      |  8 --------
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/model/templates.py b/model/templates.py
index 1e6ad30..87173d1 100644
--- a/model/templates.py
+++ b/model/templates.py
@@ -361,7 +361,22 @@ class LibvirtVMTemplate(VMTemplate):
             for v in vol_list:
                 pool = self._get_storage_pool(v['pool'])
                 # outgoing text to libvirt, encode('utf-8')
-                pool.createXML(v['xml'].encode('utf-8'), 0)
+                if 'base' in v and 'path' in v['base']:
+                    conn = self.conn.get()
+                    try:
+                        volume_base = conn.storageVolLookupByPath(
+                            v['base']['path'])
+
+                    except libvirt.libvirtError as e:
+                        pool.createXML(v['xml'].encode('utf-8'), 0)
+                        continue
+
+                    pool.createXMLFrom(v['xml'].encode('utf-8'),
+                                       volume_base,
+                                       0)
+                else:
+                    pool.createXML(v['xml'].encode('utf-8'), 0)
+
         except libvirt.libvirtError as e:
             raise OperationFailed("KCHVMSTOR0008E", {'error': e.message})
         return vol_list
diff --git a/vmtemplate.py b/vmtemplate.py
index a223beb..4ce5d19 100644
--- a/vmtemplate.py
+++ b/vmtemplate.py
@@ -264,14 +264,6 @@ class VMTemplate(object):
             v_tree.append(E.capacity(str(info['capacity']), unit='G'))
 
             target_fmt = info['format']
-            if 'base' in d:
-                # target must be qcow2 in order to use a backing file
-                target_fmt = 'qcow2'
-
-                v_tree.append(E.backingStore(
-                    E.path(info['base']['path']),
-                    E.format(type=info['base']['format'])))
-
             target = E.target(
                 E.format(type=target_fmt), E.path(info['path']))
             v_tree.append(target)
-- 
1.9.1




More information about the Kimchi-devel mailing list