[Libguestfs] [PATCH] v2v: convert libvirt display port configuration

Pino Toscano ptoscano at redhat.com
Tue Apr 14 11:24:54 UTC 2015


Read the port configuration from the XML of libvirt domains, restoring
it when writing new libvirt XMLs instead of always setting the
"autoport" option.
---
 v2v/input_disk.ml       |  2 +-
 v2v/input_libvirtxml.ml | 13 +++++++++++--
 v2v/output_libvirt.ml   |  8 +++++++-
 v2v/output_qemu.ml      |  3 ++-
 v2v/types.ml            |  1 +
 v2v/types.mli           |  1 +
 6 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/v2v/input_disk.ml b/v2v/input_disk.ml
index 2c70368..40bd783 100644
--- a/v2v/input_disk.ml
+++ b/v2v/input_disk.ml
@@ -87,7 +87,7 @@ class input_disk verbose input_format disk = object
       s_features = [ "acpi"; "apic"; "pae" ];
       s_display =
         Some { s_display_type = Window; s_keymap = None; s_password = None;
-               s_listen = LNone };
+               s_listen = LNone; s_port = None };
       s_disks = [disk];
       s_removables = [];
       s_nics = [network];
diff --git a/v2v/input_libvirtxml.ml b/v2v/input_libvirtxml.ml
index 4fb6358..2e8fa1f 100644
--- a/v2v/input_libvirtxml.ml
+++ b/v2v/input_libvirtxml.ml
@@ -117,14 +117,23 @@ let parse_libvirt_xml ~verbose xml =
             warning (f_"<listen type='%s'> in the input libvirt XML was ignored") t;
             LNone
         ) in
+      let port =
+        match xpath_to_string "@autoport" "yes" with
+        | "no" ->
+          let port = xpath_to_int "@port" (-1) in
+          if port >= 0 then Some port
+          else None
+        | _ -> None in
       match xpath_to_string "@type" "" with
       | "" -> None
       | "vnc" ->
         Some { s_display_type = VNC;
-               s_keymap = keymap; s_password = password; s_listen = listen }
+               s_keymap = keymap; s_password = password; s_listen = listen;
+               s_port = port }
       | "spice" ->
         Some { s_display_type = Spice;
-               s_keymap = keymap; s_password = password; s_listen = listen }
+               s_keymap = keymap; s_password = password; s_listen = listen;
+               s_port = port }
       | "sdl"|"desktop" as t ->
         warning (f_"virt-v2v does not support local displays, so <graphics type='%s'> in the input libvirt XML was ignored") t;
         None
diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml
index 64dc2dc..fc083d3 100644
--- a/v2v/output_libvirt.ml
+++ b/v2v/output_libvirt.ml
@@ -222,7 +222,6 @@ let create_libvirt_xml ?pool source targets guestcaps target_features =
 
     append_attr ("heads", "1") video;
 
-    append_attr ("autoport", "yes") graphics;
     (match source.s_display with
     | Some { s_keymap = Some km } -> append_attr ("keymap", km) graphics
     | _ -> ());
@@ -240,6 +239,13 @@ let create_libvirt_xml ?pool source targets guestcaps target_features =
         append_child sub graphics
       | LNone -> ())
     | _ -> ());
+    (match source.s_display with
+    | Some { s_port = Some p } ->
+      append_attr ("autoport", "no") graphics;
+      append_attr ("port", string_of_int p) graphics
+    | _ ->
+      append_attr ("autoport", "yes") graphics;
+      append_attr ("port", "-1") graphics);
 
     video, graphics in
 
diff --git a/v2v/output_qemu.ml b/v2v/output_qemu.ml
index c3f64d1..d9a10b1 100644
--- a/v2v/output_qemu.ml
+++ b/v2v/output_qemu.ml
@@ -95,7 +95,8 @@ object
       | VNC ->
         fpf "%s-display vnc=:0" nl
       | Spice ->
-        fpf "%s-spice port=5900,addr=127.0.0.1" nl
+        fpf "%s-spice port=%d,addr=127.0.0.1" nl
+        (match display.s_port with None -> 5900 | Some p -> p)
       );
       fpf "%s-vga %s" nl
         (match guestcaps.gcaps_video with Cirrus -> "cirrus" | QXL -> "qxl")
diff --git a/v2v/types.ml b/v2v/types.ml
index 9e4fa35..633fe3f 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -63,6 +63,7 @@ and source_display = {
   s_keymap : string option;
   s_password : string option;
   s_listen : s_display_listen;
+  s_port : int option;
 }
 and s_display_type = Window | VNC | Spice
 and s_display_listen =
diff --git a/v2v/types.mli b/v2v/types.mli
index a3c1fd4..a1ec4ba 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -83,6 +83,7 @@ and source_display = {
   s_password : string option;      (** If required, password to access
                                        the display. *)
   s_listen : s_display_listen;     (** Listen address. *)
+  s_port : int option;             (** Display port. *)
 }
 and s_display_type = Window | VNC | Spice
 and s_display_listen =
-- 
2.1.0




More information about the Libguestfs mailing list