devices: hostdev: Add set_defaults
This commit is contained in:
parent
0f918a4bd5
commit
ef83565e48
|
@ -8,6 +8,7 @@
|
|||
import os.path
|
||||
import unittest
|
||||
|
||||
from virtinst import Guest
|
||||
from virtinst import NodeDevice
|
||||
from virtinst import DeviceHostdev
|
||||
|
||||
|
@ -85,6 +86,7 @@ class TestNodeDev(unittest.TestCase):
|
|||
|
||||
dev = DeviceHostdev(self.conn)
|
||||
dev.set_from_nodedev(nodedev)
|
||||
dev.set_defaults(Guest(self.conn))
|
||||
utils.diff_compare(dev.get_xml() + "\n", devfile)
|
||||
|
||||
def testSystemDevice(self):
|
||||
|
|
|
@ -101,13 +101,9 @@ class DeviceHostdev(Device):
|
|||
_XML_PROP_ORDER = ["mode", "type", "managed", "vendor", "product",
|
||||
"domain", "bus", "slot", "function"]
|
||||
|
||||
mode = XMLProperty("./@mode", default_cb=lambda s: "subsystem")
|
||||
mode = XMLProperty("./@mode")
|
||||
type = XMLProperty("./@type")
|
||||
|
||||
def _get_default_managed(self):
|
||||
return self.conn.is_xen() and "no" or "yes"
|
||||
managed = XMLProperty("./@managed", is_yesno=True,
|
||||
default_cb=_get_default_managed)
|
||||
managed = XMLProperty("./@managed", is_yesno=True)
|
||||
|
||||
vendor = XMLProperty("./source/vendor/@id")
|
||||
product = XMLProperty("./source/product/@id")
|
||||
|
@ -115,12 +111,7 @@ class DeviceHostdev(Device):
|
|||
device = XMLProperty("./source/address/@device")
|
||||
bus = XMLProperty("./source/address/@bus")
|
||||
|
||||
def _get_default_domain(self):
|
||||
if self.type == "pci":
|
||||
return "0x0"
|
||||
return None
|
||||
domain = XMLProperty("./source/address/@domain",
|
||||
default_cb=_get_default_domain)
|
||||
domain = XMLProperty("./source/address/@domain")
|
||||
function = XMLProperty("./source/address/@function")
|
||||
slot = XMLProperty("./source/address/@slot")
|
||||
|
||||
|
@ -141,3 +132,16 @@ class DeviceHostdev(Device):
|
|||
|
||||
# type=misc handling
|
||||
storage_block = XMLProperty("./source/block")
|
||||
|
||||
|
||||
##################
|
||||
# Default config #
|
||||
##################
|
||||
|
||||
def set_defaults(self, guest):
|
||||
if self.managed is None:
|
||||
self.managed = self.conn.is_xen() and "no" or "yes"
|
||||
if not self.mode:
|
||||
self.mode = "subsystem"
|
||||
if self.type == "pci" and not self.domain:
|
||||
self.domain = "0x0"
|
||||
|
|
Loading…
Reference in New Issue