2013-03-17 17:06:52 -04:00
#
2013-10-27 21:59:46 +01:00
# Copyright 2010, 2013 Red Hat, Inc.
2013-03-17 17:06:52 -04:00
#
2018-04-04 14:35:41 +01:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 15:00:02 -04:00
# See the COPYING file in the top-level directory.
2013-03-17 17:06:52 -04:00
2018-03-20 15:10:04 -04:00
from . . xmlbuilder import XMLBuilder , XMLProperty , XMLChildProperty
2013-03-17 17:06:52 -04:00
2013-04-13 14:34:52 -04:00
2014-05-31 17:15:03 -04:00
class _InitArg ( XMLBuilder ) :
2018-03-21 10:53:34 -04:00
XML_NAME = " initarg "
2014-05-31 17:15:03 -04:00
val = XMLProperty ( " . " )
2013-09-10 18:32:10 -04:00
class _BootDevice ( XMLBuilder ) :
2018-03-21 10:53:34 -04:00
XML_NAME = " boot "
2013-09-10 18:32:10 -04:00
dev = XMLProperty ( " ./@dev " )
2013-07-24 12:35:03 -04:00
2021-07-28 11:13:28 +02:00
class _FirmwareFeature ( XMLBuilder ) :
XML_NAME = " feature "
_XML_PROP_ORDER = [ " enabled " , " name " ]
enabled = XMLProperty ( " ./@enabled " , is_yesno = True )
name = XMLProperty ( " ./@name " )
2018-03-20 15:10:04 -04:00
class DomainOs ( XMLBuilder ) :
2013-03-17 17: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 13:56:06 -05:00
BOOT_DEVICES = [ BOOT_DEVICE_HARDDISK , BOOT_DEVICE_CDROM ,
2013-03-17 17:06:52 -04:00
BOOT_DEVICE_FLOPPY , BOOT_DEVICE_NETWORK ]
2013-07-16 20: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-17 17:06:52 -04:00
2013-08-17 17:53:17 -04:00
def is_x86 ( self ) :
return self . arch == " x86_64 " or self . arch == " i686 "
2015-04-06 13:36:54 -04:00
def is_q35 ( self ) :
return ( self . is_x86 ( ) and
self . machine and
" q35 " in self . machine )
2014-09-23 15:12:02 -04:00
def is_arm32 ( self ) :
2013-08-17 17:53:17 -04:00
return self . arch == " armv7l "
2014-09-23 15:12:02 -04:00
def is_arm64 ( self ) :
return self . arch == " aarch64 "
def is_arm ( self ) :
return self . is_arm32 ( ) or self . is_arm64 ( )
def is_arm_machvirt ( self ) :
2015-04-22 18:39:43 +02:00
return self . is_arm ( ) and str ( self . machine ) . startswith ( " virt " )
2014-09-23 15:12:02 -04:00
2013-08-17 17:53:17 -04:00
def is_ppc64 ( self ) :
2015-01-05 07:46:18 +05:30
return self . arch == " ppc64 " or self . arch == " ppc64le "
2013-08-17 17:53:17 -04:00
def is_pseries ( self ) :
2015-07-22 14:47:39 +02:00
return self . is_ppc64 ( ) and str ( self . machine ) . startswith ( " pseries " )
2013-08-17 17:53:17 -04:00
2015-07-13 07:35:24 -04:00
def is_s390x ( self ) :
return self . arch == " s390x "
2019-04-04 12:49:44 +02:00
def is_riscv ( self ) :
return self . arch == " riscv64 " or self . arch == " riscv32 "
def is_riscv_virt ( self ) :
return self . is_riscv ( ) and str ( self . machine ) . startswith ( " virt " )
2018-03-21 10:53:34 -04:00
XML_NAME = " os "
2014-09-11 11:18:32 +02:00
_XML_PROP_ORDER = [ " arch " , " os_type " , " loader " , " loader_ro " , " loader_type " ,
" nvram " , " nvram_template " , " kernel " , " initrd " ,
2019-08-02 16:17:59 +03:00
" initdir " , " inituser " , " initgroup " ,
2019-05-14 13:39:42 -04:00
" kernel_args " , " dtb " , " bootdevs " , " smbios_mode " ]
2013-07-24 12:35:03 -04:00
def _get_bootorder ( self ) :
2019-05-14 13:39:42 -04:00
return [ dev . dev for dev in self . bootdevs ]
2013-07-24 12:35:03 -04:00
def _set_bootorder ( self , newdevs ) :
2019-05-14 13:39:42 -04:00
for dev in self . bootdevs :
2015-09-04 15:45:45 -04:00
self . remove_child ( dev )
2013-09-10 18:32:10 -04:00
for d in newdevs :
2019-05-14 13:39:42 -04:00
dev = self . bootdevs . add_new ( )
2013-09-10 18:32:10 -04:00
dev . dev = d
2019-05-14 13:39:42 -04:00
bootdevs = XMLChildProperty ( _BootDevice )
2013-07-24 12:35:03 -04:00
bootorder = property ( _get_bootorder , _set_bootorder )
2013-07-17 13:06:01 -04:00
2014-05-31 17:15:03 -04:00
initargs = XMLChildProperty ( _InitArg )
def set_initargs_string ( self , argstring ) :
import shlex
for obj in self . initargs :
2015-09-04 15:45:45 -04:00
self . remove_child ( obj )
2014-05-31 17:15:03 -04:00
for val in shlex . split ( argstring ) :
2018-02-07 17:27:56 -05:00
obj = self . initargs . add_new ( )
obj . val = val
2014-05-31 17:15:03 -04:00
2013-09-19 13:27:30 -04:00
enable_bootmenu = XMLProperty ( " ./bootmenu/@enable " , is_yesno = True )
2018-10-10 12:20:24 -07:00
rebootTimeout = XMLProperty ( " ./bios/@rebootTimeout " )
2013-09-19 13:27:30 -04:00
useserial = XMLProperty ( " ./bios/@useserial " , is_yesno = True )
2013-07-17 13:06:01 -04:00
2014-09-23 14: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 13:27:30 -04:00
kernel_args = XMLProperty ( " ./cmdline " )
2013-07-17 13:06:01 -04:00
2013-09-19 13:27:30 -04:00
init = XMLProperty ( " ./init " )
2019-08-02 16:17:59 +03:00
initdir = XMLProperty ( " ./initdir " )
inituser = XMLProperty ( " ./inituser " )
initgroup = XMLProperty ( " ./initgroup " )
2013-09-19 13:27:30 -04:00
loader = XMLProperty ( " ./loader " )
2014-09-11 11:18:32 +02:00
loader_ro = XMLProperty ( " ./loader/@readonly " , is_yesno = True )
loader_type = XMLProperty ( " ./loader/@type " )
2017-01-26 16:11:31 +01:00
loader_secure = XMLProperty ( " ./loader/@secure " , is_yesno = True )
2016-09-06 16:12:19 -06:00
smbios_mode = XMLProperty ( " ./smbios/@mode " )
2017-07-17 09:16:45 -04:00
nvram = XMLProperty ( " ./nvram " , do_abspath = True )
2014-09-11 11:18:32 +02:00
nvram_template = XMLProperty ( " ./nvram/@template " )
2018-09-02 10:05:34 -04:00
arch = XMLProperty ( " ./type/@arch " )
2013-09-19 13:27:30 -04:00
machine = XMLProperty ( " ./type/@machine " )
2018-09-02 10:05:34 -04:00
os_type = XMLProperty ( " ./type " )
2019-06-16 17:15:08 -04:00
firmware = XMLProperty ( " ./@firmware " )
2021-07-28 11:13:28 +02:00
firmware_features = XMLChildProperty ( _FirmwareFeature , relative_xpath = " ./firmware " )
2018-09-02 10:05:34 -04:00
##################
# Default config #
##################
def set_defaults ( self , guest ) :
if self . is_container ( ) and not self . init :
if guest . is_full_os_container ( ) :
self . init = " /sbin/init "
else :
self . init = " /bin/sh "