mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0010-v2v-OVF-write-ovirt-id-attribute-for-the-OS-in-OVirt.patch

d0ea73
From 1b4c00a3ec7c0618e8557e1e71d5782527a94828 Mon Sep 17 00:00:00 2001
d0ea73
From: Pino Toscano <ptoscano@redhat.com>
d0ea73
Date: Wed, 4 Apr 2018 18:18:32 +0200
d0ea73
Subject: [PATCH] v2v: OVF: write ovirt:id attribute for the OS in OVirt
d0ea73
 flavour
d0ea73
d0ea73
When writing the OVF in OVirt flavour, add a ovirt:id attribute to the
d0ea73
OperatingSystemSection tag: this attribute represents the numeric value
d0ea73
of the ostype ID, which is ignored by oVirt when parsing OVFs in API
d0ea73
mode.
d0ea73
d0ea73
(cherry picked from commit 593a19cc86cfa8f24c66518c8ba21222550b066a)
d0ea73
---
d0ea73
 v2v/create_ovf.ml | 202 +++++++++++++++++++++++++++++++++++++++++++++-
d0ea73
 1 file changed, 201 insertions(+), 1 deletion(-)
d0ea73
d0ea73
diff --git a/v2v/create_ovf.ml b/v2v/create_ovf.ml
d0ea73
index 0e07afea8..730ab64b4 100644
d0ea73
--- a/v2v/create_ovf.ml
d0ea73
+++ b/v2v/create_ovf.ml
d0ea73
@@ -242,6 +242,203 @@ and get_ostype = function
d0ea73
       typ distro major minor arch product;
d0ea73
     "Unassigned"
d0ea73
 
d0ea73
+(* Determine the ovirt:id attribute from libguestfs inspection.
d0ea73
+ * See ovirt-engine sources, file:
d0ea73
+ *   packaging/conf/osinfo-defaults.properties
d0ea73
+ * and also:
d0ea73
+ *   https://bugzilla.redhat.com/show_bug.cgi?id=1219857#c9
d0ea73
+ *)
d0ea73
+and get_ovirt_osid = function
d0ea73
+  | { i_type = "linux"; i_distro = ("rhel"|"centos"); i_major_version = 3;
d0ea73
+      i_arch = "i386" } ->
d0ea73
+    9
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = ("rhel"|"centos"); i_major_version = 3;
d0ea73
+      i_arch = "x86_64" } ->
d0ea73
+    15
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = ("rhel"|"centos"); i_major_version = 4;
d0ea73
+      i_arch = "i386" } ->
d0ea73
+    8
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = ("rhel"|"centos"); i_major_version = 4;
d0ea73
+      i_arch = "x86_64" } ->
d0ea73
+    14
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = ("rhel"|"centos"); i_major_version = 5;
d0ea73
+      i_arch = "i386" } ->
d0ea73
+    7
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = ("rhel"|"centos"); i_major_version = 5;
d0ea73
+      i_arch = "x86_64" } ->
d0ea73
+    13
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = ("rhel"|"centos"); i_major_version = 6;
d0ea73
+      i_arch = "i386" } ->
d0ea73
+    18
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = ("rhel"|"centos"); i_major_version = 6;
d0ea73
+      i_arch = "x86_64" } ->
d0ea73
+    19
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = ("rhel"|"centos"); i_major_version = 6;
d0ea73
+      i_minor_version = min; i_arch = ("ppc64"|"ppc64le") } when min >= 9 ->
d0ea73
+    1007
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = ("rhel"|"centos"); i_major_version = 6;
d0ea73
+      i_arch = ("ppc64"|"ppc64le") } ->
d0ea73
+    1003
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = ("rhel"|"centos"); i_major_version = 7;
d0ea73
+      i_arch = "x86_64" } ->
d0ea73
+    24
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = ("rhel"|"centos"); i_major_version = 7;
d0ea73
+      i_arch = ("ppc64"|"ppc64le") } ->
d0ea73
+    1006
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = ("rhel"|"centos"); i_major_version = 7;
d0ea73
+      i_arch = "s390x" } ->
d0ea73
+    2003
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = "sles"; i_major_version = maj;
d0ea73
+      i_arch = "x86_64" } when maj >= 11 ->
d0ea73
+    1193
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = "sles"; i_major_version = maj;
d0ea73
+      i_arch = ("ppc64"|"ppc64le") } when maj >= 11 ->
d0ea73
+    1004
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = "sles"; i_major_version = maj;
d0ea73
+      i_arch = "s390x" } when maj >= 12 ->
d0ea73
+    2004
d0ea73
+
d0ea73
+   (* Only Debian 7 is available, so use it for any 7+ version. *)
d0ea73
+  | { i_type = "linux"; i_distro = "debian"; i_major_version = v }
d0ea73
+      when v >= 7 ->
d0ea73
+    1300
d0ea73
+
d0ea73
+   (* Only Ubuntu 12.04 to 14.04 are available, so use them starting
d0ea73
+    * from 12.04, and 14.04 for anything after it.
d0ea73
+    *)
d0ea73
+  | { i_type = "linux"; i_distro = "ubuntu"; i_major_version = v;
d0ea73
+      i_arch = ("ppc64"|"ppc64le") } when v >= 14 ->
d0ea73
+    1005
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = "ubuntu"; i_major_version = v;
d0ea73
+      i_arch = "s390x" } when v >= 16 ->
d0ea73
+    2005
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = "ubuntu"; i_major_version = v }
d0ea73
+      when v >= 14 ->
d0ea73
+    1256
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = "ubuntu"; i_major_version = 12;
d0ea73
+      i_minor_version = 4 } ->
d0ea73
+    1252
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = "ubuntu"; i_major_version = 12;
d0ea73
+      i_minor_version = 10 } ->
d0ea73
+    1253
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = "ubuntu"; i_major_version = 13;
d0ea73
+      i_minor_version = 4 } ->
d0ea73
+    1254
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_distro = "ubuntu"; i_major_version = 13;
d0ea73
+      i_minor_version = 10 } ->
d0ea73
+    1255
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_arch = ("ppc64"|"ppc64le") } ->
d0ea73
+    1002
d0ea73
+
d0ea73
+  | { i_type = "linux"; i_arch = "s390x" } ->
d0ea73
+    2002
d0ea73
+
d0ea73
+  | { i_type = "linux" } ->
d0ea73
+    5
d0ea73
+
d0ea73
+  | { i_type = "windows"; i_major_version = 5; i_minor_version = 1 } ->
d0ea73
+    1 (* no architecture differentiation of XP on RHV *)
d0ea73
+
d0ea73
+  | { i_type = "windows"; i_major_version = 5; i_minor_version = 2;
d0ea73
+      i_product_name = product } when String.find product "XP" >= 0 ->
d0ea73
+    1 (* no architecture differentiation of XP on RHV *)
d0ea73
+
d0ea73
+  | { i_type = "windows"; i_major_version = 5; i_minor_version = 2;
d0ea73
+      i_arch = "i386" } ->
d0ea73
+    3
d0ea73
+
d0ea73
+  | { i_type = "windows"; i_major_version = 5; i_minor_version = 2;
d0ea73
+      i_arch = "x86_64" } ->
d0ea73
+    10
d0ea73
+
d0ea73
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 0;
d0ea73
+      i_arch = "i386" } ->
d0ea73
+    4
d0ea73
+
d0ea73
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 0;
d0ea73
+      i_arch = "x86_64" } ->
d0ea73
+    16
d0ea73
+
d0ea73
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 1;
d0ea73
+      i_arch = "i386" } ->
d0ea73
+    11
d0ea73
+
d0ea73
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 1;
d0ea73
+      i_arch = "x86_64"; i_product_variant = "Client" } ->
d0ea73
+    12
d0ea73
+
d0ea73
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 1;
d0ea73
+      i_arch = "x86_64" } ->
d0ea73
+    17
d0ea73
+
d0ea73
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 2;
d0ea73
+      i_arch = "i386" } ->
d0ea73
+    20
d0ea73
+
d0ea73
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 2;
d0ea73
+      i_arch = "x86_64"; i_product_variant = "Client" } ->
d0ea73
+    21
d0ea73
+
d0ea73
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 2;
d0ea73
+      i_arch = "x86_64" } ->
d0ea73
+    23
d0ea73
+
d0ea73
+   (* Treat Windows 8.1 client like Windows 8.  See:
d0ea73
+    * https://bugzilla.redhat.com/show_bug.cgi?id=1309580#c4
d0ea73
+    *)
d0ea73
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 3;
d0ea73
+      i_arch = "i386"; i_product_variant = "Client" } ->
d0ea73
+    20
d0ea73
+
d0ea73
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 3;
d0ea73
+      i_arch = "x86_64"; i_product_variant = "Client" } ->
d0ea73
+    21
d0ea73
+
d0ea73
+  | { i_type = "windows"; i_major_version = 6; i_minor_version = 3;
d0ea73
+      i_arch = "x86_64" } ->
d0ea73
+    23
d0ea73
+
d0ea73
+  | { i_type = "windows"; i_major_version = 10; i_minor_version = 0;
d0ea73
+      i_arch = "i386" } ->
d0ea73
+    26
d0ea73
+
d0ea73
+  | { i_type = "windows"; i_major_version = 10; i_minor_version = 0;
d0ea73
+      i_arch = "x86_64"; i_product_variant = "Client" } ->
d0ea73
+    27
d0ea73
+
d0ea73
+  | { i_type = "windows"; i_major_version = 10; i_minor_version = 0;
d0ea73
+      i_arch = "x86_64" } ->
d0ea73
+    29
d0ea73
+
d0ea73
+  | { i_type = typ; i_distro = distro;
d0ea73
+      i_major_version = major; i_minor_version = minor; i_arch = arch;
d0ea73
+      i_product_name = product } ->
d0ea73
+    warning (f_"unknown guest operating system: %s %s %d.%d %s (%s)")
d0ea73
+      typ distro major minor arch product;
d0ea73
+    0
d0ea73
+
d0ea73
 (* Set the <Origin/> element based on the source hypervisor.
d0ea73
  * https://bugzilla.redhat.com/show_bug.cgi?id=1342398#c6
d0ea73
  * https://gerrit.ovirt.org/#/c/59147/
d0ea73
@@ -321,6 +518,7 @@ let rec create_ovf source targets guestcaps inspect
d0ea73
       "xmlns:vssd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData";
d0ea73
       "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance";
d0ea73
       "xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1/";
d0ea73
+      "xmlns:ovirt", "http://www.ovirt.org/ovf";
d0ea73
       "ovf:version", "0.9"
d0ea73
     ] [
d0ea73
       Comment generated_by;
d0ea73
@@ -383,8 +581,10 @@ let rec create_ovf source targets guestcaps inspect
d0ea73
         ] in
d0ea73
         (match ovf_flavour with
d0ea73
         | OVirt ->
d0ea73
+          let ovirt_osid = get_ovirt_osid inspect in
d0ea73
           e "OperatingSystemSection" ["ovf:id", vm_uuid;
d0ea73
-                                      "ovf:required", "false"]
d0ea73
+                                      "ovf:required", "false";
d0ea73
+                                      "ovirt:id", string_of_int ovirt_osid]
d0ea73
             osinfo_subnodes
d0ea73
         | RHVExportStorageDomain ->
d0ea73
           e "Section" ["ovf:id", vm_uuid; "ovf:required", "false";
d0ea73
-- 
6b9fda
2.21.0
d0ea73