[Kimchi-devel] [PATCH v2] Add support for serial console

Ramon Medeiros ramonn at linux.vnet.ibm.com
Tue Nov 24 12:07:49 UTC 2015


Changes:

v2:
Add ppc rules to serial.py
Correct date on "Copyright"

Automatically create serial console device.

Signed-off-by: Ramon Medeiros <ramonn at linux.vnet.ibm.com>
---
 src/wok/plugins/kimchi/vmtemplate.py      | 13 ++------
 src/wok/plugins/kimchi/xmlutils/serial.py | 55 +++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 10 deletions(-)
 create mode 100644 src/wok/plugins/kimchi/xmlutils/serial.py

diff --git a/src/wok/plugins/kimchi/vmtemplate.py b/src/wok/plugins/kimchi/vmtemplate.py
index d653665..34bf38b 100644
--- a/src/wok/plugins/kimchi/vmtemplate.py
+++ b/src/wok/plugins/kimchi/vmtemplate.py
@@ -38,7 +38,7 @@ from wok.plugins.kimchi.xmlutils.disk import get_disk_xml
 from wok.plugins.kimchi.xmlutils.graphics import get_graphics_xml
 from wok.plugins.kimchi.xmlutils.interface import get_iface_xml
 from wok.plugins.kimchi.xmlutils.qemucmdline import get_qemucmdline_xml
-
+from wok.plugins.kimchi.xmlutils.serial import get_serial_xml
 
 class VMTemplate(object):
     def __init__(self, args, scan=False):
@@ -312,6 +312,7 @@ class VMTemplate(object):
         params['qemu-stream-cmdline'] = ''
         params['cpu_info'] = self._get_cpu_xml()
         params['disks'] = self._get_disks_xml(vm_uuid)
+        params['serial'] = get_serial_xml(params)
 
         graphics = dict(self.info['graphics'])
         graphics.update(kwargs.get('graphics', {}))
@@ -371,20 +372,12 @@ class VMTemplate(object):
             %(networks)s
             %(graphics)s
             %(input_output)s
+            %(serial)s
             <memballoon model='virtio' />
           </devices>
         </domain>
         """ % params
 
-        # Adding PPC console configuration
-        if params['arch'] in ['ppc', 'ppc64']:
-            ppc_console = """<memballoon model='virtio' />
-            <console type='pty'>
-              <target type='serial' port='1'/>
-              <address type='spapr-vio' reg='0x30001000'/>
-            </console>"""
-            xml = xml.replace("<memballoon model='virtio' />", ppc_console)
-
         return xml
 
     def validate(self):
diff --git a/src/wok/plugins/kimchi/xmlutils/serial.py b/src/wok/plugins/kimchi/xmlutils/serial.py
new file mode 100644
index 0000000..869a971
--- /dev/null
+++ b/src/wok/plugins/kimchi/xmlutils/serial.py
@@ -0,0 +1,55 @@
+#
+# Project Kimchi
+#
+# Copyright IBM, Corp. 2015
+#
+# 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_serial_xml(params):
+    """
+     For X
+     <serial type='pty'>
+       <target port='0'/>
+     </serial>
+     <console type='pty'>
+       <target type='serial' port='0'/>
+     </console>
+
+     For ppc
+     <console type='pty'>
+         <target type='serial' port='1'/>
+         <address type='spapr-vio' reg='0x30001000'/>
+     </console>
+    """
+    # pcc serial console
+    if params["arch"] in ["ppc", "ppc64"]:
+        console = E.console(type="pty")
+        console.append(E.target(type="serial", port='1'))
+        console.append(E.address(type="spapr-vio", reg="0x30001000"))
+        return ET.tostring(console, encoding='utf-8', pretty_print=True)
+
+    # for x
+    else:
+        serial = E.serial(type="pty")
+        serial.append(E.target(port='0'))
+        console = E.console(type="pty")
+        console.append(E.target(type="serial", port='0'))
+        return ET.tostring(serial, encoding='utf-8', pretty_print=True) + \
+               ET.tostring(console, encoding='utf-8', pretty_print=True)
+
+    return ''
-- 
2.1.0




More information about the Kimchi-devel mailing list