mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-26 21:57:33 +03:00
VirtualSmartCard: Convert to new style XML props
This commit is contained in:
parent
f3a37ba195
commit
b6f2d99db2
@ -74,8 +74,7 @@
|
||||
<channel type="spicevmc">
|
||||
<target type="virtio" name="com.redhat.spice.0"/>
|
||||
</channel>
|
||||
<smartcard mode="passthrough" type="spicevmc">
|
||||
</smartcard>
|
||||
<smartcard mode="passthrough" type="spicevmc"/>
|
||||
<tpm model="tpm-tis">
|
||||
<backend type="passthrough">
|
||||
<device path="/dev/tpm0"/>
|
||||
@ -161,8 +160,7 @@
|
||||
<channel type="spicevmc">
|
||||
<target type="virtio" name="com.redhat.spice.0"/>
|
||||
</channel>
|
||||
<smartcard mode="passthrough" type="spicevmc">
|
||||
</smartcard>
|
||||
<smartcard mode="passthrough" type="spicevmc"/>
|
||||
<tpm model="tpm-tis">
|
||||
<backend type="passthrough">
|
||||
<device path="/dev/tpm0"/>
|
||||
|
@ -1588,7 +1588,9 @@ class vmmAddHardware(vmmGObjectUI):
|
||||
mode = self.get_config_smartcard_mode()
|
||||
|
||||
try:
|
||||
self._dev = VirtualSmartCardDevice(conn, mode)
|
||||
self._dev = VirtualSmartCardDevice(conn)
|
||||
self._dev.mode = mode
|
||||
self._dev.validate()
|
||||
except Exception, e:
|
||||
return self.err.val_err(_("Smartcard device parameter error"), e)
|
||||
|
||||
|
@ -809,6 +809,7 @@ class vmmDomain(vmmLibvirtObject):
|
||||
def define_smartcard_mode(self, devobj, newmodel):
|
||||
def change(editdev):
|
||||
editdev.mode = newmodel
|
||||
editdev.type = editdev.TYPE_DEFAULT
|
||||
return self._redefine_device(change, devobj)
|
||||
|
||||
# Controller define methods
|
||||
|
@ -28,59 +28,23 @@ class VirtualSmartCardDevice(VirtualDevice):
|
||||
_virtual_device_type = VirtualDevice.VIRTUAL_DEV_SMARTCARD
|
||||
|
||||
# Default models list
|
||||
MODE_DEFAULT = "passthrough"
|
||||
_modes = ["passthrough", "host-certificates", "host"]
|
||||
MODE_DEFAULT = "default"
|
||||
MODES = ["passthrough", "host-certificates", "host"]
|
||||
|
||||
TYPE_DEFAULT = "tcp"
|
||||
_types = ["tcp", "spicevmc", None]
|
||||
TYPE_DEFAULT = "default"
|
||||
TYPES = ["tcp", "spicevmc", "default"]
|
||||
|
||||
def __init__(self, conn, mode=MODE_DEFAULT,
|
||||
parsexml=None, parsexmlnode=None):
|
||||
VirtualDevice.__init__(self, conn, parsexml, parsexmlnode)
|
||||
|
||||
self._mode = None
|
||||
self._type = None
|
||||
_XML_PROP_ORDER = ["mode", "type"]
|
||||
|
||||
if self._is_parse():
|
||||
return
|
||||
mode = XMLProperty(xpath="./@mode",
|
||||
default_cb=lambda s: "passthrough",
|
||||
default_name=MODE_DEFAULT)
|
||||
|
||||
self.mode = mode
|
||||
|
||||
def get_modes(self):
|
||||
return self._modes[:]
|
||||
modes = property(get_modes)
|
||||
|
||||
def get_mode(self):
|
||||
return self._mode
|
||||
def set_mode(self, val):
|
||||
if val not in self.modes:
|
||||
raise ValueError(_("Unknown smartcard mode '%s'") % val)
|
||||
self._mode = val
|
||||
mode = XMLProperty(get_mode, set_mode,
|
||||
xpath="./@mode")
|
||||
|
||||
def get_types(self):
|
||||
return self._types[:]
|
||||
types = property(get_types)
|
||||
|
||||
def get_type(self):
|
||||
if self._type is None and self.mode == "passthrough":
|
||||
def _default_type(self):
|
||||
if self.mode == self.MODE_DEFAULT or self.mode == "passthrough":
|
||||
return "spicevmc"
|
||||
return self._type
|
||||
def set_type(self, val):
|
||||
if val not in self.types:
|
||||
raise ValueError(_("Unknown smartcard type '%s'") % val)
|
||||
self._type = val
|
||||
type = XMLProperty(get_type, set_type,
|
||||
xpath="./@type")
|
||||
|
||||
def _get_xml_config(self):
|
||||
mode = self.mode
|
||||
|
||||
xml = " <smartcard mode='%s'" % mode
|
||||
if self.type:
|
||||
xml += " type='%s'" % self.type
|
||||
xml += ">\n"
|
||||
xml += " </smartcard>"
|
||||
|
||||
return xml
|
||||
return "tcp"
|
||||
type = XMLProperty(xpath="./@type",
|
||||
default_cb=_default_type,
|
||||
default_name=TYPE_DEFAULT)
|
||||
|
@ -1573,11 +1573,11 @@ def parse_network(guest, optstring, dev=None, mac=None):
|
||||
|
||||
return dev
|
||||
|
||||
|
||||
######################
|
||||
# --graphics parsing #
|
||||
######################
|
||||
|
||||
|
||||
def parse_graphics(guest, optstring, dev=None):
|
||||
if optstring is None:
|
||||
return None
|
||||
@ -1628,10 +1628,10 @@ def parse_graphics(guest, optstring, dev=None):
|
||||
|
||||
return dev
|
||||
|
||||
#######################
|
||||
# --controller parsing #
|
||||
#######################
|
||||
|
||||
########################
|
||||
# --controller parsing #
|
||||
########################
|
||||
|
||||
def parse_controller(guest, optstring, dev=None):
|
||||
if optstring is None:
|
||||
@ -1663,11 +1663,11 @@ def parse_controller(guest, optstring, dev=None):
|
||||
|
||||
return dev
|
||||
|
||||
|
||||
#######################
|
||||
# --smartcard parsing #
|
||||
#######################
|
||||
|
||||
|
||||
def parse_smartcard(guest, optstring, dev=None):
|
||||
if optstring is None:
|
||||
return None
|
||||
@ -1678,7 +1678,7 @@ def parse_smartcard(guest, optstring, dev=None):
|
||||
return None
|
||||
|
||||
if not dev:
|
||||
dev = virtinst.VirtualSmartCardDevice(guest.conn, opts.get("mode"))
|
||||
dev = virtinst.VirtualSmartCardDevice(guest.conn)
|
||||
|
||||
set_param = _build_set_param(dev, opts)
|
||||
|
||||
@ -1690,11 +1690,11 @@ def parse_smartcard(guest, optstring, dev=None):
|
||||
|
||||
return dev
|
||||
|
||||
|
||||
######################
|
||||
# --redirdev parsing #
|
||||
######################
|
||||
|
||||
|
||||
def parse_redirdev(guest, optstring, dev=None):
|
||||
if optstring is None:
|
||||
return None
|
||||
@ -1727,10 +1727,10 @@ def parse_redirdev(guest, optstring, dev=None):
|
||||
|
||||
return dev
|
||||
|
||||
#######################
|
||||
# --tpm parsing #
|
||||
#######################
|
||||
|
||||
#################
|
||||
# --tpm parsing #
|
||||
#################
|
||||
|
||||
def parse_tpm(guest, optstring, dev=None):
|
||||
if optstring is None:
|
||||
@ -1755,11 +1755,11 @@ def parse_tpm(guest, optstring, dev=None):
|
||||
|
||||
return dev
|
||||
|
||||
|
||||
######################
|
||||
# --watchdog parsing #
|
||||
######################
|
||||
|
||||
|
||||
def parse_watchdog(guest, optstring, dev=None):
|
||||
# Peel the model type off the front
|
||||
opts = parse_optstr(optstring, remove_first="model")
|
||||
@ -1782,11 +1782,11 @@ def parse_watchdog(guest, optstring, dev=None):
|
||||
|
||||
return dev
|
||||
|
||||
|
||||
########################
|
||||
# --memballoon parsing #
|
||||
########################
|
||||
|
||||
|
||||
def parse_memballoon(guest, optstring, dev=None):
|
||||
if optstring is None:
|
||||
return None
|
||||
@ -1909,11 +1909,11 @@ def parse_filesystem(guest, optstring, dev=None):
|
||||
|
||||
return dev
|
||||
|
||||
|
||||
###################
|
||||
# --video parsing #
|
||||
###################
|
||||
|
||||
|
||||
def parse_video(guest, optstr, dev=None):
|
||||
opts = {"model" : optstr}
|
||||
|
||||
@ -1928,6 +1928,7 @@ def parse_video(guest, optstr, dev=None):
|
||||
raise ValueError(_("Unknown options %s") % opts.keys())
|
||||
return dev
|
||||
|
||||
|
||||
#####################
|
||||
# --soundhw parsing #
|
||||
#####################
|
||||
@ -1947,11 +1948,11 @@ def parse_sound(guest, optstr, dev=None):
|
||||
raise ValueError(_("Unknown options %s") % opts.keys())
|
||||
return dev
|
||||
|
||||
|
||||
#####################
|
||||
# --hostdev parsing #
|
||||
#####################
|
||||
|
||||
|
||||
def parse_hostdev(guest, optstr, dev=None):
|
||||
ignore = dev
|
||||
return virtinst.VirtualHostDevice.device_from_node(conn=guest.conn,
|
||||
|
@ -713,6 +713,9 @@ class XMLBuilder(object):
|
||||
def set_defaults(self):
|
||||
pass
|
||||
|
||||
def validate(self):
|
||||
pass
|
||||
|
||||
def _get_xml_config(self):
|
||||
"""
|
||||
Internal XML building function. Must be overwritten by subclass
|
||||
|
Loading…
x
Reference in New Issue
Block a user