1#
2# Copyright 2011, 2013 Red Hat, Inc.
3#
4# This work is licensed under the GNU GPLv2 or later.
5# See the COPYING file in the top-level directory.
6
7from .char import CharSource
8from .device import Device
9from ..xmlbuilder import XMLBuilder, XMLChildProperty, XMLProperty
10
11
12class _Certificate(XMLBuilder):
13    XML_NAME = "certificate"
14
15    value = XMLProperty("./.")
16
17
18class DeviceSmartcard(Device):
19    XML_NAME = "smartcard"
20    _XML_PROP_ORDER = ["mode", "type"]
21
22    mode = XMLProperty("./@mode")
23    type = XMLProperty("./@type")
24    source = XMLChildProperty(CharSource, is_single=True)
25
26    database = XMLProperty("./database")
27    certificates = XMLChildProperty(_Certificate)
28
29
30    ##################
31    # Default config #
32    ##################
33
34    def default_type(self):
35        return self.mode == "passthrough" and "spicevmc" or "tcp"
36
37    def set_defaults(self, guest):
38        if not self.mode:
39            self.mode = "passthrough"
40        if not self.type:
41            self.type = self.default_type()
42