1#
2# Copyright 2013 Fujitsu Limited.
3# Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
4#
5# This work is licensed under the GNU GPLv2 or later.
6# See the COPYING file in the top-level directory.
7
8from .device import Device
9from ..xmlbuilder import XMLProperty
10
11
12class DevicePanic(Device):
13    XML_NAME = "panic"
14
15    MODEL_ISA = "isa"
16    MODEL_PSERIES = "pseries"
17    MODEL_HYPERV = "hyperv"
18    MODEL_S390 = "s390"
19
20    model = XMLProperty("./@model")
21
22
23    ##################
24    # Default config #
25    ##################
26
27    @staticmethod
28    def get_models(guest):
29        if guest.os.is_x86():
30            return [DevicePanic.MODEL_ISA,
31                    DevicePanic.MODEL_HYPERV]
32        elif guest.os.is_pseries():
33            return [DevicePanic.MODEL_PSERIES]
34        elif guest.os.is_s390x():
35            return [DevicePanic.MODEL_S390]
36        return []
37
38    @staticmethod
39    def get_default_model(guest):
40        models = DevicePanic.get_models(guest)
41        if models:
42            return models[0]
43        return None
44
45    def set_defaults(self, guest):
46        if not self.address.type and self.address.iobase:
47            self.address.type = "isa"
48        if not self.model:
49            self.model = DevicePanic.get_default_model(guest)
50