According to
https://libvirt.org/formatdomain.html only vnc and sdl
graphics types support port/autoport.
In addition, autoport='yes' is the non-deprecated replacement for
port='-1'. Since we don't need to support ancient libvirt, we don't
need to keep adding port='-1' in the autoport case. virt-xml-validate
rejects our XML if it has both attributes.
---
output/create_libvirt_xml.ml | 22 ++++++++++------------
tests/test-v2v-i-ova.xml | 2 +-
2 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/output/create_libvirt_xml.ml b/output/create_libvirt_xml.ml
index 87bfab178a..93ceb803cc 100644
--- a/output/create_libvirt_xml.ml
+++ b/output/create_libvirt_xml.ml
@@ -435,13 +435,18 @@ let create_libvirt_xml ?pool source inspect
let graphics =
match source.s_display with
- | None -> e "graphics" [ "type", "vnc" ] []
+ | None ->
+ e "graphics" [ "type", "vnc"; "autoport",
"yes" ] []
| Some { s_display_type = Window } ->
e "graphics" [ "type", "sdl" ] []
- | Some { s_display_type = VNC } ->
- e "graphics" [ "type", "vnc" ] []
- | Some { s_display_type = Spice } ->
- e "graphics" [ "type", "spice" ] [] in
+ | Some { s_display_type = VNC; s_port = Some p } ->
+ e "graphics" [ "type", "vnc"; "port",
string_of_int p ] []
+ | Some { s_display_type = VNC; s_port = None } ->
+ e "graphics" [ "type", "vnc"; "autoport",
"yes" ] []
+ | Some { s_display_type = Spice; s_port = Some p } ->
+ e "graphics" [ "type", "spice"; "port",
string_of_int p ] []
+ | Some { s_display_type = Spice; s_port = None } ->
+ e "graphics" [ "type", "spice";
"autoport", "yes" ] [] in
(match source.s_display with
| Some { s_keymap = Some km } -> append_attr ("keymap", km) graphics
@@ -469,13 +474,6 @@ let create_libvirt_xml ?pool source inspect
append_child sub graphics
)
| None -> ());
- (match source.s_display with
- | Some { s_port = Some p } ->
- append_attr ("autoport", "no") graphics;
- append_attr ("port", string_of_int p) graphics
- | Some { s_port = None } | None ->
- append_attr ("autoport", "yes") graphics;
- append_attr ("port", "-1") graphics);
List.push_back devices graphics;
let sound =
diff --git a/tests/test-v2v-i-ova.xml b/tests/test-v2v-i-ova.xml
index 2b6a8de0f4..e72c1db396 100644
--- a/tests/test-v2v-i-ova.xml
+++ b/tests/test-v2v-i-ova.xml
@@ -41,7 +41,7 @@
<video>
<model type='vga' vram='16384' heads='1'/>
</video>
- <graphics type='vnc' autoport='yes' port='-1'/>
+ <graphics type='vnc' autoport='yes'/>
<rng model='virtio-transitional'>
<backend model='random'>/dev/urandom</backend>
</rng>
--
2.32.0