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

Ramon Medeiros ramonn at linux.vnet.ibm.com
Tue Apr 26 20:48:54 UTC 2016



On 04/26/2016 04:47 PM, Paulo Ricardo Paz Vital wrote:
> On Apr 26 04:32PM, Ramon Medeiros wrote:
>>
>> On 04/26/2016 03:30 PM, pvital at linux.vnet.ibm.com wrote:
>>> 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():
>> how can source_media be present here? We used .pop on model/templates
> I changed to .get to keep the parameters persistent through the code flow.
ok. Don't forget to remove the source_media before storing the template 
to objectstore. We don't want to save this info at template
>
>>> +            if args['source_media']['type'] == 'netboot':
>>> +                return distro, version
>>> +
>>>           # Identify the cdrom if present
>>>           iso = args.get('cdrom', '')
>>>           if len(iso) > 0:
>> --
>>
>> Ramon Nunes Medeiros
>> Kimchi Developer
>> Linux Technology Center Brazil
>> IBM Systems & Technology Group
>> Phone : +55 19 2132 7878
>> ramonn at br.ibm.com
>>
> --
> Paulo Ricardo Paz Vital
> Linux Technology Center, IBM Systems
> http://www.ibm.com/linux/ltc/
>
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>

-- 

Ramon Nunes Medeiros
Kimchi Developer
Linux Technology Center Brazil
IBM Systems & Technology Group
Phone : +55 19 2132 7878
ramonn at br.ibm.com




More information about the Kimchi-devel mailing list