Blob Blame History Raw
From 165d9fbc3bb53daff1c1e1336610fba672a9412a Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 26 Apr 2016 12:27:14 +0100
Subject: [PATCH] v2v: OVF: Better mapping for inspection data to vmtype.

The old mapping code was directly copied from old virt-v2v, translated
from Perl to OCaml.

The new mapping code does a few things more accurately:

 - Use the i_product_variant field (Windows InstallationType) if available.

 - Simplify rules, so there is only one special case needed for RHEL 3/4.

 - Don't assume Fedora == Desktop.

 - Don't assume all later Windows variants are server.

 - Works for Windows > 7.

(cherry picked from commit 5ec42a62384f87a4de841d202e31d0337c64f5af)
---
 v2v/OVF.ml | 61 ++++++++++++++++++++-----------------------------------------
 1 file changed, 20 insertions(+), 41 deletions(-)

diff --git a/v2v/OVF.ml b/v2v/OVF.ml
index 8dc3fea..f1d8de5 100644
--- a/v2v/OVF.ml
+++ b/v2v/OVF.ml
@@ -46,55 +46,34 @@ let iso_time =
  * when the [--vmtype] parameter is NOT passed.
  *)
 let get_vmtype = function
-  | { i_type = "linux"; i_distro = "rhel"; i_major_version = major;
+  (* Special cases for RHEL 3 & RHEL 4. *)
+  | { i_type = "linux"; i_distro = "rhel"; i_major_version = (3|4);
       i_product_name = product }
-      when major >= 5 && String.find product "Server" >= 0 ->
-    Server
+       when String.find product "ES" >= 0 ->
+     Server
 
-  | { i_type = "linux"; i_distro = "rhel"; i_major_version = major }
-      when major >= 5 ->
-    Desktop
-
-  | { i_type = "linux"; i_distro = "rhel"; i_major_version = major;
-      i_product_name = product }
-      when major >= 3 && String.find product "ES" >= 0 ->
-    Server
-
-  | { i_type = "linux"; i_distro = "rhel"; i_major_version = major;
+  | { i_type = "linux"; i_distro = "rhel"; i_major_version = (3|4);
       i_product_name = product }
-      when major >= 3 && String.find product "AS" >= 0 ->
-    Server
-
-  | { i_type = "linux"; i_distro = "rhel"; i_major_version = major }
-      when major >= 3 ->
-    Desktop
-
-  | { i_type = "linux"; i_distro = "fedora" } -> Desktop
-
-  | { i_type = "windows"; i_major_version = 5; i_minor_version = 1 } ->
-    Desktop                            (* Windows XP *)
-
-  | { i_type = "windows"; i_major_version = 5; i_minor_version = 2;
-      i_product_name = product } when String.find product "XP" >= 0 ->
-    Desktop                            (* Windows XP *)
-
-  | { i_type = "windows"; i_major_version = 5; i_minor_version = 2 } ->
-    Server                             (* Windows 2003 *)
+       when String.find product "AS" >= 0 ->
+     Server
 
-  | { i_type = "windows"; i_major_version = 6; i_minor_version = 0;
-      i_product_name = product } when String.find product "Server" >= 0 ->
-    Server                             (* Windows 2008 *)
+  | { i_type = "linux"; i_distro = "rhel"; i_major_version = (3|4) } ->
+     Desktop
 
-  | { i_type = "windows"; i_major_version = 6; i_minor_version = 0 } ->
-    Desktop                            (* Vista *)
+  (* For Windows (and maybe Linux in future, but it is not set now),
+   * use the i_product_variant field.
+   *)
+  | { i_product_variant = ("Server"|"Server Core"|"Embedded") } -> Server
+  | { i_product_variant = "Client" } -> Desktop
 
-  | { i_type = "windows"; i_major_version = 6; i_minor_version = 1;
-      i_product_name = product } when String.find product "Server" >= 0 ->
-    Server                             (* Windows 2008R2 *)
+  (* If the product name has "Server" or "Desktop" in it, use that. *)
+  | { i_product_name = product } when String.find product "Server" >= 0 ->
+     Server
 
-  | { i_type = "windows"; i_major_version = 6; i_minor_version = 1 } ->
-    Server                             (* Windows 7 *)
+  | { i_product_name = product } when String.find product "Desktop" >= 0 ->
+     Desktop
 
+  (* Otherwise return server, a safe choice. *)
   | _ -> Server
 
 (* Determine the ovf:OperatingSystemSection_Type from libguestfs
-- 
1.8.3.1