[Kimchi-devel] [PATCH] [Kimchi 2/4] Add support to create guests to netboot.

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


From: Paulo Vital <pvital at 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 at linux.vnet.ibm.com>
---
 vmtemplate.py         | 24 +++++++++++++++---------
 xmlutils/bootorder.py | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 9 deletions(-)
 create mode 100644 xmlutils/bootorder.py

diff --git a/vmtemplate.py b/vmtemplate.py
index 3e4418f..0611a07 100644
--- a/vmtemplate.py
+++ b/vmtemplate.py
@@ -33,6 +33,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
@@ -174,7 +175,7 @@ class VMTemplate(object):
 
     def _get_cdrom_xml(self, libvirt_stream_protocols):
         if 'cdrom' not in self.info:
-            return ''
+            return None
 
         params = {}
         params['type'] = 'cdrom'
@@ -354,12 +355,18 @@ class VMTemplate(object):
         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
+        # Add information of CD-ROM device only if template have info about it.
+        if cdrom_xml is not None:
+            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
+
+        # Set the boot order of VM
+        # TODO: need modify this when boot order edition feature came upstream.
+        params['boot_order'] = get_bootorder_xml()
 
         # Setting maximum number of slots to avoid errors when hotplug memory
         # Number of slots are the numbers of chunks of 1GB that fit inside
@@ -413,8 +420,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..28457e7
--- /dev/null
+++ b/xmlutils/bootorder.py
@@ -0,0 +1,39 @@
+#
+# 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(boot_order=['hd', 'cdrom', 'network']):
+    """
+    Returns the XML for boot order. The default return includes the following:
+
+    <boot dev='hd'/>
+    <boot dev='cdrom'/>
+    <boot dev='network'/>
+
+    To a different boot order, specify the order by a list as argument.
+    """
+    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.5




More information about the Kimchi-devel mailing list