mirror of
https://github.com/virt-manager/virt-manager.git
synced 2026-08-05 18:57:03 -05:00
devices: Add set_defaults for memballon, redirdev, rng, smartcard
This commit is contained in:
@@ -227,6 +227,7 @@
|
||||
</interface>
|
||||
<smartcard mode="passthrough" type="spicevmc"/>
|
||||
<smartcard mode="passthrough" type="host"/>
|
||||
<smartcard mode="passthrough" type="spicevmc"/>
|
||||
<serial type="tcp">
|
||||
<source mode="bind" host="127.0.0.1" service="2222"/>
|
||||
<protocol type="telnet"/>
|
||||
@@ -389,6 +390,7 @@
|
||||
<source host="127.0.0.1" service="4002"/>
|
||||
<boot order="3"/>
|
||||
</redirdev>
|
||||
<redirdev bus="usb" type="spicevmc"/>
|
||||
<rng model="virtio">
|
||||
<backend model="egd" type="tcp">
|
||||
<source mode="connect" host="127.0.0.1" service="8000"/>
|
||||
|
||||
@@ -500,10 +500,12 @@ c.add_compare(""" \
|
||||
\
|
||||
--smartcard passthrough,type=spicevmc \
|
||||
--smartcard type=host \
|
||||
--smartcard default \
|
||||
\
|
||||
--redirdev usb,type=spicevmc \
|
||||
--redirdev usb,type=tcp,server=localhost:4000 \
|
||||
--redirdev usb,type=tcp,server=127.0.0.1:4002,boot_order=3 \
|
||||
--redirdev default \
|
||||
\
|
||||
--rng egd,backend_host=127.0.0.1,backend_service=8000,backend_type=tcp \
|
||||
\
|
||||
|
||||
@@ -897,7 +897,8 @@ class vmmDomain(vmmLibvirtObject):
|
||||
|
||||
if model != _SENTINEL:
|
||||
editdev.mode = model
|
||||
editdev.type = editdev.TYPE_DEFAULT
|
||||
editdev.type = None
|
||||
editdev.type = editdev.default_type()
|
||||
|
||||
if do_hotplug:
|
||||
self.hotplug(device=editdev)
|
||||
|
||||
+4
-4
@@ -2384,8 +2384,8 @@ class ParserSmartcard(VirtCLIParser):
|
||||
|
||||
_register_virt_parser(ParserSmartcard)
|
||||
_add_device_address_args(ParserSmartcard)
|
||||
ParserSmartcard.add_arg("mode", "mode")
|
||||
ParserSmartcard.add_arg("type", "type")
|
||||
ParserSmartcard.add_arg("mode", "mode", ignore_default=True)
|
||||
ParserSmartcard.add_arg("type", "type", ignore_default=True)
|
||||
|
||||
|
||||
######################
|
||||
@@ -2409,8 +2409,8 @@ class ParserRedir(VirtCLIParser):
|
||||
|
||||
_register_virt_parser(ParserRedir)
|
||||
_add_device_address_args(ParserRedir)
|
||||
ParserRedir.add_arg("bus", "bus")
|
||||
ParserRedir.add_arg("type", "type")
|
||||
ParserRedir.add_arg("bus", "bus", ignore_default=True)
|
||||
ParserRedir.add_arg("type", "type", ignore_default=True)
|
||||
ParserRedir.add_arg("boot.order", "boot_order")
|
||||
ParserRedir.add_arg(None, "server", cb=ParserRedir.set_server_cb)
|
||||
|
||||
|
||||
@@ -13,9 +13,13 @@ from ..xmlbuilder import XMLProperty
|
||||
class DeviceMemballoon(Device):
|
||||
XML_NAME = "memballoon"
|
||||
|
||||
MODEL_DEFAULT = "default"
|
||||
MODELS = ["virtio", "xen", "none"]
|
||||
model = XMLProperty("./@model")
|
||||
|
||||
model = XMLProperty("./@model",
|
||||
default_name=MODEL_DEFAULT,
|
||||
default_cb=lambda s: "virtio")
|
||||
|
||||
##################
|
||||
# Default config #
|
||||
##################
|
||||
|
||||
def set_defaults(self, guest):
|
||||
if not self.model:
|
||||
self.model = "virtio"
|
||||
|
||||
@@ -13,12 +13,6 @@ from ..xmlbuilder import XMLProperty
|
||||
class DeviceRedirdev(Device):
|
||||
XML_NAME = "redirdev"
|
||||
|
||||
BUS_DEFAULT = "default"
|
||||
BUSES = ["usb"]
|
||||
|
||||
TYPE_DEFAULT = "default"
|
||||
TYPES = ["tcp", "spicevmc"]
|
||||
|
||||
@staticmethod
|
||||
def pretty_type(typ):
|
||||
if typ == "tcp":
|
||||
@@ -36,12 +30,19 @@ class DeviceRedirdev(Device):
|
||||
|
||||
_XML_PROP_ORDER = ["bus", "type"]
|
||||
|
||||
bus = XMLProperty("./@bus",
|
||||
default_cb=lambda s: "usb",
|
||||
default_name=BUS_DEFAULT)
|
||||
type = XMLProperty("./@type",
|
||||
default_cb=lambda s: "spicevmc",
|
||||
default_name=TYPE_DEFAULT)
|
||||
bus = XMLProperty("./@bus")
|
||||
type = XMLProperty("./@type")
|
||||
|
||||
host = XMLProperty("./source/@host")
|
||||
service = XMLProperty("./source/@service", is_int=True)
|
||||
|
||||
|
||||
##################
|
||||
# Default config #
|
||||
##################
|
||||
|
||||
def set_defaults(self, guest):
|
||||
if not self.bus:
|
||||
self.bus = "usb"
|
||||
if not self.type:
|
||||
self.type = "spicevmc"
|
||||
|
||||
+10
-4
@@ -14,15 +14,12 @@ class DeviceRng(Device):
|
||||
|
||||
TYPE_RANDOM = "random"
|
||||
TYPE_EGD = "egd"
|
||||
TYPES = [TYPE_RANDOM, TYPE_EGD]
|
||||
|
||||
BACKEND_TYPE_UDP = "udp"
|
||||
BACKEND_TYPE_TCP = "tcp"
|
||||
BACKEND_TYPES = [BACKEND_TYPE_UDP, BACKEND_TYPE_TCP]
|
||||
|
||||
BACKEND_MODE_BIND = "bind"
|
||||
BACKEND_MODE_CONNECT = "connect"
|
||||
BACKEND_MODES = [BACKEND_MODE_BIND, BACKEND_MODE_CONNECT]
|
||||
|
||||
@staticmethod
|
||||
def get_pretty_type(rng_type):
|
||||
@@ -86,7 +83,7 @@ class DeviceRng(Device):
|
||||
return val
|
||||
|
||||
type = XMLProperty("./backend/@model")
|
||||
model = XMLProperty("./@model", default_cb=lambda s: "virtio")
|
||||
model = XMLProperty("./@model")
|
||||
|
||||
backend_type = XMLProperty("./backend/@type")
|
||||
|
||||
@@ -104,3 +101,12 @@ class DeviceRng(Device):
|
||||
rate_period = XMLProperty("./rate/@period")
|
||||
|
||||
device = XMLProperty("./backend[@model='random']")
|
||||
|
||||
|
||||
##################
|
||||
# Default config #
|
||||
##################
|
||||
|
||||
def set_defaults(self, guest):
|
||||
if not self.model:
|
||||
self.model = "virtio"
|
||||
|
||||
@@ -12,25 +12,21 @@ from ..xmlbuilder import XMLProperty
|
||||
|
||||
class DeviceSmartcard(Device):
|
||||
XML_NAME = "smartcard"
|
||||
|
||||
# Default models list
|
||||
MODE_DEFAULT = "default"
|
||||
MODES = ["passthrough", "host-certificates", "host"]
|
||||
|
||||
TYPE_DEFAULT = "default"
|
||||
TYPES = ["tcp", "spicevmc", "default"]
|
||||
|
||||
|
||||
_XML_PROP_ORDER = ["mode", "type"]
|
||||
|
||||
mode = XMLProperty("./@mode",
|
||||
default_cb=lambda s: "passthrough",
|
||||
default_name=MODE_DEFAULT)
|
||||
mode = XMLProperty("./@mode")
|
||||
type = XMLProperty("./@type")
|
||||
|
||||
def _default_type(self):
|
||||
if self.mode == self.MODE_DEFAULT or self.mode == "passthrough":
|
||||
return "spicevmc"
|
||||
return "tcp"
|
||||
type = XMLProperty("./@type",
|
||||
default_cb=_default_type,
|
||||
default_name=TYPE_DEFAULT)
|
||||
|
||||
##################
|
||||
# Default config #
|
||||
##################
|
||||
|
||||
def default_type(self):
|
||||
return self.mode == "passthrough" and "spicevmc" or "tcp"
|
||||
|
||||
def set_defaults(self, guest):
|
||||
if not self.mode:
|
||||
self.mode = "passthrough"
|
||||
if not self.type:
|
||||
self.type = self.default_type()
|
||||
|
||||
Reference in New Issue
Block a user