[Pkg-libvirt-commits] [libguestfs] 20/40: v2v: Move some utility functions into Lib_ovf module.

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:44:44 UTC 2014


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

bengen pushed a commit to annotated tag debian/1%1.27.44-1
in repository libguestfs.

commit 4c25f48bbad353ac6b0cc32f4174d2b4923d1f28
Author: Richard W.M. Jones <rjones at redhat.com>
Date:   Thu Sep 11 16:21:16 2014 +0100

    v2v: Move some utility functions into Lib_ovf module.
    
    This is just code refactoring and has no functional effect.
---
 po/POTFILES-ml     |   1 +
 v2v/Makefile.am    |   2 +
 v2v/lib_ovf.ml     | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 v2v/lib_ovf.mli    |  34 ++++++++++++++
 v2v/output_rhev.ml | 113 +-------------------------------------------
 5 files changed, 175 insertions(+), 111 deletions(-)

diff --git a/po/POTFILES-ml b/po/POTFILES-ml
index 81de7a0..fab73ee 100644
--- a/po/POTFILES-ml
+++ b/po/POTFILES-ml
@@ -94,6 +94,7 @@ v2v/input_libvirtxml.ml
 v2v/input_ova.ml
 v2v/lib_esx.ml
 v2v/lib_linux.ml
+v2v/lib_ovf.ml
 v2v/lib_xen.ml
 v2v/modules_list.ml
 v2v/output_glance.ml
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index 31db829..3e84f3c 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -38,6 +38,7 @@ SOURCES_MLI = \
 	JSON.mli \
 	lib_esx.mli \
 	lib_linux.mli \
+	lib_ovf.mli \
 	lib_xen.mli \
 	modules_list.mli \
 	output_glance.mli \
@@ -58,6 +59,7 @@ SOURCES_ML = \
 	JSON.ml \
 	lib_esx.ml \
 	lib_xen.ml \
+	lib_ovf.ml \
 	lib_linux.ml \
 	modules_list.ml \
 	input_disk.ml \
diff --git a/v2v/lib_ovf.ml b/v2v/lib_ovf.ml
new file mode 100644
index 0000000..e7c98c0
--- /dev/null
+++ b/v2v/lib_ovf.ml
@@ -0,0 +1,136 @@
+(* virt-v2v
+ * Copyright (C) 2009-2014 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+(* Functions for dealing with OVF files. *)
+
+open Common_gettext.Gettext
+open Common_utils
+
+open Types
+open Utils
+
+open Printf
+
+(* Guess vmtype based on the guest inspection data.  This is used
+ * when the [--vmtype] parameter is NOT passed.
+ *)
+let ovf_vmtype = function
+  | { i_type = "linux"; i_distro = "rhel"; i_major_version = major;
+      i_product_name = product }
+      when major >= 5 && string_find product "Server" >= 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_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 *)
+
+  | { 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 = "windows"; i_major_version = 6; i_minor_version = 0 } ->
+    `Desktop                            (* Vista *)
+
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 1;
+      i_product_name = product } when string_find product "Server" >= 0 ->
+    `Server                             (* Windows 2008R2 *)
+
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 1 } ->
+    `Server                             (* Windows 7 *)
+
+  | _ -> `Server
+
+(* Determine the ovf:OperatingSystemSection_Type from libguestfs inspection. *)
+and ovf_ostype = function
+  | { i_type = "linux"; i_distro = "rhel"; i_major_version = v;
+      i_arch = "i386" } ->
+    sprintf "RHEL%d" v
+
+  | { i_type = "linux"; i_distro = "rhel"; i_major_version = v;
+      i_arch = "x86_64" } ->
+    sprintf "RHEL%dx64" v
+
+  | { i_type = "linux" } -> "OtherLinux"
+
+  | { i_type = "windows"; i_major_version = 5; i_minor_version = 1 } ->
+    "WindowsXP" (* no architecture differentiation of XP on RHEV *)
+
+  | { i_type = "windows"; i_major_version = 5; i_minor_version = 2;
+      i_product_name = product } when string_find product "XP" >= 0 ->
+    "WindowsXP" (* no architecture differentiation of XP on RHEV *)
+
+  | { i_type = "windows"; i_major_version = 5; i_minor_version = 2;
+      i_arch = "i386" } ->
+    "Windows2003"
+
+  | { i_type = "windows"; i_major_version = 5; i_minor_version = 2;
+      i_arch = "x86_64" } ->
+    "Windows2003x64"
+
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 0;
+      i_arch = "i386" } ->
+    "Windows2008"
+
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 0;
+      i_arch = "x86_64" } ->
+    "Windows2008x64"
+
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 1;
+      i_arch = "i386" } ->
+    "Windows7"
+
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 1;
+      i_arch = "x86_64"; i_product_variant = "Client" } ->
+    "Windows7x64"
+
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 1;
+      i_arch = "x86_64" } ->
+    "Windows2008R2x64"
+
+  | { i_type = typ; i_distro = distro;
+      i_major_version = major; i_minor_version = minor;
+      i_product_name = product } ->
+    warning ~prog (f_"unknown guest operating system: %s %s %d.%d (%s)")
+      typ distro major minor product;
+    "Unassigned"
diff --git a/v2v/lib_ovf.mli b/v2v/lib_ovf.mli
new file mode 100644
index 0000000..59eced7
--- /dev/null
+++ b/v2v/lib_ovf.mli
@@ -0,0 +1,34 @@
+(* virt-v2v
+ * Copyright (C) 2009-2014 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+(** Functions for dealing with OVF files. *)
+
+open Common_gettext.Gettext
+open Common_utils
+
+open Utils
+
+open Printf
+
+val ovf_vmtype : Types.inspect -> [`Server|`Desktop]
+(** Guess vmtype based on the guest inspection data.  This is used
+    when the [--vmtype] parameter is NOT passed. *)
+
+val ovf_ostype : Types.inspect -> string
+(** Determine the ovf:OperatingSystemSection_Type from libguestfs
+    inspection. *)
diff --git a/v2v/output_rhev.ml b/v2v/output_rhev.ml
index bfcb0cc..854ff20 100644
--- a/v2v/output_rhev.ml
+++ b/v2v/output_rhev.ml
@@ -55,115 +55,6 @@ let iso_time =
     (tm.tm_year + 1900) (tm.tm_mon + 1) tm.tm_mday
     tm.tm_hour tm.tm_min tm.tm_sec
 
-(* Guess vmtype based on the guest inspection data.  This is used
- * when the [--vmtype] parameter is NOT passed.
- *)
-let get_vmtype = function
-  | { i_type = "linux"; i_distro = "rhel"; i_major_version = major;
-      i_product_name = product }
-      when major >= 5 && string_find product "Server" >= 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_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 *)
-
-  | { 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 = "windows"; i_major_version = 6; i_minor_version = 0 } ->
-    `Desktop                            (* Vista *)
-
-  | { i_type = "windows"; i_major_version = 6; i_minor_version = 1;
-      i_product_name = product } when string_find product "Server" >= 0 ->
-    `Server                             (* Windows 2008R2 *)
-
-  | { i_type = "windows"; i_major_version = 6; i_minor_version = 1 } ->
-    `Server                             (* Windows 7 *)
-
-  | _ -> `Server
-
-(* Determine the ovf:OperatingSystemSection_Type from libguestfs inspection. *)
-and get_ostype = function
-  | { i_type = "linux"; i_distro = "rhel"; i_major_version = v;
-      i_arch = "i386" } ->
-    sprintf "RHEL%d" v
-
-  | { i_type = "linux"; i_distro = "rhel"; i_major_version = v;
-      i_arch = "x86_64" } ->
-    sprintf "RHEL%dx64" v
-
-  | { i_type = "linux" } -> "OtherLinux"
-
-  | { i_type = "windows"; i_major_version = 5; i_minor_version = 1 } ->
-    "WindowsXP" (* no architecture differentiation of XP on RHEV *)
-
-  | { i_type = "windows"; i_major_version = 5; i_minor_version = 2;
-      i_product_name = product } when string_find product "XP" >= 0 ->
-    "WindowsXP" (* no architecture differentiation of XP on RHEV *)
-
-  | { i_type = "windows"; i_major_version = 5; i_minor_version = 2;
-      i_arch = "i386" } ->
-    "Windows2003"
-
-  | { i_type = "windows"; i_major_version = 5; i_minor_version = 2;
-      i_arch = "x86_64" } ->
-    "Windows2003x64"
-
-  | { i_type = "windows"; i_major_version = 6; i_minor_version = 0;
-      i_arch = "i386" } ->
-    "Windows2008"
-
-  | { i_type = "windows"; i_major_version = 6; i_minor_version = 0;
-      i_arch = "x86_64" } ->
-    "Windows2008x64"
-
-  | { i_type = "windows"; i_major_version = 6; i_minor_version = 1;
-      i_arch = "i386" } ->
-    "Windows7"
-
-  | { i_type = "windows"; i_major_version = 6; i_minor_version = 1;
-      i_arch = "x86_64"; i_product_variant = "Client" } ->
-    "Windows7x64"
-
-  | { i_type = "windows"; i_major_version = 6; i_minor_version = 1;
-      i_arch = "x86_64" } ->
-    "Windows2008R2x64"
-
-  | { i_type = typ; i_distro = distro;
-      i_major_version = major; i_minor_version = minor;
-      i_product_name = product } ->
-    warning ~prog (f_"unknown guest operating system: %s %s %d.%d (%s)")
-      typ distro major minor product;
-    "Unassigned"
-
 class output_rhev verbose os rhev_params output_alloc =
 object
   inherit output verbose
@@ -614,9 +505,9 @@ object
     let vmtype =
       match rhev_params.vmtype with
       | Some vmtype -> vmtype
-      | None -> get_vmtype inspect in
+      | None -> Lib_ovf.ovf_vmtype inspect in
     let vmtype = match vmtype with `Desktop -> "DESKTOP" | `Server -> "SERVER" in
-    let ostype = get_ostype inspect in
+    let ostype = Lib_ovf.ovf_ostype inspect in
 
     let ovf : doc =
       doc "ovf:Envelope" [

-- 
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