2013-03-18 01:06:52 +04:00
#
2013-10-28 00:59:46 +04:00
# Copyright 2010, 2013 Red Hat, Inc.
2013-03-18 01:06:52 +04:00
# Cole Robinson <crobinso@redhat.com>
#
2018-03-20 22:00:02 +03:00
# This work is licensed under the GNU GPLv2.
# See the COPYING file in the top-level directory.
2013-03-18 01:06:52 +04:00
2014-09-12 23:59:22 +04:00
from . xmlbuilder import XMLBuilder , XMLProperty , XMLChildProperty
2013-03-18 01:06:52 +04:00
2013-04-13 22:34:52 +04:00
2014-06-01 01:15:03 +04:00
class _InitArg ( XMLBuilder ) :
_XML_ROOT_NAME = " initarg "
val = XMLProperty ( " . " )
2013-09-11 02:32:10 +04:00
class _BootDevice ( XMLBuilder ) :
2013-09-11 19:47:09 +04:00
_XML_ROOT_NAME = " boot "
2013-09-11 02:32:10 +04:00
dev = XMLProperty ( " ./@dev " )
2013-07-24 20:35:03 +04:00
2013-07-17 04:39:24 +04:00
class OSXML ( XMLBuilder ) :
2013-03-18 01:06:52 +04:00
"""
Class for generating boot device related XML
"""
BOOT_DEVICE_HARDDISK = " hd "
BOOT_DEVICE_CDROM = " cdrom "
BOOT_DEVICE_FLOPPY = " fd "
BOOT_DEVICE_NETWORK = " network "
2014-01-19 22:56:06 +04:00
BOOT_DEVICES = [ BOOT_DEVICE_HARDDISK , BOOT_DEVICE_CDROM ,
2013-03-18 01:06:52 +04:00
BOOT_DEVICE_FLOPPY , BOOT_DEVICE_NETWORK ]
2013-07-17 04:39:24 +04:00
def is_hvm ( self ) :
return self . os_type == " hvm "
def is_xenpv ( self ) :
return self . os_type in [ " xen " , " linux " ]
def is_container ( self ) :
return self . os_type == " exe "
2013-03-18 01:06:52 +04:00
2013-08-18 01:53:17 +04:00
def is_x86 ( self ) :
return self . arch == " x86_64 " or self . arch == " i686 "
2015-04-06 20:36:54 +03:00
def is_q35 ( self ) :
return ( self . is_x86 ( ) and
self . machine and
" q35 " in self . machine )
2014-09-23 23:12:02 +04:00
def is_arm32 ( self ) :
2013-08-18 01:53:17 +04:00
return self . arch == " armv7l "
2014-09-23 23:12:02 +04:00
def is_arm64 ( self ) :
return self . arch == " aarch64 "
def is_arm ( self ) :
return self . is_arm32 ( ) or self . is_arm64 ( )
2013-08-18 16:59:19 +04:00
def is_arm_vexpress ( self ) :
return self . is_arm ( ) and str ( self . machine ) . startswith ( " vexpress- " )
2014-09-23 23:12:02 +04:00
def is_arm_machvirt ( self ) :
2015-04-22 19:39:43 +03:00
return self . is_arm ( ) and str ( self . machine ) . startswith ( " virt " )
2014-09-23 23:12:02 +04:00
2013-08-18 01:53:17 +04:00
def is_ppc64 ( self ) :
2015-01-05 05:16:18 +03:00
return self . arch == " ppc64 " or self . arch == " ppc64le "
2013-08-18 01:53:17 +04:00
def is_pseries ( self ) :
2015-07-22 15:47:39 +03:00
return self . is_ppc64 ( ) and str ( self . machine ) . startswith ( " pseries " )
2013-08-18 01:53:17 +04:00
2015-07-13 14:35:24 +03:00
def is_s390x ( self ) :
return self . arch == " s390x "
2013-09-11 19:47:09 +04:00
_XML_ROOT_NAME = " os "
2014-09-11 13:18:32 +04:00
_XML_PROP_ORDER = [ " arch " , " os_type " , " loader " , " loader_ro " , " loader_type " ,
" nvram " , " nvram_template " , " kernel " , " initrd " ,
2016-09-07 01:12:19 +03:00
" kernel_args " , " dtb " , " _bootdevs " , " smbios_mode " ]
2013-07-24 20:35:03 +04:00
def _get_bootorder ( self ) :
return [ dev . dev for dev in self . _bootdevs ]
def _set_bootorder ( self , newdevs ) :
for dev in self . _bootdevs :
2015-09-04 22:45:45 +03:00
self . remove_child ( dev )
2013-09-11 02:32:10 +04:00
for d in newdevs :
2018-02-08 01:27:56 +03:00
dev = self . _bootdevs . add_new ( )
2013-09-11 02:32:10 +04:00
dev . dev = d
_bootdevs = XMLChildProperty ( _BootDevice )
2013-07-24 20:35:03 +04:00
bootorder = property ( _get_bootorder , _set_bootorder )
2013-07-17 21:06:01 +04:00
2014-06-01 01:15:03 +04:00
initargs = XMLChildProperty ( _InitArg )
def set_initargs_string ( self , argstring ) :
import shlex
for obj in self . initargs :
2015-09-04 22:45:45 +03:00
self . remove_child ( obj )
2014-06-01 01:15:03 +04:00
for val in shlex . split ( argstring ) :
2018-02-08 01:27:56 +03:00
obj = self . initargs . add_new ( )
obj . val = val
2014-06-01 01:15:03 +04:00
2013-09-19 21:27:30 +04:00
enable_bootmenu = XMLProperty ( " ./bootmenu/@enable " , is_yesno = True )
useserial = XMLProperty ( " ./bios/@useserial " , is_yesno = True )
2013-07-17 21:06:01 +04:00
2014-09-23 22:25:14 +04:00
kernel = XMLProperty ( " ./kernel " , do_abspath = True )
initrd = XMLProperty ( " ./initrd " , do_abspath = True )
dtb = XMLProperty ( " ./dtb " , do_abspath = True )
2013-09-19 21:27:30 +04:00
kernel_args = XMLProperty ( " ./cmdline " )
2013-07-17 21:06:01 +04:00
2013-09-19 21:27:30 +04:00
init = XMLProperty ( " ./init " )
loader = XMLProperty ( " ./loader " )
2014-09-11 13:18:32 +04:00
loader_ro = XMLProperty ( " ./loader/@readonly " , is_yesno = True )
loader_type = XMLProperty ( " ./loader/@type " )
2017-01-26 18:11:31 +03:00
loader_secure = XMLProperty ( " ./loader/@secure " , is_yesno = True )
2016-09-07 01:12:19 +03:00
smbios_mode = XMLProperty ( " ./smbios/@mode " )
2017-07-17 16:16:45 +03:00
nvram = XMLProperty ( " ./nvram " , do_abspath = True )
2014-09-11 13:18:32 +04:00
nvram_template = XMLProperty ( " ./nvram/@template " )
2013-09-19 21:27:30 +04:00
arch = XMLProperty ( " ./type/@arch " ,
2014-01-18 22:23:30 +04:00
default_cb = lambda s : s . conn . caps . host . cpu . arch )
2013-09-19 21:27:30 +04:00
machine = XMLProperty ( " ./type/@machine " )
os_type = XMLProperty ( " ./type " , default_cb = lambda s : " xen " )