[Pkg-libvirt-commits] [libguestfs] 105/146: v2v: Reduce use of polymorphic variants.

Hilko Bengen bengen at moszumanska.debian.org
Sun Mar 29 17:01:11 UTC 2015


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch master
in repository libguestfs.

commit f121dee1c32975f73de9130c6c56685cf8697912
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Wed Dec 24 18:10:37 2014 +0000

    v2v: Reduce use of polymorphic variants.
    
    Ordinary variants prevent coding errors.
    
    (cherry picked from commit 3a080c3fbffa5846f71528c6fd978be7853b33b8)
---
 v2v/convert_linux.ml    |  6 +++---
 v2v/input_disk.ml       |  2 +-
 v2v/input_libvirtxml.ml | 20 ++++++++++----------
 v2v/input_ova.ml        |  8 ++++----
 v2v/output_libvirt.ml   |  4 ++--
 v2v/output_qemu.ml      |  6 +++---
 v2v/types.ml            | 18 ++++++++++--------
 v2v/types.mli           | 13 ++++++++-----
 8 files changed, 41 insertions(+), 36 deletions(-)

diff --git a/v2v/convert_linux.ml b/v2v/convert_linux.ml
index b689c5f..378cbad 100644
--- a/v2v/convert_linux.ml
+++ b/v2v/convert_linux.ml
@@ -1274,9 +1274,9 @@ let rec convert ~verbose ~keep_serial_console (g : G.guestfs) inspect source =
         fun i disk ->
           let block_prefix_before_conversion =
             match disk.s_controller with
-            | Some `IDE -> ide_block_prefix
-            | Some `SCSI -> "sd"
-            | Some `Virtio_blk -> "vd"
+            | Some Source_IDE -> ide_block_prefix
+            | Some Source_SCSI -> "sd"
+            | Some Source_virtio_blk -> "vd"
             | None ->
               (* This is basically a guess.  It assumes the source used IDE. *)
               ide_block_prefix in
diff --git a/v2v/input_disk.ml b/v2v/input_disk.ml
index 3c9c1cf..730d534 100644
--- a/v2v/input_disk.ml
+++ b/v2v/input_disk.ml
@@ -86,7 +86,7 @@ class input_disk verbose input_format disk = object
       s_vcpu = 1;                         (* 1 vCPU is a safe default *)
       s_features = [ "acpi"; "apic"; "pae" ];
       s_display =
-        Some { s_display_type = `Window; s_keymap = None; s_password = None };
+        Some { s_display_type = Window; s_keymap = None; s_password = None };
       s_disks = [disk];
       s_removables = [];
       s_nics = [network];
diff --git a/v2v/input_libvirtxml.ml b/v2v/input_libvirtxml.ml
index b0430b2..b8c55c7 100644
--- a/v2v/input_libvirtxml.ml
+++ b/v2v/input_libvirtxml.ml
@@ -98,10 +98,10 @@ let parse_libvirt_xml ~verbose xml =
       match xpath_to_string "@type" "" with
       | "" -> None
       | "vnc" ->
-        Some { s_display_type = `VNC;
+        Some { s_display_type = VNC;
                s_keymap = keymap; s_password = password }
       | "spice" ->
-        Some { s_display_type = `Spice;
+        Some { s_display_type = Spice;
                s_keymap = keymap; s_password = password }
       | "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;
@@ -140,9 +140,9 @@ let parse_libvirt_xml ~verbose xml =
         let target_bus = xpath_to_string "target/@bus" "" in
         match target_bus with
         | "" -> None
-        | "ide" -> Some `IDE
-        | "scsi" -> Some `SCSI
-        | "virtio" -> Some `Virtio_blk
+        | "ide" -> Some Source_IDE
+        | "scsi" -> Some Source_SCSI
+        | "virtio" -> Some Source_virtio_blk
         | _ -> None in
 
       let format =
@@ -200,15 +200,15 @@ let parse_libvirt_xml ~verbose xml =
         let target_bus = xpath_to_string "target/@bus" "" in
         match target_bus with
         | "" -> None
-        | "ide" -> Some `IDE
-        | "scsi" -> Some `SCSI
-        | "virtio" -> Some `Virtio_blk
+        | "ide" -> Some Source_IDE
+        | "scsi" -> Some Source_SCSI
+        | "virtio" -> Some Source_virtio_blk
         | _ -> None in
 
       let typ =
         match xpath_to_string "@device" "" with
-        | "cdrom" -> `CDROM
-        | "floppy" -> `Floppy
+        | "cdrom" -> CDROM
+        | "floppy" -> Floppy
         | _ -> assert false (* libxml2 error? *) in
 
       let disk =
diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml
index b26ce65..e7de110 100644
--- a/v2v/input_ova.ml
+++ b/v2v/input_ova.ml
@@ -167,8 +167,8 @@ object
 
       (* 6: iscsi controller, 5: ide *)
       match controller with
-      | 6 -> Some `SCSI
-      | 5 -> Some `IDE
+      | 6 -> Some Source_SCSI
+      | 5 -> Some Source_IDE
       | 0 ->
         warning (f_"ova disk has no parent controller, please report this as a bug supplying the *.ovf file extracted from the ova");
         None
@@ -272,8 +272,8 @@ object
 
         let typ =
           match id with
-            | 14 -> `Floppy
-            | 15 | 16 -> `CDROM
+            | 14 -> Floppy
+            | 15 | 16 -> CDROM
             | _ -> assert false in
         let disk = {
           s_removable_type = typ;
diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml
index 6445819..6048676 100644
--- a/v2v/output_libvirt.ml
+++ b/v2v/output_libvirt.ml
@@ -150,7 +150,7 @@ let create_libvirt_xml ?pool source targets guestcaps target_features =
 
     List.map (
       function
-      | { s_removable_type = `CDROM } ->
+      | { s_removable_type = CDROM } ->
         let i = !cdrom_index in
         incr cdrom_index;
         let name = cdrom_block_prefix ^ drive_name i in
@@ -159,7 +159,7 @@ let create_libvirt_xml ?pool source targets guestcaps target_features =
           e "target" [ "dev", name; "bus", cdrom_bus ] []
         ]
 
-      | { s_removable_type = `Floppy } ->
+      | { s_removable_type = Floppy } ->
         let i = !fd_index in
         incr fd_index;
         let name = "fd" ^ drive_name i in
diff --git a/v2v/output_qemu.ml b/v2v/output_qemu.ml
index de5c813..15ff667 100644
--- a/v2v/output_qemu.ml
+++ b/v2v/output_qemu.ml
@@ -90,11 +90,11 @@ object
     | None -> ()
     | Some display ->
       (match display.s_display_type with
-      | `Window ->
+      | Window ->
         fpf "%s-display gtk" nl
-      | `VNC ->
+      | VNC ->
         fpf "%s-display vnc=:0" nl
-      | `Spice ->
+      | Spice ->
         fpf "%s-spice port=5900,addr=127.0.0.1" nl
       );
       fpf "%s-vga %s" nl
diff --git a/v2v/types.ml b/v2v/types.ml
index dbc464b..a0fbedb 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -45,11 +45,12 @@ and source_disk = {
   s_format : string option;
   s_controller : s_controller option;
 }
-and s_controller = [`IDE | `SCSI | `Virtio_blk]
+and s_controller = Source_IDE | Source_SCSI | Source_virtio_blk
 and source_removable = {
-  s_removable_type : [`CDROM|`Floppy];
+  s_removable_type : s_removable_type;
   s_removable_controller : s_controller option;
 }
+and s_removable_type = CDROM | Floppy
 and source_nic = {
   s_mac : string option;
   s_vnet : string;
@@ -58,10 +59,11 @@ and source_nic = {
 }
 and vnet_type = Bridge | Network
 and source_display = {
-  s_display_type : [`Window|`VNC|`Spice];
+  s_display_type : s_display_type;
   s_keymap : string option;
   s_password : string option;
 }
+and s_display_type = Window | VNC | Spice
 
 let rec string_of_source s =
   sprintf "    source name: %s
@@ -139,14 +141,14 @@ and string_of_source_disk { s_qemu_uri = qemu_uri; s_format = format;
     | Some controller -> " [" ^ string_of_controller controller ^ "]")
 
 and string_of_controller = function
-  | `IDE -> "ide"
-  | `SCSI -> "scsi"
-  | `Virtio_blk -> "virtio"
+  | Source_IDE -> "ide"
+  | Source_SCSI -> "scsi"
+  | Source_virtio_blk -> "virtio"
 
 and string_of_source_removable { s_removable_type = typ;
                                  s_removable_controller = controller } =
   sprintf "\t%s%s"
-    (match typ with `CDROM -> "CD-ROM" | `Floppy -> "Floppy")
+    (match typ with CDROM -> "CD-ROM" | Floppy -> "Floppy")
     (match controller with
     | None -> ""
     | Some controller -> " [" ^ string_of_controller controller ^ "]")
@@ -162,7 +164,7 @@ and string_of_source_nic { s_mac = mac; s_vnet = vnet; s_vnet_type = typ } =
 and string_of_source_display { s_display_type = typ;
                                s_keymap = keymap; s_password = password } =
   sprintf "%s%s%s"
-    (match typ with `Window -> "window" | `VNC -> "vnc" | `Spice -> "spice")
+    (match typ with Window -> "window" | VNC -> "vnc" | Spice -> "spice")
     (match keymap with None -> "" | Some km -> " " ^ km)
     (match password with None -> "" | Some _ -> " with password")
 
diff --git a/v2v/types.mli b/v2v/types.mli
index ee7394a..0608db0 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -53,19 +53,21 @@ and source_disk = {
 }
 (** A source disk. *)
 
-and s_controller = [`IDE | `SCSI | `Virtio_blk]
+and s_controller = Source_IDE | Source_SCSI | Source_virtio_blk
 (** Source disk controller.
 
     For the purposes of this field, we can treat virtio-scsi as
-    [`SCSI].  However we don't support conversions from virtio in any
+    [SCSI].  However we don't support conversions from virtio in any
     case so virtio is here only to make it work for testing. *)
 
 and source_removable = {
-  s_removable_type : [`CDROM|`Floppy];  (** Type.  *)
+  s_removable_type : s_removable_type;  (** Type.  *)
   s_removable_controller : s_controller option; (** Controller, eg. IDE, SCSI.*)
 }
 (** Removable media. *)
 
+and s_removable_type = CDROM | Floppy
+
 and source_nic = {
   s_mac : string option;                (** MAC address. *)
   s_vnet : string;                      (** Source network name. *)
@@ -76,11 +78,12 @@ and source_nic = {
 and vnet_type = Bridge | Network
 
 and source_display = {
-  s_display_type : [`Window|`VNC|`Spice]; (** Display type. *)
-  s_keymap : string option;               (** Guest keymap. *)
+  s_display_type : s_display_type; (** Display type. *)
+  s_keymap : string option;        (** Guest keymap. *)
   s_password : string option;      (** If required, password to access
                                        the display. *)
 }
+and s_display_type = Window | VNC | Spice
 
 val string_of_source : source -> string
 val string_of_source_disk : source_disk -> string

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list