[Kimchi-devel] [PATCH v2] [Kimchi] Replace backing image by clone when using template based on existing img
Aline Manera
alinefm at linux.vnet.ibm.com
Mon Apr 18 16:00:28 UTC 2016
On 04/15/2016 09:27 AM, Jose Ricardo Ziviani wrote:
> - 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 a02099c..9ae7f5e 100644
> --- a/model/templates.py
> +++ b/model/templates.py
> @@ -378,7 +378,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
> +
createXML() will only create a storage volume XML according to a file
information which mean the storage volume created will point to an empty
file, ie, it will not be a copy of the input image file.
I think, in addition to this createXML() you need to copy the file
content to this new storage volume path.
The test I did was:
1. Get a image file which has an installed OS (I used one from a guest I
have in my laptop).
2. Copy it to a directory which it is not a storage pool (I used ~/Desktop)
3. Give the right file permissions to allow libvirt accesses it.
4. Create a Template using this ~/Desktop path
5. Create a guest using this Template
6. Start the guest
Actual behavior with this patch:
7. Guest will not boot because of there is no bootable disk found
Excepted behavior:
7. Guest boots the OS installed in the image file.
Let me know if you have further questions about it.
> + 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)
More information about the Kimchi-devel
mailing list