diff options
-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): |