2014-01-10 13:37:54 +04:00
#
# Copyright 2013 Fujitsu Limited.
# Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
#
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.
2014-01-10 13:37:54 +04:00
2018-03-20 19:18:35 +03:00
from . device import Device
2018-03-20 19:27:37 +03:00
from . . xmlbuilder import XMLProperty
2014-01-10 13:37:54 +04:00
2018-03-20 19:18:35 +03:00
class DevicePanic ( Device ) :
2018-03-21 17:53:34 +03:00
XML_NAME = " panic "
2017-09-04 19:40:34 +03:00
MODEL_ISA = " isa "
2017-09-05 10:38:39 +03:00
MODEL_PSERIES = " pseries "
MODEL_HYPERV = " hyperv "
MODEL_S390 = " s390 "
2014-01-10 13:37:54 +04:00
@staticmethod
2017-09-04 19:40:34 +03:00
def get_pretty_model ( panic_model ) :
2018-03-20 19:18:35 +03:00
if panic_model == DevicePanic . MODEL_ISA :
2014-01-10 13:37:54 +04:00
return _ ( " ISA " )
2018-03-20 19:18:35 +03:00
elif panic_model == DevicePanic . MODEL_PSERIES :
2017-09-05 10:38:39 +03:00
return _ ( " pSeries " )
2018-03-20 19:18:35 +03:00
elif panic_model == DevicePanic . MODEL_HYPERV :
2017-09-05 10:38:39 +03:00
return _ ( " Hyper-V " )
2018-03-20 19:18:35 +03:00
elif panic_model == DevicePanic . MODEL_S390 :
2017-09-05 10:38:39 +03:00
return _ ( " s390 " )
2017-09-04 19:40:34 +03:00
return panic_model
2014-01-10 13:37:54 +04:00
2017-09-05 10:38:39 +03:00
@staticmethod
def get_models ( os ) :
if os . is_x86 ( ) :
2018-03-20 19:18:35 +03:00
return [ DevicePanic . MODEL_ISA ,
DevicePanic . MODEL_HYPERV ]
2017-09-05 10:38:39 +03:00
elif os . is_pseries ( ) :
2018-03-20 19:18:35 +03:00
return [ DevicePanic . MODEL_PSERIES ]
2017-09-05 10:38:39 +03:00
elif os . is_s390x ( ) :
2018-03-20 19:18:35 +03:00
return [ DevicePanic . MODEL_S390 ]
2017-10-27 10:42:54 +03:00
return [ ]
2017-09-05 10:38:39 +03:00
2018-09-01 22:58:26 +03:00
model = XMLProperty ( " ./@model " )
##################
# Default config #
##################
2017-09-05 10:38:39 +03:00
@staticmethod
2018-09-01 22:58:26 +03:00
def get_default_model ( guest ) :
models = DevicePanic . get_models ( guest . os )
2017-09-05 10:38:39 +03:00
if models :
return models [ 0 ]
return None
2018-09-01 22:58:26 +03:00
def set_defaults ( self , guest ) :
2019-05-12 16:18:36 +03:00
if not self . address . type and self . address . iobase :
self . address . type = " isa "
2018-09-01 22:58:26 +03:00
if not self . model :
self . model = self . get_default_model ( guest )