Add support for setting up <channel> elements in libvirt config

To enable use of guest agents, support for configuring the
<channel> elements in libvirt XML config is required

Blueprint: libvirt-spice
Change-Id: I3cea7b326bb2f746c5804d0aa3bbe369da6935e8
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2012-12-18 11:31:40 +00:00
parent 5873dbd6b1
commit a41f4c96ca
2 changed files with 62 additions and 6 deletions

View File

@ -539,6 +539,29 @@ class LibvirtConfigGuestConsoleTest(LibvirtConfigBaseTest):
<console type="pty"/>""")
class LibvirtConfigGuestChannelTest(LibvirtConfigBaseTest):
def test_config_spice_minimal(self):
obj = config.LibvirtConfigGuestChannel()
obj.type = "spicevmc"
xml = obj.to_xml()
self.assertXmlEqual(xml, """
<channel type="spicevmc">
<target type='virtio'/>
</channel>""")
def test_config_spice_full(self):
obj = config.LibvirtConfigGuestChannel()
obj.type = "spicevmc"
obj.target_name = "com.redhat.spice.0"
xml = obj.to_xml()
self.assertXmlEqual(xml, """
<channel type="spicevmc">
<target type='virtio' name='com.redhat.spice.0'/>
</channel>""")
class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest):
def test_config_ethernet(self):
obj = config.LibvirtConfigGuestInterface()

View File

@ -648,21 +648,34 @@ class LibvirtConfigGuestGraphics(LibvirtConfigGuestDevice):
return dev
class LibvirtConfigGuestChar(LibvirtConfigGuestDevice):
class LibvirtConfigGuestCharBase(LibvirtConfigGuestDevice):
def __init__(self, **kwargs):
super(LibvirtConfigGuestCharBase, self).__init__(**kwargs)
self.type = "pty"
self.source_path = None
def format_dom(self):
dev = super(LibvirtConfigGuestCharBase, self).format_dom()
dev.set("type", self.type)
if self.type == "file":
dev.append(etree.Element("source", path=self.source_path))
return dev
class LibvirtConfigGuestChar(LibvirtConfigGuestCharBase):
def __init__(self, **kwargs):
super(LibvirtConfigGuestChar, self).__init__(**kwargs)
self.type = "pty"
self.source_path = None
self.target_port = None
def format_dom(self):
dev = super(LibvirtConfigGuestChar, self).format_dom()
dev.set("type", self.type)
if self.type == "file":
dev.append(etree.Element("source", path=self.source_path))
if self.target_port is not None:
dev.append(etree.Element("target", port=str(self.target_port)))
@ -683,6 +696,26 @@ class LibvirtConfigGuestConsole(LibvirtConfigGuestChar):
**kwargs)
class LibvirtConfigGuestChannel(LibvirtConfigGuestCharBase):
def __init__(self, **kwargs):
super(LibvirtConfigGuestChannel, self).__init__(root_name="channel",
**kwargs)
self.target_type = "virtio"
self.target_name = None
def format_dom(self):
dev = super(LibvirtConfigGuestChannel, self).format_dom()
target = etree.Element("target", type=self.target_type)
if self.target_name is not None:
target.set("name", self.target_name)
dev.append(target)
return dev
class LibvirtConfigGuest(LibvirtConfigObject):
def __init__(self, **kwargs):