
From: Paulo Vital <pvital@linux.vnet.ibm.com> Add support to create guests without CD-ROM device information and setting the second boot order option as 'netboot'. This is part of solution to Issue #372. Signed-off-by: Paulo Vital <pvital@linux.vnet.ibm.com> --- vmtemplate.py | 27 +++++++++++++++++---------- xmlutils/bootorder.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 10 deletions(-) create mode 100644 xmlutils/bootorder.py diff --git a/vmtemplate.py b/vmtemplate.py index 435bf42..ce99627 100644 --- a/vmtemplate.py +++ b/vmtemplate.py @@ -34,6 +34,7 @@ from wok.plugins.kimchi import imageinfo from wok.plugins.kimchi import osinfo from wok.plugins.kimchi.isoinfo import IsoImage from wok.plugins.kimchi.utils import check_url_path, pool_name_from_uri +from wok.plugins.kimchi.xmlutils.bootorder import get_bootorder_xml from wok.plugins.kimchi.xmlutils.cpu import get_cpu_xml from wok.plugins.kimchi.xmlutils.disk import get_disk_xml from wok.plugins.kimchi.xmlutils.graphics import get_graphics_xml @@ -365,15 +366,22 @@ class VMTemplate(object): graphics.update(kwargs.get('graphics', {})) params['graphics'] = get_graphics_xml(graphics) - libvirt_stream_protocols = kwargs.get('libvirt_stream_protocols', []) - cdrom_xml = self._get_cdrom_xml(libvirt_stream_protocols) - - if not urlparse.urlparse(self.info.get('cdrom', "")).scheme in \ - libvirt_stream_protocols and \ - params.get('iso_stream', False): - params['qemu-stream-cmdline'] = cdrom_xml + # Add information of CD-ROM device only if not setup to netboot. + # Also, setup the correct boot order + if params['cdrom'] == 'netboot': + params['boot_order'] = get_bootorder_xml(network=True) else: - params['cdroms'] = cdrom_xml + libvirt_stream_protocols = kwargs.get('libvirt_stream_protocols', + []) + cdrom_xml = self._get_cdrom_xml(libvirt_stream_protocols) + + if (not urlparse.urlparse(self.info.get('cdrom', "")).scheme in + libvirt_stream_protocols and + params.get('iso_stream', False)): + params['qemu-stream-cmdline'] = cdrom_xml + else: + params['cdroms'] = cdrom_xml + params['boot_order'] = get_bootorder_xml() # max memory params['max_memory'] = self._get_max_memory(params['memory']) @@ -419,8 +427,7 @@ class VMTemplate(object): %(cpu_info_xml)s <os> <type arch='%(arch)s'>hvm</type> - <boot dev='hd'/> - <boot dev='cdrom'/> + %(boot_order)s </os> <features> <acpi/> diff --git a/xmlutils/bootorder.py b/xmlutils/bootorder.py new file mode 100644 index 0000000..269f052 --- /dev/null +++ b/xmlutils/bootorder.py @@ -0,0 +1,44 @@ +# +# Project Kimchi +# +# Copyright IBM, Corp. 2016 +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +import lxml.etree as ET +from lxml.builder import E + + +def get_bootorder_xml(network=False): + """ + <boot dev='hd'/> + <boot dev='cdrom'/> + + - For netboot configuration: + + <boot dev='hd'/> + <boot dev='cdrom'/> + <boot dev='network'/> + """ + boot_order = ['hd', 'cdrom'] + if network: + boot_order.append('network') + + boot_xml = '' + for device in boot_order: + boot = E.boot(dev=device) + boot_xml += ET.tostring(boot, encoding='utf-8', pretty_print=True) + + return boot_xml -- 2.5.0