[Kimchi-devel] [PATCH] [Kimchi 1/4] Add support to create netboot templates.

pvital at linux.vnet.ibm.com pvital at linux.vnet.ibm.com
Tue Apr 26 18:30:41 UTC 2016


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

Changed API.json and model to accept 'netboot' as source media parameter while
creating a new template.

Now, when creating a new template and specifying 'netboot' as source media
parameter, it is assumed the template will use netboot process - 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>
---
 API.json           | 18 +++++++++++++++---
 model/templates.py | 14 +++++++++++++-
 vmtemplate.py      |  4 ++++
 3 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/API.json b/API.json
index 380ed19..d452270 100644
--- a/API.json
+++ b/API.json
@@ -505,9 +505,21 @@
                 },
                 "memory": { "$ref": "#/kimchitype/memory" },
                 "source_media": {
-                    "description": "Path for installation media (ISO, disk, remote ISO)",
-                    "type" : "string",
-                    "pattern" : "^((/)|(http)[s]?:|[t]?(ftp)[s]?:)+.*$",
+                    "type" : "object",
+                    "properties" : {
+                        "type": {
+                            "description": "Type of source media: disk or netboot",
+                            "type": "string",
+                            "pattern": "^disk|netboot$",
+                            "required": true
+                        },
+                        "path": {
+                            "description": "Path for installation media (ISO, disk, remote ISO)",
+                            "type": "string",
+                            "pattern" : "^((/)|(http)[s]?:|[t]?(ftp)[s]?:)+.*$"
+                        }
+                    },
+                    "additionalProperties": false,
                     "required": true
                 },
                 "disks": {
diff --git a/model/templates.py b/model/templates.py
index 431cae0..90b6603 100644
--- a/model/templates.py
+++ b/model/templates.py
@@ -63,9 +63,21 @@ class TemplatesModel(object):
                                                         'template': name})
 
         # get source_media
-        path = params.pop("source_media")
+        source_media = params.get("source_media", None)
+
+        if source_media['type'] == 'netboot':
+            params['os_distro'] = 'unknown'
+            params['os_version'] = 'unknown'
+            return self.save_template(params)
+        else:
+            # Get path of source media if it's based on disk type.
+            path = source_media.get('path', None)
+
+        if path is None:
+            raise InvalidParameter("KCHTMPL0016E")
 
         # not local image: set as remote ISO
+        path = path.encode('utf-8')
         if urlparse.urlparse(path).scheme in ["http", "https", "tftp", "ftp",
                                               "ftps"]:
             params["cdrom"] = path
diff --git a/vmtemplate.py b/vmtemplate.py
index a223beb..3e4418f 100644
--- a/vmtemplate.py
+++ b/vmtemplate.py
@@ -123,6 +123,10 @@ class VMTemplate(object):
     def _get_os_info(self, args, scan):
         distro = version = 'unknown'
 
+        if 'source_media' in args.keys():
+            if args['source_media']['type'] == 'netboot':
+                return distro, version
+
         # Identify the cdrom if present
         iso = args.get('cdrom', '')
         if len(iso) > 0:
-- 
2.5.5




More information about the Kimchi-devel mailing list