diff options
author | Daniel P. Berrange <berrange@redhat.com> | 2012-12-18 11:31:40 +0000 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2013-01-16 10:19:37 +0000 |
commit | a41f4c96ca5f1d8323c5631b9a0eab4de3e2001e (patch) | |
tree | 951d7426d51acea94218776f13606eaa44be0943 | |
parent | 5873dbd6b19db0b6b8f69f226ffaef9efa80fcb9 (diff) | |
download | nova-a41f4c96ca5f1d8323c5631b9a0eab4de3e2001e.tar.gz nova-a41f4c96ca5f1d8323c5631b9a0eab4de3e2001e.tar.xz nova-a41f4c96ca5f1d8323c5631b9a0eab4de3e2001e.zip |
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>
-rw-r--r-- | nova/tests/test_libvirt_config.py | 23 | ||||
-rw-r--r-- | 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): <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() 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): |