2013-03-17 17:06:52 -04:00
#
# Copyright 2010 Red Hat, Inc.
# Cole Robinson <crobinso@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
2013-09-10 18:32:10 -04:00
from virtinst . xmlbuilder import XMLBuilder , XMLProperty , XMLChildProperty
2013-03-17 17:06:52 -04:00
2013-04-13 14:34:52 -04:00
2013-09-10 18:32:10 -04:00
class _BootDevice ( XMLBuilder ) :
2013-09-11 11:47:09 -04:00
_XML_ROOT_NAME = " boot "
2013-09-10 18:32:10 -04:00
dev = XMLProperty ( " ./@dev " )
2013-07-24 12:35:03 -04:00
2013-07-16 20:39:24 -04:00
class OSXML ( 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 "
boot_devices = [ BOOT_DEVICE_HARDDISK , BOOT_DEVICE_CDROM ,
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 "
def is_arm ( self ) :
return self . arch == " armv7l "
2013-08-18 08:59:19 -04:00
def is_arm_vexpress ( self ) :
return self . is_arm ( ) and str ( self . machine ) . startswith ( " vexpress- " )
2013-08-17 17:53:17 -04:00
def is_ppc64 ( self ) :
return self . arch == " ppc64 "
def is_pseries ( self ) :
return self . is_ppc64 and self . machine == " pseries "
2013-09-11 11:47:09 -04:00
_XML_ROOT_NAME = " os "
2013-07-17 13:06:01 -04:00
_XML_PROP_ORDER = [ " arch " , " os_type " , " loader " ,
2013-08-16 19:25:26 -04:00
" kernel " , " initrd " , " kernel_args " , " dtb " ,
2013-07-24 12:35:03 -04:00
" _bootdevs " ]
def _get_bootorder ( self ) :
return [ dev . dev for dev in self . _bootdevs ]
def _set_bootorder ( self , newdevs ) :
for dev in self . _bootdevs :
2013-09-10 18:32:10 -04:00
self . _remove_child ( dev )
for d in newdevs :
dev = _BootDevice ( self . conn )
dev . dev = d
self . _add_child ( dev )
_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
2013-09-19 13:27:30 -04:00
enable_bootmenu = XMLProperty ( " ./bootmenu/@enable " , is_yesno = True )
useserial = XMLProperty ( " ./bios/@useserial " , is_yesno = True )
2013-07-17 13:06:01 -04:00
2013-09-19 13:27:30 -04:00
kernel = XMLProperty ( " ./kernel " )
initrd = XMLProperty ( " ./initrd " )
kernel_args = XMLProperty ( " ./cmdline " )
dtb = XMLProperty ( " ./dtb " )
2013-07-17 13:06:01 -04:00
2013-09-19 13:27:30 -04:00
init = XMLProperty ( " ./init " )
loader = XMLProperty ( " ./loader " )
arch = XMLProperty ( " ./type/@arch " ,
2013-07-17 13:06:01 -04:00
default_cb = lambda s : s . conn . caps . host . arch )
2013-09-19 13:27:30 -04:00
machine = XMLProperty ( " ./type/@machine " )
os_type = XMLProperty ( " ./type " , default_cb = lambda s : " xen " )