[Kimchi-devel] [PATCH 2/4] add a new method to get iso info for VMTemplate class

shaohef at linux.vnet.ibm.com shaohef at linux.vnet.ibm.com
Wed Feb 19 14:23:10 UTC 2014


From: ShaoHe Feng <shaohef at linux.vnet.ibm.com>

move the related code about get iso info to a new function.
Then template integrity can make use of it.

Signed-off-by: ShaoHe Feng <shaohef at linux.vnet.ibm.com>
---
 src/kimchi/vmtemplate.py | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/kimchi/vmtemplate.py b/src/kimchi/vmtemplate.py
index 5767a13..a11ddd0 100644
--- a/src/kimchi/vmtemplate.py
+++ b/src/kimchi/vmtemplate.py
@@ -56,20 +56,10 @@ class VMTemplate(object):
         iso = args.get('cdrom', '')
 
         if scan and len(iso) > 0:
-
-            iso_prefixes = ['/', 'http', 'https', 'ftp', 'ftps', 'tftp']
-            if len(filter(iso.startswith, iso_prefixes)) == 0:
-                raise InvalidParameter("KCHTMPL0006E", {'param': iso})
-
+            iso_distro, iso_version = self.get_iso_info(iso)
             if not iso.startswith('/'):
                 self.info.update({'iso_stream': True})
 
-            try:
-                iso_img = IsoImage(iso)
-                iso_distro, iso_version = iso_img.probe()
-            except IsoFormatError:
-                raise InvalidParameter("KCHISO0001E", {'filename': iso})
-
         # Fetch defaults based on the os distro and version
         os_distro = args.get('os_distro', iso_distro)
         os_version = args.get('os_version', iso_version)
@@ -84,6 +74,16 @@ class VMTemplate(object):
             args['graphics'] = graphics
         self.info.update(args)
 
+    def get_iso_info(self, iso):
+        iso_prefixes = ['/', 'http', 'https', 'ftp', 'ftps', 'tftp']
+        if len(filter(iso.startswith, iso_prefixes)) == 0:
+            raise InvalidParameter("KCHTMPL0006E", {'param': iso})
+        try:
+            iso_img = IsoImage(iso)
+            return iso_img.probe()
+        except IsoFormatError:
+            raise InvalidParameter("KCHISO0001E", {'filename': iso})
+
     def _get_cdrom_xml(self, libvirt_stream, qemu_stream_dns):
         bus = self.info['cdrom_bus']
         dev = "%s%s" % (self._bus_to_dev[bus],
-- 
1.8.4.2




More information about the Kimchi-devel mailing list