Blob Blame History Raw
From 84f74f74a398164a8b6d102633b58b690874fa00 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Thu, 22 Feb 2018 14:22:12 +0000
Subject: [PATCH] v2v: OVF: Code formatting.

Updates commit a52ed4b4454396eb13d2cdf5762292bff3104f66
("v2v: ovf: Create OVF more aligned with the standard") with some
small code refactoring and formatting.

(cherry picked from commit 9e83f3a2ccef4e91b0b3275b712df8b16e233cff)
---
 v2v/create_ovf.ml | 73 ++++++++++++++++++++++++++---------------------
 1 file changed, 41 insertions(+), 32 deletions(-)

diff --git a/v2v/create_ovf.ml b/v2v/create_ovf.ml
index f1985ea86..bf3741e0f 100644
--- a/v2v/create_ovf.ml
+++ b/v2v/create_ovf.ml
@@ -530,20 +530,16 @@ let rec create_ovf source targets guestcaps inspect
  * For example normal disk section is in node <DiskSection> whereas in case of
  * RHV export storage domain it is <Section xsi:type="ovf:DiskSection_Type">.
  *)
-and get_flavoured_section ovf ovf_flavour ovirt_path rhv_path rhv_path_attr =
-  let nodes =
-    match ovf_flavour with
-    | OVirt ->
-      let nodes = path_to_nodes ovf ovirt_path in
-      (match nodes with
+and get_flavoured_section ovf ovirt_path rhv_path rhv_path_attr = function
+  | OVirt ->
+     let nodes = path_to_nodes ovf ovirt_path in
+     (match nodes with
       | [node] -> node
       | [] | _::_::_ -> assert false)
-    | RHVExportStorageDomain ->
-      let nodes = path_to_nodes ovf rhv_path in
-      try find_node_by_attr nodes rhv_path_attr
-      with Not_found -> assert false
-  in
-  nodes
+  | RHVExportStorageDomain ->
+     let nodes = path_to_nodes ovf rhv_path in
+     try find_node_by_attr nodes rhv_path_attr
+     with Not_found -> assert false
 
 (* This modifies the OVF DOM, adding a section for each disk. *)
 and add_disks targets guestcaps output_alloc sd_uuid image_uuids vol_uuids
@@ -553,14 +549,19 @@ and add_disks targets guestcaps output_alloc sd_uuid image_uuids vol_uuids
     match nodes with
     | [] | _::_::_ -> assert false
     | [node] -> node in
-  let disk_section = get_flavoured_section ovf ovf_flavour
-    ["ovf:Envelope"; "DiskSection"]
-    ["ovf:Envelope"; "Section"]
-    ("xsi:type", "ovf:DiskSection_Type") in
-  let virtualhardware_section = get_flavoured_section ovf ovf_flavour
-    ["ovf:Envelope"; "VirtualSystem"; "VirtualHardwareSection"]
-    ["ovf:Envelope"; "Content"; "Section"]
-    ("xsi:type", "ovf:VirtualHardwareSection_Type") in
+  let disk_section =
+    get_flavoured_section ovf
+                          ["ovf:Envelope"; "DiskSection"]
+                          ["ovf:Envelope"; "Section"]
+                          ("xsi:type", "ovf:DiskSection_Type")
+                          ovf_flavour in
+  let virtualhardware_section =
+    get_flavoured_section ovf
+                          ["ovf:Envelope"; "VirtualSystem";
+                               "VirtualHardwareSection"]
+                          ["ovf:Envelope"; "Content"; "Section"]
+                          ("xsi:type", "ovf:VirtualHardwareSection_Type")
+                          ovf_flavour in
 
   (* Iterate over the disks, adding them to the OVF document. *)
   List.iteri (
@@ -687,14 +688,19 @@ and add_disks targets guestcaps output_alloc sd_uuid image_uuids vol_uuids
 
 (* This modifies the OVF DOM, adding a section for each NIC. *)
 and add_networks nics guestcaps ovf_flavour ovf =
-  let network_section = get_flavoured_section ovf ovf_flavour
-    ["ovf:Envelope"; "NetworkSection"]
-    ["ovf:Envelope"; "Section"]
-    ("xsi:type", "ovf:NetworkSection_Type") in
-  let virtualhardware_section = get_flavoured_section ovf ovf_flavour
-    ["ovf:Envelope"; "VirtualSystem"; "VirtualHardwareSection"]
-    ["ovf:Envelope"; "Content"; "Section"]
-    ("xsi:type", "ovf:VirtualHardwareSection_Type") in
+  let network_section =
+    get_flavoured_section ovf
+                          ["ovf:Envelope"; "NetworkSection"]
+                          ["ovf:Envelope"; "Section"]
+                          ("xsi:type", "ovf:NetworkSection_Type")
+                          ovf_flavour in
+  let virtualhardware_section =
+    get_flavoured_section ovf
+                          ["ovf:Envelope"; "VirtualSystem";
+                               "VirtualHardwareSection"]
+                          ["ovf:Envelope"; "Content"; "Section"]
+                          ("xsi:type", "ovf:VirtualHardwareSection_Type")
+                          ovf_flavour in
 
   (* Iterate over the NICs, adding them to the OVF document. *)
   List.iteri (
@@ -755,10 +761,13 @@ and add_sound_card sound ovf_flavour ovf =
 
   match device with
   | Some device ->
-     let virtualhardware_section = get_flavoured_section ovf ovf_flavour
-       ["ovf:Envelope"; "VirtualSystem"; "VirtualHardwareSection"]
-       ["ovf:Envelope"; "Content"; "Section"]
-       ("xsi:type", "ovf:VirtualHardwareSection_Type") in
+     let virtualhardware_section =
+       get_flavoured_section ovf
+                             ["ovf:Envelope"; "VirtualSystem";
+                                  "VirtualHardwareSection"]
+                             ["ovf:Envelope"; "Content"; "Section"]
+                             ("xsi:type", "ovf:VirtualHardwareSection_Type")
+                             ovf_flavour in
 
      let item =
        e "Item" [] [
-- 
2.20.1