devices: input: Add set_defaults

This commit is contained in:
Cole Robinson 2018-09-01 17:26:35 -04:00
parent 698c72e60d
commit 31d74ff0eb

View File

@ -15,15 +15,11 @@ class DeviceInput(Device):
TYPE_MOUSE = "mouse"
TYPE_TABLET = "tablet"
TYPE_KEYBOARD = "keyboard"
TYPE_DEFAULT = "default"
TYPES = [TYPE_MOUSE, TYPE_TABLET, TYPE_KEYBOARD, TYPE_DEFAULT]
BUS_PS2 = "ps2"
BUS_USB = "usb"
BUS_VIRTIO = "virtio"
BUS_XEN = "xen"
BUS_DEFAULT = "default"
BUSES = [BUS_PS2, BUS_USB, BUS_XEN, BUS_DEFAULT]
@staticmethod
def pretty_name(typ, bus):
@ -36,16 +32,23 @@ class DeviceInput(Device):
return "%s %s" % (str(bus).capitalize(), str(typ).capitalize())
type = XMLProperty("./@type",
default_cb=lambda s: s.TYPE_MOUSE,
default_name=TYPE_DEFAULT)
type = XMLProperty("./@type")
bus = XMLProperty("./@bus")
def _default_bus(self):
##################
# Default config #
##################
def _default_bus(self, _guest):
if self.type == self.TYPE_TABLET:
return self.BUS_USB
if self.conn.is_xen():
return self.BUS_XEN
return self.BUS_PS2
bus = XMLProperty("./@bus",
default_cb=_default_bus,
default_name=BUS_DEFAULT)
def set_defaults(self, guest):
if not self.type:
self.type = self.TYPE_MOUSE
if not self.bus:
self.bus = self._default_bus(guest)