[Pkg-libvirt-commits] [libguestfs] 72/179: v2v: -i ova: Mainly whitespace and formatting changes.
Hilko Bengen
bengen at moszumanska.debian.org
Fri Oct 31 19:08:25 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to branch experimental
in repository libguestfs.
commit 516a95824a9a5408c353dc9843492b5092fbe0fc
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Wed Oct 15 21:00:21 2014 +0200
v2v: -i ova: Mainly whitespace and formatting changes.
Mainly tidy up the indentation and comments to match the "house
style". No significant functional change.
---
v2v/input_ova.ml | 135 ++++++++++++++++++++++++++++++-------------------------
1 file changed, 74 insertions(+), 61 deletions(-)
diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml
index f7089b6..d5efcb2 100644
--- a/v2v/input_ova.ml
+++ b/v2v/input_ova.ml
@@ -25,31 +25,30 @@ open Types
open Utils
class input_ova verbose ova =
- let tmpdir =
- let base_dir = (new Guestfs.guestfs ())#get_cachedir () in
- let t = Mkdtemp.temp_dir ~base_dir "ova." "" in
- rmdir_on_exit t;
- t in
+ let tmpdir =
+ let base_dir = (new Guestfs.guestfs ())#get_cachedir () in
+ let t = Mkdtemp.temp_dir ~base_dir "ova." "" in
+ rmdir_on_exit t;
+ t in
object
inherit input verbose
method as_options = "-i ova " ^ ova
method source () =
-
- (* extract ova (tar) file *)
+ (* Extract ova (tar) file. *)
let cmd = sprintf "tar -xf %s -C %s" (quote ova) (quote tmpdir) in
-
+ if verbose then printf "%s\n%!" cmd;
if Sys.command cmd <> 0 then
- error (f_"error running command: %s") cmd;
+ error (f_"error unpacking OVA file: %s") cmd;
let files = Sys.readdir tmpdir in
let mf = ref "" in
let ovf = ref "" in
- (* search for the ovf file *)
+ (* Search for the ovf file. *)
Array.iter (fun file ->
if Filename.check_suffix file ".ovf" then
- ovf := file
+ ovf := file
else if Filename.check_suffix file ".mf" then
mf := file
) files;
@@ -66,23 +65,29 @@ object
let sha1 = Str.matched_group 2 line in
let cmd = sprintf "sha1sum %s" (quote (tmpdir // file)) in
let out = external_command ~prog cmd in
- (match out with
- | [] -> error (f_"no output from sha1sum command, see previous errors")
- | [line] ->
- let hash, _ = string_split " " line in
- if hash <> sha1 then
- error (f_"Checksum of %s does not match manifest sha1 %s") file sha1;
- | _::_ -> error (f_"cannot parse output of sha1sum command")
- );
- ) lines;
-
- (* parse the ovf file *)
+ (match out with
+ | [] -> error (f_"no output from sha1sum command, see previous errors")
+ | [line] ->
+ let hash, _ = string_split " " line in
+ if hash <> sha1 then
+ error (f_"checksum of %s does not match manifest sha1 %s")
+ file sha1;
+ | _::_ -> error (f_"cannot parse output of sha1sum command")
+ );
+ ) lines;
+
+ (* Parse the ovf file. *)
let xml = read_whole_file (tmpdir // !ovf) in
let doc = Xml.parse_memory xml in
+
+ (* Handle namespaces. *)
let xpathctx = Xml.xpath_new_context doc in
- Xml.xpath_register_ns xpathctx "ovf" "http://schemas.dmtf.org/ovf/envelope/1";
- Xml.xpath_register_ns xpathctx "rasd" "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData";
- Xml.xpath_register_ns xpathctx "vssd" "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData";
+ Xml.xpath_register_ns xpathctx
+ "ovf" "http://schemas.dmtf.org/ovf/envelope/1";
+ Xml.xpath_register_ns xpathctx
+ "rasd" "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData";
+ Xml.xpath_register_ns xpathctx
+ "vssd" "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData";
let xpath_to_string expr default =
let obj = Xml.xpath_eval_expression xpathctx expr in
@@ -107,7 +112,7 @@ object
let disks = ref [] in
let removables = ref [] in
- (* resources hard-disk, CD-ROMs and floppy *)
+ (* Resources hard-disk, CD-ROMs and floppy. *)
let add_resource id =
let expr = sprintf "/ovf:Envelope/ovf:VirtualSystem/ovf:VirtualHardwareSection/ovf:Item[rasd:ResourceType/text()=%d]" id in
let obj = Xml.xpath_eval_expression xpathctx expr in
@@ -117,19 +122,18 @@ object
Xml.xpathctx_set_current_context xpathctx n;
let address = xpath_to_int "rasd:AddressOnParent/text()" 0 in
let parent_id = xpath_to_int "rasd:Parent/text()" 0 in
- (* prob the parent controller *)
+ (* Probably the parent controller. *)
let expr = sprintf "/ovf:Envelope/ovf:VirtualSystem/ovf:VirtualHardwareSection/ovf:Item[rasd:InstanceId/text()=%d]/rasd:ResourceType/text()" parent_id in
let controller = xpath_to_int expr 0 in
- (* 6: iscsi controller, 5: ide. assueming scsi or ide *)
+ (* 6: iscsi controller, 5: ide. assuming scsi or ide *)
let target_dev =
match controller with
- | 6 -> "sd"
- | 0 | 5 | _ -> "hd" in
- (*FIXME in floppy should be 'fd'??? *)
+ | 6 -> "sd"
+ | 0 | 5 | _ (* XXX floppy should be 'fd'? *) -> "hd" in
- let target_dev = sprintf "%s%c" target_dev (Char.chr(48+address)) in
+ let target_dev = target_dev ^ drive_name address in
- (* add disk(17)/removables to its collections *)
+ (* Add disk(17)/removables to its collections. *)
if id = 17 then (
Xml.xpathctx_set_current_context xpathctx n;
let file_id = xpath_to_string "rasd:HostResource/text()" "" in
@@ -138,13 +142,17 @@ object
let file_id = Str.matched_group 1 file_id in
let expr = sprintf "/ovf:Envelope/ovf:DiskSection/ovf:Disk[@ovf:diskId='%s']/@ovf:fileRef" file_id in
let file_ref = xpath_to_string expr "" in
- if file_ref == "" then error (f_"Error parsing disk fileRef");
+ if file_ref == "" then error (f_"error parsing disk fileRef");
let expr = sprintf "/ovf:Envelope/ovf:References/ovf:File[@ovf:id='%s']/@ovf:href" file_ref in
let file_name = xpath_to_string expr "" in
- let disk = { s_qemu_uri=(tmpdir // file_name); s_format=Some "vmdk"; s_target_dev=Some target_dev } in
+ let disk = {
+ s_qemu_uri= tmpdir // file_name;
+ s_format = Some "vmdk";
+ s_target_dev = Some target_dev;
+ } in
disks := disk :: !disks;
) else
- error (f_"could not parse disk rasd:HostResource from OVF document");
+ error (f_"could not parse disk rasd:HostResource from OVF document");
)
else (
(* 14: Floppy 15: CD 16: CDROM*)
@@ -153,51 +161,55 @@ object
| 14 -> `Floppy
| 15 | 16 -> `CDROM
| _ -> assert false in
- let disk = { s_removable_type = typ; s_removable_target_dev = Some target_dev } in
+ let disk = {
+ s_removable_type = typ;
+ s_removable_target_dev = Some target_dev
+ } in
removables := disk :: !removables;
)
done;
- in
+ in
- (* search for vm name *)
- let name = xpath_to_string "/ovf:Envelope/ovf:VirtualSystem/ovf:Name/text()" "" in
+ (* Search for vm name. *)
+ let name =
+ xpath_to_string "/ovf:Envelope/ovf:VirtualSystem/ovf:Name/text()" "" in
if name = "" then
error (f_"could not parse ovf:Name from OVF document");
- (* search for memory *)
+ (* Search for memory. *)
let memory = xpath_to_int "/ovf:Envelope/ovf:VirtualSystem/ovf:VirtualHardwareSection/ovf:Item[rasd:ResourceType/text()=4]/rasd:VirtualQuantity/text()" (1024 * 1024) in
let memory = Int64.of_int (memory * 1024 * 1024) in
- (* search for cpu *)
- let cpu = xpath_to_int "/ovf:Envelope/ovf:VirtualSystem/ovf:VirtualHardwareSection/ovf:Item[rasd:ResourceType/text()=3]/rasd:VirtualQuantity/text()" 1 in
+ (* Search for number of vCPUs. *)
+ let vcpu = xpath_to_int "/ovf:Envelope/ovf:VirtualSystem/ovf:VirtualHardwareSection/ovf:Item[rasd:ResourceType/text()=3]/rasd:VirtualQuantity/text()" 1 in
- (* search for floopy *)
+ (* Search for floppies. *)
add_resource 14;
- (* search for cd *)
+ (* Search for CDs. *)
add_resource 15;
- (* search for cdrom *)
+ (* Search for CDROMs. *)
add_resource 16;
- (* search for hard-disk *)
+ (* Search for hard disks. *)
add_resource 17;
- (* serch for networks ResourceType: 10*)
+ (* Search for networks ResourceType: 10 *)
let nics = ref [] in
let obj = Xml.xpath_eval_expression xpathctx "/ovf:Envelope/ovf:VirtualSystem/ovf:VirtualHardwareSection/ovf:Item[rasd:ResourceType/text()=10]" in
let nr_nodes = Xml.xpathobj_nr_nodes obj in
for i = 0 to nr_nodes-1 do
- let n = Xml.xpathobj_node doc obj i in
- Xml.xpathctx_set_current_context xpathctx n;
- let vnet = xpath_to_string "rasd:ElementName/text()" (sprintf"eth%d" i) in
- let nic = {
- s_mac = None;
- s_vnet = vnet;
- s_vnet_orig = vnet;
- s_vnet_type = Network;
- } in
- nics := nic :: !nics
+ let n = Xml.xpathobj_node doc obj i in
+ Xml.xpathctx_set_current_context xpathctx n;
+ let vnet = xpath_to_string "rasd:ElementName/text()" (sprintf"eth%d" i) in
+ let nic = {
+ s_mac = None;
+ s_vnet = vnet;
+ s_vnet_orig = vnet;
+ s_vnet_type = Network;
+ } in
+ nics := nic :: !nics
done;
let source = {
@@ -205,13 +217,14 @@ object
s_name = name;
s_orig_name = name;
s_memory = memory;
- s_vcpu = cpu;
- s_features = []; (* FIXME: *)
- s_display = None; (* FIXME: *)
+ s_vcpu = vcpu;
+ s_features = []; (* XXX *)
+ s_display = None; (* XXX *)
s_disks = !disks;
s_removables = !removables;
s_nics = !nics;
} in
+
source
end
--
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