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

Daniel Henrique Barboza dhbarboza82 at gmail.com
Mon Nov 23 16:15:57 UTC 2015



On 11/23/2015 02:14 PM, Aline Manera wrote:
>
>
> On 17/11/2015 10:13, Ramon Medeiros wrote:
>> Automatically create serial console device.
>>
>> Signed-off-by: Ramon Medeiros <ramonn at linux.vnet.ibm.com>
>> ---
>>   src/wok/plugins/kimchi/vmtemplate.py      |  7 +++++-
>>   src/wok/plugins/kimchi/xmlutils/serial.py | 40 
>> +++++++++++++++++++++++++++++++
>>   2 files changed, 46 insertions(+), 1 deletion(-)
>>   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 283d94d..d8f2f7f 100644
>> --- a/src/wok/plugins/kimchi/vmtemplate.py
>> +++ b/src/wok/plugins/kimchi/vmtemplate.py
>> @@ -37,7 +37,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,10 @@ class VMTemplate(object):
>>           params['cpu_info'] = self._get_cpu_xml()
>>           params['disks'] = self._get_disks_xml(vm_uuid)
>
>> +        params['serial'] = ''
>> +        if params['arch'] not in ['ppc', 'ppc64']:
>> +            params['serial'] = get_serial_xml()
>> +
>
> I suggest to adapt the get_serial_xml() function to cover both archs 
> (x86 and ppc)
>
> From the current code, we have in vmtemplate.py:
>
> <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)
>
>
> This code is very odd! We don't need to replace the <memballoon> to 
> add a new XML entry.
>
> Only add %(serial)s to the guest XML and let get_serial_xml() returns 
> the right XML according to arch.
>
>>           graphics = dict(self.info['graphics'])
>>           graphics.update(kwargs.get('graphics', {}))
>>           params['graphics'] = get_graphics_xml(graphics)
>> @@ -365,6 +369,7 @@ class VMTemplate(object):
>>               %(networks)s
>>               %(graphics)s
>>               %(input_output)s
>> +            %(serial)s
>>               <memballoon model='virtio' />
>>             </devices>
>>           </domain>
>> diff --git a/src/wok/plugins/kimchi/xmlutils/serial.py 
>> b/src/wok/plugins/kimchi/xmlutils/serial.py
>> new file mode 100644
>> index 0000000..2892c45
>> --- /dev/null
>> +++ b/src/wok/plugins/kimchi/xmlutils/serial.py
>> @@ -0,0 +1,40 @@
>> +#
>> +# Project Kimchi
>> +#
>> +# Copyright IBM, Corp. 2014
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():
>> +    """
>> +     <serial type='pty'>
>> +       <target port='0'/>
>> +     </serial>
>> +     <console type='pty'>
>> +       <target type='serial' port='0'/>
>> +     </console>
>> +    """
>> +    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)
>> +
>> +
>> +
>
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/kimchi-devel




More information about the Kimchi-devel mailing list