[Kimchi-devel] [PATCH 2/3] issue #565: Allow a template's ISO to be a block device

Aline Manera alinefm at linux.vnet.ibm.com
Fri Mar 20 13:32:12 UTC 2015




Reviewed-by: Aline Manera <alinefm at linux.vnet.ibm.com>

On 18/03/2015 23:51, Crístian Viana wrote:
> The current template code checks whether an ISO path is a regular file
> (i.e. not a directory, not a char device, not a link). However, a block
> device may also be a valid ISO path because storage volumes belonging
> to logical pools are always block devices (e.g. /dev/mypool/myvol.iso),
> and they should also be used to create templates.
>
> Instead of allowing only regular files to be used as template ISOs,
> allow block devices as well.
>
> Fix issue #565 (Allow creating templates with device files).
>
> Signed-off-by: Crístian Viana <vianac at linux.vnet.ibm.com>
> ---
>   src/kimchi/isoinfo.py    |  7 +++++--
>   src/kimchi/vmtemplate.py | 10 ++++++++--
>   2 files changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/src/kimchi/isoinfo.py b/src/kimchi/isoinfo.py
> index b5a1769..badb002 100644
> --- a/src/kimchi/isoinfo.py
> +++ b/src/kimchi/isoinfo.py
> @@ -22,6 +22,7 @@ import glob
>   import platform
>   import os
>   import re
> +import stat
>   import struct
>   import sys
>   import urllib2
> @@ -151,8 +152,10 @@ class IsoImage(object):
>           self._scan()
>   
>       def _is_iso_remote(self):
> -        if os.path.isfile(self.path):
> -            return False
> +        if os.path.exists(self.path):
> +            st_mode = os.stat(self.path).st_mode
> +            if stat.S_ISREG(st_mode) or stat.S_ISBLK(st_mode):
> +                return False
>   
>           if check_url_path(self.path):
>               return True
> diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
> index ef41d0a..ec477dd 100644
> --- a/src/kimchi/vmtemplate.py
> +++ b/src/kimchi/vmtemplate.py
> @@ -19,6 +19,7 @@
>   
>   import os
>   import socket
> +import stat
>   import time
>   import urlparse
>   import uuid
> @@ -403,8 +404,13 @@ class VMTemplate(object):
>           # validate iso integrity
>           # FIXME when we support multiples cdrom devices
>           iso = self.info.get('cdrom')
> -        if iso and not (os.path.isfile(iso) or check_url_path(iso)):
> -            invalid['cdrom'] = [iso]
> +        if iso:
> +            if os.path.exists(iso):
> +                st_mode = os.stat(iso).st_mode
> +                if not (stat.S_ISREG(st_mode) or stat.S_ISBLK(st_mode)):
> +                    invalid['cdrom'] = [iso]
> +            elif not check_url_path(iso):
> +                invalid['cdrom'] = [iso]
>   
>           self.info['invalid'] = invalid
>   




More information about the Kimchi-devel mailing list