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

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