https://bugzilla.redhat.com/show_bug.cgi?id=1342398#c6
---
v2v/OVF.ml | 138 ++++++++++++++++++++++++++++++++++---------------------------
1 file changed, 76 insertions(+), 62 deletions(-)
diff --git a/v2v/OVF.ml b/v2v/OVF.ml
index 8a6f13e..0599306 100644
--- a/v2v/OVF.ml
+++ b/v2v/OVF.ml
@@ -184,6 +184,15 @@ and get_ostype = function
typ distro major minor arch product;
"Unassigned"
+(* Set the Origin field based on the source hypervisor.
+ *
https://bugzilla.redhat.com/show_bug.cgi?id=1342398#c6
+ *)
+let origin_of_source_hypervisor = function
+ | VMware -> Some 1
+ | Xen -> Some 2
+ | QEmu | KVM -> Some 7
+ | _ -> None
+
(* Generate the .meta file associated with each volume. *)
let create_meta_files output_alloc sd_uuid image_uuids targets =
(* Note: Upper case in the .meta, mixed case in the OVF. *)
@@ -238,11 +247,29 @@ let rec create_ovf source targets guestcaps inspect
let vmtype = match vmtype with `Desktop -> "0" | `Server ->
"1" in
let ostype = get_ostype inspect in
- let origin =
- match source.s_hypervisor with
- | VMware -> 1
- | Xen -> 2
- | _ -> 0 in
+ let content_fields = [
+ e "Name" [] [PCData source.s_name];
+ e "TemplateId" [] [PCData
"00000000-0000-0000-0000-000000000000"];
+ e "TemplateName" [] [PCData "Blank"];
+ e "Description" [] [PCData generated_by];
+ e "Domain" [] [];
+ e "CreationDate" [] [PCData iso_time];
+ e "IsInitilized" (* sic *) [] [PCData "True"];
+ e "IsAutoSuspend" [] [PCData "False"];
+ e "TimeZone" [] [];
+ e "IsStateless" [] [PCData "False"];
+ e "VmType" [] [PCData vmtype];
+ (* See
https://bugzilla.redhat.com/show_bug.cgi?id=1260590#c17 *)
+ e "DefaultDisplayType" [] [PCData "1"];
+ ] in
+
+ (* Add the <Origin> element if we can. *)
+ let content_fields =
+ match origin_of_source_hypervisor source.s_hypervisor with
+ | None -> content_fields
+ | Some origin ->
+ content_fields @
+ [e "Origin" [] [PCData (string_of_int origin)]] in
let ovf : doc =
doc "ovf:Envelope" [
@@ -260,66 +287,53 @@ let rec create_ovf source targets guestcaps inspect
e "Section" ["xsi:type", "ovf:DiskSection_Type"] [
e "Info" [] [PCData "List of Virtual Disks"]
];
- e "Content" ["ovf:id", "out"; "xsi:type",
"ovf:VirtualSystem_Type"] [
- e "Name" [] [PCData source.s_name];
- e "TemplateId" [] [PCData
"00000000-0000-0000-0000-000000000000"];
- e "TemplateName" [] [PCData "Blank"];
- e "Description" [] [PCData generated_by];
- e "Domain" [] [];
- e "CreationDate" [] [PCData iso_time];
- e "IsInitilized" (* sic *) [] [PCData "True"];
- e "IsAutoSuspend" [] [PCData "False"];
- e "TimeZone" [] [];
- e "IsStateless" [] [PCData "False"];
- e "Origin" [] [PCData (string_of_int origin)];
- e "VmType" [] [PCData vmtype];
- (* See
https://bugzilla.redhat.com/show_bug.cgi?id=1260590#c17 *)
- e "DefaultDisplayType" [] [PCData "1"];
-
- e "Section" ["ovf:id", vm_uuid; "ovf:required",
"false";
- "xsi:type", "ovf:OperatingSystemSection_Type"]
[
- e "Info" [] [PCData inspect.i_product_name];
- e "Description" [] [PCData ostype];
- ];
-
- e "Section" ["xsi:type",
"ovf:VirtualHardwareSection_Type"] [
- e "Info" [] [PCData (sprintf "%d CPU, %Ld Memory"
source.s_vcpu memsize_mb)];
- e "Item" [] [
- e "rasd:Caption" [] [PCData (sprintf "%d virtual cpu"
source.s_vcpu)];
- e "rasd:Description" [] [PCData "Number of virtual
CPU"];
- e "rasd:InstanceId" [] [PCData "1"];
- e "rasd:ResourceType" [] [PCData "3"];
- e "rasd:num_of_sockets" [] [PCData (string_of_int source.s_vcpu)];
- e "rasd:cpu_per_socket"[] [PCData "1"];
- ];
- e "Item" [] [
- e "rasd:Caption" [] [PCData (sprintf "%Ld MB of memory"
memsize_mb)];
- e "rasd:Description" [] [PCData "Memory Size"];
- e "rasd:InstanceId" [] [PCData "2"];
- e "rasd:ResourceType" [] [PCData "4"];
- e "rasd:AllocationUnits" [] [PCData "MegaBytes"];
- e "rasd:VirtualQuantity" [] [PCData (Int64.to_string memsize_mb)];
+ e "Content" ["ovf:id", "out"; "xsi:type",
"ovf:VirtualSystem_Type"] (
+ content_fields @ [
+ e "Section" ["ovf:id", vm_uuid; "ovf:required",
"false";
+ "xsi:type", "ovf:OperatingSystemSection_Type"]
[
+ e "Info" [] [PCData inspect.i_product_name];
+ e "Description" [] [PCData ostype];
];
- e "Item" [] [
- e "rasd:Caption" [] [PCData "USB Controller"];
- e "rasd:InstanceId" [] [PCData "3"];
- e "rasd:ResourceType" [] [PCData "23"];
- e "rasd:UsbPolicy" [] [PCData "Disabled"];
- ];
- (* We always add a qxl device when outputting to RHEV.
- * See RHBZ#1213701 and RHBZ#1211231 for the reasoning
- * behind that.
- *)
- e "Item" [] [
- e "rasd:Caption" [] [PCData "Graphical Controller"];
- e "rasd:InstanceId" [] [PCData (uuidgen ())];
- e "rasd:ResourceType" [] [PCData "20"];
- e "Type" [] [PCData "video"];
- e "rasd:VirtualQuantity" [] [PCData "1"];
- e "rasd:Device" [] [PCData "qxl"];
+
+ e "Section" ["xsi:type",
"ovf:VirtualHardwareSection_Type"] [
+ e "Info" [] [PCData (sprintf "%d CPU, %Ld Memory"
source.s_vcpu memsize_mb)];
+ e "Item" [] [
+ e "rasd:Caption" [] [PCData (sprintf "%d virtual cpu"
source.s_vcpu)];
+ e "rasd:Description" [] [PCData "Number of virtual
CPU"];
+ e "rasd:InstanceId" [] [PCData "1"];
+ e "rasd:ResourceType" [] [PCData "3"];
+ e "rasd:num_of_sockets" [] [PCData (string_of_int
source.s_vcpu)];
+ e "rasd:cpu_per_socket"[] [PCData "1"];
+ ];
+ e "Item" [] [
+ e "rasd:Caption" [] [PCData (sprintf "%Ld MB of memory"
memsize_mb)];
+ e "rasd:Description" [] [PCData "Memory Size"];
+ e "rasd:InstanceId" [] [PCData "2"];
+ e "rasd:ResourceType" [] [PCData "4"];
+ e "rasd:AllocationUnits" [] [PCData "MegaBytes"];
+ e "rasd:VirtualQuantity" [] [PCData (Int64.to_string
memsize_mb)];
+ ];
+ e "Item" [] [
+ e "rasd:Caption" [] [PCData "USB Controller"];
+ e "rasd:InstanceId" [] [PCData "3"];
+ e "rasd:ResourceType" [] [PCData "23"];
+ e "rasd:UsbPolicy" [] [PCData "Disabled"];
+ ];
+ (* We always add a qxl device when outputting to RHEV.
+ * See RHBZ#1213701 and RHBZ#1211231 for the reasoning
+ * behind that.
+ *)
+ e "Item" [] [
+ e "rasd:Caption" [] [PCData "Graphical Controller"];
+ e "rasd:InstanceId" [] [PCData (uuidgen ())];
+ e "rasd:ResourceType" [] [PCData "20"];
+ e "Type" [] [PCData "video"];
+ e "rasd:VirtualQuantity" [] [PCData "1"];
+ e "rasd:Device" [] [PCData "qxl"];
+ ]
]
]
- ]
+ )
] in
(* Add disks to the OVF XML. *)
--
2.7.4