devicegraphics: Fix updating listen address

We need to make sure to change the corresponding <listen> block on newish
libvirt.
This commit is contained in:
Cole Robinson 2014-01-29 08:18:01 -05:00
parent c5581c01d2
commit d0c734e215
4 changed files with 45 additions and 6 deletions

View File

@ -25,10 +25,15 @@
</disk>
<graphics type="vnc" passwd="foobar" port="100" listen="0.0.0.0"/>
<graphics type="sdl" xauth="/tmp/.Xauthority" display="1:2"/>
<graphics type="rdp"/>
<graphics type="rdp" listen='1.1.2.3'>
<listen type='address' address='1.1.2.3'/>
</graphics>
<graphics type="vnc" port="-1" socket="/tmp/foobar"/>
<graphics type="vnc" autoport="yes"/>
<graphics type="vnc" autoport="yes">
<listen type='network' network='Bobsnetwork'/>
</graphics>
<graphics type="spice" passwd="foobar" port="100" tlsPort="101" listen="0.0.0.0" passwdValidTo="2010-04-09T15:51:00">
<listen type='address' address='0.0.0.0'/>
<channel name='inputs' mode='insecure'/>
<channel name='main' mode='secure'/>
<channel name='record' mode='any'/>

View File

@ -25,10 +25,14 @@
</disk>
<graphics type="vnc" passwd="newpass" port="6000" listen="1.2.3.4" keymap="en-us"/>
<graphics type="sdl" xauth="fooauth" display="6:1"/>
<graphics type="vnc"/>
<graphics type="vnc">
</graphics>
<graphics type="vnc" port="-1" socket="/var/lib/libvirt/socket/foo"/>
<graphics type="vnc" autoport="no"/>
<graphics type="vnc" autoport="no">
<listen type="network" network="mynewnet"/>
</graphics>
<graphics type="spice" passwd="newpass" port="6000" tlsPort="6001" listen="1.2.3.4" passwdValidTo="2011-01-07T19:08:00">
<listen type="address" address="1.2.3.4"/>
<channel name="inputs" mode="secure"/>
<channel name="main" mode="any"/>
<channel name="record" mode="insecure"/>

View File

@ -503,6 +503,7 @@ class XMLParseTest(unittest.TestCase):
check = self._make_checker(dev3)
check("type", "rdp", "vnc")
check("listen", "1.1.2.3", None)
check = self._make_checker(dev4)
check("type", "vnc")
@ -511,7 +512,13 @@ class XMLParseTest(unittest.TestCase):
check = self._make_checker(dev5)
check("autoport", True, False)
check = self._make_checker(dev5.listens[0])
check("type", "network", "foo", "network")
check("network", "Bobsnetwork", "mynewnet")
check = self._make_checker(dev6.listens[0])
check("type", "address")
check("address", "0.0.0.0")
check = self._make_checker(dev6)
check("type", "spice")
check("passwd", "foobar", "newpass")

View File

@ -20,7 +20,7 @@
import os
from virtinst import VirtualDevice
from virtinst.xmlbuilder import XMLProperty
from virtinst.xmlbuilder import XMLBuilder, XMLChildProperty, XMLProperty
def _get_mode_prop(channel_type):
@ -39,6 +39,14 @@ def _validate_port(name, val):
return val
class _GraphicsListen(XMLBuilder):
_XML_ROOT_NAME = "listen"
type = XMLProperty("./@type")
address = XMLProperty("./@address")
network = XMLProperty("./@network")
class VirtualGraphics(VirtualDevice):
virtual_device_type = VirtualDevice.VIRTUAL_DEV_GRAPHICS
@ -177,13 +185,28 @@ class VirtualGraphics(VirtualDevice):
default_cb=_get_default_display)
def _set_listen(self, val):
# Update the corresponding <listen> block
find_listen = [l for l in self.listens if
(l.type == "address" and l.address == self.listen)]
if find_listen:
if val is None:
self.remove_listen(find_listen[0])
else:
find_listen[0].address = val
return val
listen = XMLProperty("./@listen", set_converter=_set_listen)
type = XMLProperty("./@type",
default_cb=lambda s: "vnc",
default_name="default")
listen = XMLProperty("./@listen")
passwd = XMLProperty("./@passwd")
passwdValidTo = XMLProperty("./@passwdValidTo")
socket = XMLProperty("./@socket")
listens = XMLChildProperty(_GraphicsListen)
def remove_listen(self, obj):
self._remove_child(obj)
VirtualGraphics.register_type()