[Kimchi-devel] [PATCH] [Kimchi 1/3] Add support to create templates without ISO image.

pvital at linux.vnet.ibm.com pvital at linux.vnet.ibm.com
Tue Feb 16 21:40:16 UTC 2016


From: Paulo Vital <pvital at linux.vnet.ibm.com>

Changed API.json and model to accept empty parameters or missing the cdrom (ISO
image) parameter while creating a new template.

Now, when creating a new template and not specifying an ISO image it is assumed
the template will use netboot - PXE/DHCP/TFTP/(NFS/HTTP/FTP).

This is part of solution to Issue #372.

Signed-off-by: Paulo Vital <pvital at linux.vnet.ibm.com>
---
 model/templates.py | 35 ++++++++++++++++++++++-------------
 vmtemplate.py      |  2 +-
 2 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/model/templates.py b/model/templates.py
index 8a29e02..bbf5081 100644
--- a/model/templates.py
+++ b/model/templates.py
@@ -41,18 +41,24 @@ class TemplatesModel(object):
 
     def create(self, params):
         name = params.get('name', '').strip()
-        iso = params.get('cdrom')
-        # check search permission
-        if iso and iso.startswith('/') and os.path.exists(iso):
-            st_mode = os.stat(iso).st_mode
-            if stat.S_ISREG(st_mode) or stat.S_ISBLK(st_mode):
-                user = UserTests().probe_user()
-                run_setfacl_set_attr(iso, user=user)
-                ret, excp = probe_file_permission_as_user(iso, user)
-                if ret is False:
-                    raise InvalidParameter('KCHISO0008E',
-                                           {'filename': iso, 'user': user,
-                                            'err': excp})
+        iso = params.get('cdrom', '')
+
+        if not iso:
+            # set template to boot via network card (net boot)
+            params['cdrom'] = 'netboot'
+            params['os_distro'] = 'unknown'
+            params['os_version'] = 'unknown'
+        else:
+            # check search permission
+            if iso and iso.startswith('/') and os.path.exists(iso):
+                st_mode = os.stat(iso).st_mode
+                if stat.S_ISREG(st_mode) or stat.S_ISBLK(st_mode):
+                    user = UserTests().probe_user()
+                    run_setfacl_set_attr(iso, user=user)
+                    ret, excp = probe_file_permission_as_user(iso, user)
+                    if ret is False:
+                        raise InvalidParameter('KCHISO0008E', {'filename': iso,
+                                               'user': user, 'err': excp})
 
         conn = self.conn.get()
         for net_name in params.get(u'networks', []):
@@ -64,7 +70,10 @@ class TemplatesModel(object):
         # Creates the template class with necessary information
         # Checkings will be done while creating this class, so any exception
         # will be raised here
-        t = LibvirtVMTemplate(params, scan=True, conn=self.conn)
+        if params['cdrom'] == 'netboot':
+            t = LibvirtVMTemplate(params, conn=self.conn)
+        else:
+            t = LibvirtVMTemplate(params, scan=True, conn=self.conn)
 
         # Validate cpu info
         t.cpuinfo_validate()
diff --git a/vmtemplate.py b/vmtemplate.py
index ef17ff6..435bf42 100644
--- a/vmtemplate.py
+++ b/vmtemplate.py
@@ -501,7 +501,7 @@ class VMTemplate(object):
         # validate iso integrity
         # FIXME when we support multiples cdrom devices
         iso = self.info.get('cdrom')
-        if iso:
+        if iso and (iso != 'netboot'):
             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)):
-- 
2.5.0




More information about the Kimchi-devel mailing list