
From: Paulo Vital <pvital@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@linux.vnet.ibm.com> --- API.json | 18 +++++++++++++++--- model/templates.py | 16 ++++++++++++++-- vmtemplate.py | 15 ++++++++++----- 3 files changed, 39 insertions(+), 10 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..131f86b 100644 --- a/model/templates.py +++ b/model/templates.py @@ -63,9 +63,20 @@ class TemplatesModel(object): 'template': name}) # get source_media - path = params.pop("source_media") + source_media = params.pop("source_media") + + if source_media['type'] == 'netboot': + params['netboot'] = True + 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 @@ -301,7 +312,8 @@ def validate_memory(memory): class LibvirtVMTemplate(VMTemplate): def __init__(self, args, scan=False, conn=None): self.conn = conn - VMTemplate.__init__(self, args, scan) + netboot = True if 'netboot' in args.keys() else False + VMTemplate.__init__(self, args, scan, netboot) self.set_cpu_info() def _validate_memory(self): diff --git a/vmtemplate.py b/vmtemplate.py index a223beb..c4b9d8e 100644 --- a/vmtemplate.py +++ b/vmtemplate.py @@ -42,7 +42,7 @@ from wok.plugins.kimchi.xmlutils.serial import get_serial_xml class VMTemplate(object): - def __init__(self, args, scan=False): + def __init__(self, args, scan=False, netboot=False): """ Construct a VM Template from a widely variable amount of information. The only required parameter is a name for the VMTemplate. If present, @@ -50,15 +50,20 @@ class VMTemplate(object): settings. Any parameters provided by the caller will override the defaults. If scan is True and a cdrom or a base img is present, the operating system will be detected by probing the installation media. + If netboot is True, no cdrom or base img will be used to boot the VM. """ self.info = {} self.fc_host_support = args.get('fc_host_support') # Fetch defaults based on the os distro and version - try: - distro, version = self._get_os_info(args, scan) - except ImageFormatError as e: - raise OperationFailed('KCHTMPL0020E', {'err': e.message}) + if netboot: + distro = version = 'unknown' + else: + try: + distro, version = self._get_os_info(args, scan) + except ImageFormatError as e: + raise OperationFailed('KCHTMPL0020E', {'err': e.message}) + os_distro = args.get('os_distro', distro) os_version = args.get('os_version', version) entry = osinfo.lookup(os_distro, os_version) -- 2.5.5