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
#
2018-04-04 16:35:41 +03:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 22:00:02 +03:00
# See the COPYING file in the top-level directory.
2013-03-18 01:06:52 +04:00
2018-03-20 22:10:04 +03: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 ) :
2018-03-21 17:53:34 +03:00
XML_NAME = " initarg "
2014-06-01 01:15:03 +04:00
val = XMLProperty ( " . " )
2021-07-28 16:49:38 +03:00
class _InitEnv ( XMLBuilder ) :
XML_NAME = " initenv "
name = XMLProperty ( " ./@name " )
value = XMLProperty ( " . " )
2013-09-11 02:32:10 +04:00
class _BootDevice ( XMLBuilder ) :
2018-03-21 17:53:34 +03:00
XML_NAME = " boot "
2013-09-11 02:32:10 +04:00
dev = XMLProperty ( " ./@dev " )
2013-07-24 20:35:03 +04:00
2021-07-28 12:13:28 +03:00
class _FirmwareFeature ( XMLBuilder ) :
XML_NAME = " feature "
_XML_PROP_ORDER = [ " enabled " , " name " ]
enabled = XMLProperty ( " ./@enabled " , is_yesno = True )
name = XMLProperty ( " ./@name " )
2018-03-20 22:10:04 +03:00
class DomainOs ( 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 ) :
2024-09-06 22:27:23 +03:00
return self . os_type in [ " xen " , " linux " , " xenpvh " ]
2013-07-17 04:39:24 +04:00
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 ( )
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 "
2019-04-04 13:49:44 +03: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 " )
2023-12-13 12:43:24 +03:00
def is_loongarch64 ( self ) :
return self . arch == " loongarch64 "
2019-04-04 13:49:44 +03:00
2021-07-28 17:42:45 +03:00
##################
# XML properties #
##################
2018-03-21 17:53:34 +03:00
XML_NAME = " os "
2021-07-28 17:42:45 +03:00
_XML_PROP_ORDER = [
" firmware " , " os_type " , " arch " , " machine " , " firmware_features " ,
" loader " , " loader_ro " , " loader_secure " , " loader_type " ,
2022-10-17 18:54:37 +03:00
" loader_stateless " ,
2021-07-28 17:42:45 +03:00
" nvram " , " nvram_template " ,
" init " , " initargs " , " initenvs " , " initdir " , " inituser " , " initgroup " ,
" kernel " , " initrd " , " kernel_args " , " dtb " , " acpi_tb " , " acpi_tb_type " ,
" bootdevs " , " bootmenu_enable " , " bootmenu_timeout " ,
" bios_useserial " , " bios_rebootTimeout " , " smbios_mode " ]
# Shared/Generic boot options
os_type = XMLProperty ( " ./type " )
arch = XMLProperty ( " ./type/@arch " )
machine = XMLProperty ( " ./type/@machine " )
loader = XMLProperty ( " ./loader " )
loader_ro = XMLProperty ( " ./loader/@readonly " , is_yesno = True )
loader_type = XMLProperty ( " ./loader/@type " )
loader_secure = XMLProperty ( " ./loader/@secure " , is_yesno = True )
2022-10-17 18:54:37 +03:00
loader_stateless = XMLProperty ( " ./loader/@stateless " , is_yesno = True )
2013-07-24 20:35:03 +04:00
2021-07-28 17:42:45 +03:00
# BIOS bootloader options
2013-07-24 20:35:03 +04:00
def _get_bootorder ( self ) :
2019-05-14 20:39:42 +03:00
return [ dev . dev for dev in self . bootdevs ]
2013-07-24 20:35:03 +04:00
def _set_bootorder ( self , newdevs ) :
2019-05-14 20:39:42 +03:00
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 :
2019-05-14 20:39:42 +03:00
dev = self . bootdevs . add_new ( )
2013-09-11 02:32:10 +04:00
dev . dev = d
2013-07-24 20:35:03 +04:00
bootorder = property ( _get_bootorder , _set_bootorder )
2021-07-28 15:58:07 +03:00
bootdevs = XMLChildProperty ( _BootDevice )
2021-07-28 17:42:45 +03:00
firmware = XMLProperty ( " ./@firmware " )
firmware_features = XMLChildProperty ( _FirmwareFeature , relative_xpath = " ./firmware " )
nvram = XMLProperty ( " ./nvram " , do_abspath = True )
nvram_template = XMLProperty ( " ./nvram/@template " )
2021-07-28 15:58:07 +03:00
bootmenu_enable = XMLProperty ( " ./bootmenu/@enable " , is_yesno = True )
bootmenu_timeout = XMLProperty ( " ./bootmenu/@timeout " , is_int = True )
bios_useserial = XMLProperty ( " ./bios/@useserial " , is_yesno = True )
2021-07-28 17:42:45 +03:00
bios_rebootTimeout = XMLProperty ( " ./bios/@rebootTimeout " , is_int = True )
smbios_mode = XMLProperty ( " ./smbios/@mode " )
2013-07-17 21:06:01 +04:00
2021-07-28 17:42:45 +03:00
# Host bootloader options
2021-07-28 16:07:55 +03:00
# Since the elements for a host bootloader are actually directly under
# <domain> rather than <domain><os>, they are handled via callbacks in
# the CLI. This is just a placeholder to remind of that fact.
2021-07-28 17:42:45 +03:00
# Direct kernel boot options
2021-07-28 16:11:17 +03:00
kernel = XMLProperty ( " ./kernel " , do_abspath = True )
initrd = XMLProperty ( " ./initrd " , do_abspath = True )
kernel_args = XMLProperty ( " ./cmdline " )
dtb = XMLProperty ( " ./dtb " , do_abspath = True )
acpi_tb = XMLProperty ( " ./acpi/table " , do_abspath = True )
acpi_tb_type = XMLProperty ( " ./acpi/table/@type " )
2021-07-28 17:42:45 +03:00
# Container boot options
2021-07-28 16:49:38 +03:00
init = XMLProperty ( " ./init " )
2014-06-01 01:15:03 +04:00
initargs = XMLChildProperty ( _InitArg )
2021-07-28 16:49:38 +03:00
initenvs = XMLChildProperty ( _InitEnv )
initdir = XMLProperty ( " ./initdir " )
inituser = XMLProperty ( " ./inituser " )
initgroup = XMLProperty ( " ./initgroup " )
2014-06-01 01:15:03 +04:00
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
2018-09-02 17:05:34 +03: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 "