virtinst: allow EGD RNG devices to have both bind and connect sources
Remove backend_mode from VirtualRNGDevice and allow to directly specify bind and connect sources. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
parent
2a040ccd17
commit
8248331d6c
|
@ -53,6 +53,7 @@
|
|||
<rng model='virtio'>
|
||||
<rate period='2000' bytes='1234'/>
|
||||
<backend model='egd' type='udp'>
|
||||
<source mode='bind' service='1233'/>
|
||||
<source mode='connect' host='1.2.3.4' service='1234'/>
|
||||
</backend>
|
||||
</rng>
|
||||
|
|
|
@ -52,8 +52,9 @@
|
|||
<console type="pty"/>
|
||||
<rng model="virtio">
|
||||
<rate period="2001" bytes="4321"/>
|
||||
<backend model="egd" type="tcp">
|
||||
<source mode="bind" host="1.2.3.5" service="1235"/>
|
||||
<backend model="egd" type="udp">
|
||||
<source mode="bind" service="1236"/>
|
||||
<source mode="connect" host="1.2.3.5" service="1235"/>
|
||||
</backend>
|
||||
</rng>
|
||||
</devices>
|
||||
|
|
|
@ -747,11 +747,12 @@ class XMLParseTest(unittest.TestCase):
|
|||
|
||||
check = self._make_checker(dev1)
|
||||
check("type", "egd")
|
||||
check("backend_type", "udp", "tcp")
|
||||
check("backend_type", "udp", "udp")
|
||||
|
||||
check("backend_source_host", "1.2.3.4", "1.2.3.5")
|
||||
check("backend_source_service", "1234", "1235")
|
||||
check("backend_source_mode", "connect", "bind")
|
||||
check("connect_host", "1.2.3.4", "1.2.3.5")
|
||||
check("connect_service", "1234", "1235")
|
||||
check("bind_host", None, None)
|
||||
check("bind_service", "1233", "1236")
|
||||
|
||||
check("rate_bytes", "1234", "4321")
|
||||
check("rate_period", "2000", "2001")
|
||||
|
|
|
@ -62,11 +62,11 @@ class VirtualRNGDevice(VirtualDevice):
|
|||
"""
|
||||
users = {
|
||||
"type" : [self.TYPE_EGD, self.TYPE_RANDOM],
|
||||
|
||||
"model" : [self.TYPE_EGD, self.TYPE_RANDOM],
|
||||
"backend_source_host" : [self.TYPE_EGD],
|
||||
"backend_source_mode" : [self.TYPE_EGD],
|
||||
"backend_source_service" : [self.TYPE_EGD],
|
||||
"bind_host" : [self.TYPE_EGD],
|
||||
"bind_service" : [self.TYPE_EGD],
|
||||
"connect_host" : [self.TYPE_EGD],
|
||||
"connect_service" : [self.TYPE_EGD],
|
||||
"backend_type" : [self.TYPE_EGD],
|
||||
"device" : [self.TYPE_RANDOM],
|
||||
"rate_bytes" : [self.TYPE_EGD, self.TYPE_RANDOM],
|
||||
|
@ -77,14 +77,43 @@ class VirtualRNGDevice(VirtualDevice):
|
|||
|
||||
return hasattr(self, propname)
|
||||
|
||||
def backend_mode(self):
|
||||
ret = []
|
||||
if self._has_mode_bind:
|
||||
ret.append(VirtualRNGDevice.BACKEND_MODE_BIND)
|
||||
if self._has_mode_connect:
|
||||
ret.append(VirtualRNGDevice.BACKEND_MODE_CONNECT)
|
||||
return ret
|
||||
|
||||
_XML_PROP_ORDER = ["_has_mode_bind", "_has_mode_connect"]
|
||||
|
||||
_has_mode_connect = XMLProperty("./backend/source[@mode='connect']/@mode")
|
||||
def _set_connect_validate(self, val):
|
||||
if val:
|
||||
self._has_mode_connect = VirtualRNGDevice.BACKEND_MODE_CONNECT
|
||||
return val
|
||||
|
||||
_has_mode_bind = XMLProperty("./backend/source[@mode='bind']/@mode")
|
||||
def _set_bind_validate(self, val):
|
||||
if val:
|
||||
self._has_mode_bind = VirtualRNGDevice.BACKEND_MODE_BIND
|
||||
return val
|
||||
|
||||
type = XMLProperty(xpath="./backend/@model")
|
||||
model = XMLProperty(xpath="./@model",
|
||||
default_cb=lambda s: "virtio")
|
||||
|
||||
backend_type = XMLProperty(xpath="./backend/@type")
|
||||
backend_source_host = XMLProperty(xpath="./backend/source/@host")
|
||||
backend_source_service = XMLProperty(xpath="./backend/source/@service")
|
||||
backend_source_mode = XMLProperty(xpath="./backend/source/@mode")
|
||||
|
||||
bind_host = XMLProperty(xpath="./backend/source[@mode='bind']/@host",
|
||||
set_converter=_set_bind_validate)
|
||||
bind_service = XMLProperty(xpath="./backend/source[@mode='bind']/@service",
|
||||
set_converter=_set_bind_validate)
|
||||
|
||||
connect_host = XMLProperty(xpath="./backend/source[@mode='connect']/@host",
|
||||
set_converter=_set_connect_validate)
|
||||
connect_service = XMLProperty(set_converter=_set_connect_validate,
|
||||
xpath="./backend/source[@mode='connect']/@service")
|
||||
|
||||
rate_bytes = XMLProperty(xpath="./rate/@bytes")
|
||||
rate_period = XMLProperty(xpath="./rate/@period")
|
||||
|
|
Loading…
Reference in New Issue