From a41f4c96ca5f1d8323c5631b9a0eab4de3e2001e Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 18 Dec 2012 11:31:40 +0000 Subject: Add support for setting up elements in libvirt config To enable use of guest agents, support for configuring the elements in libvirt XML config is required Blueprint: libvirt-spice Change-Id: I3cea7b326bb2f746c5804d0aa3bbe369da6935e8 Signed-off-by: Daniel P. Berrange --- nova/tests/test_libvirt_config.py | 23 ++++++++++++++++++++++ nova/virt/libvirt/config.py | 41 +++++++++++++++++++++++++++++++++++---- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/nova/tests/test_libvirt_config.py b/nova/tests/test_libvirt_config.py index 5eafba841..56719de11 100644 --- a/nova/tests/test_libvirt_config.py +++ b/nova/tests/test_libvirt_config.py @@ -539,6 +539,29 @@ class LibvirtConfigGuestConsoleTest(LibvirtConfigBaseTest): """) +class LibvirtConfigGuestChannelTest(LibvirtConfigBaseTest): + def test_config_spice_minimal(self): + obj = config.LibvirtConfigGuestChannel() + obj.type = "spicevmc" + + xml = obj.to_xml() + self.assertXmlEqual(xml, """ + + + """) + + 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, """ + + + """) + + class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest): def test_config_ethernet(self): obj = config.LibvirtConfigGuestInterface() diff --git a/nova/virt/libvirt/config.py b/nova/virt/libvirt/config.py index 6785c8823..ed5b21c79 100644 --- a/nova/virt/libvirt/config.py +++ b/nova/virt/libvirt/config.py @@ -648,21 +648,34 @@ class LibvirtConfigGuestGraphics(LibvirtConfigGuestDevice): return dev -class LibvirtConfigGuestChar(LibvirtConfigGuestDevice): +class LibvirtConfigGuestCharBase(LibvirtConfigGuestDevice): def __init__(self, **kwargs): - super(LibvirtConfigGuestChar, self).__init__(**kwargs) + super(LibvirtConfigGuestCharBase, 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 = 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.target_port = None + + def format_dom(self): + dev = super(LibvirtConfigGuestChar, self).format_dom() + 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): -- cgit