[Pkg-libvirt-commits] [libguestfs] 60/116: v2v: Make source s.hypervisor field type-safe.
Hilko Bengen
bengen at moszumanska.debian.org
Wed Nov 26 22:05:11 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag debian/1%1.29.10-1
in repository libguestfs.
commit a5bb1a4ccbe82ab4939b5d240877009d1762d49c
Author: Richard W.M. Jones <rjones at redhat.com>
Date: Sat Nov 15 18:26:54 2014 +0000
v2v: Make source s.hypervisor field type-safe.
---
v2v/input_disk.ml | 2 +-
v2v/input_libvirtxml.ml | 2 ++
v2v/input_ova.ml | 2 +-
v2v/types.ml | 49 +++++++++++++++++++++++++++++++++++++++++++++++--
v2v/types.mli | 16 +++++++++++++++-
v2v/v2v.ml | 7 ++++++-
6 files changed, 72 insertions(+), 6 deletions(-)
diff --git a/v2v/input_disk.ml b/v2v/input_disk.ml
index 19dfbcb..6ef33b9 100644
--- a/v2v/input_disk.ml
+++ b/v2v/input_disk.ml
@@ -80,7 +80,7 @@ class input_disk verbose input_format disk = object
} in
let source = {
- s_hypervisor = "unknown";
+ s_hypervisor = `UnknownHV;
s_name = name; s_orig_name = name;
s_memory = 2048L *^ 1024L *^ 1024L; (* 2048 MB *)
s_vcpu = 1; (* 1 vCPU is a safe default *)
diff --git a/v2v/input_libvirtxml.ml b/v2v/input_libvirtxml.ml
index b4ee9df..250477a 100644
--- a/v2v/input_libvirtxml.ml
+++ b/v2v/input_libvirtxml.ml
@@ -68,6 +68,8 @@ let parse_libvirt_xml ~verbose xml =
if hypervisor = "" then
error (f_"in the libvirt XML metadata, <domain type='...'> is missing or empty");
+ let hypervisor = source_hypervisor_of_string hypervisor in
+
if name = "" then
error (f_"in the libvirt XML metadata, <name> is missing or empty");
diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml
index bff789b..3aa1182 100644
--- a/v2v/input_ova.ml
+++ b/v2v/input_ova.ml
@@ -285,7 +285,7 @@ object
done;
let source = {
- s_hypervisor = "vmware";
+ s_hypervisor = `VMware;
s_name = name;
s_orig_name = name;
s_memory = memory;
diff --git a/v2v/types.ml b/v2v/types.ml
index 580ece0..45aed49 100644
--- a/v2v/types.ml
+++ b/v2v/types.ml
@@ -21,7 +21,7 @@ open Printf
(* Types. See types.mli for documentation. *)
type source = {
- s_hypervisor : string;
+ s_hypervisor : source_hypervisor;
s_name : string;
s_orig_name : string;
s_memory : int64;
@@ -32,6 +32,13 @@ type source = {
s_removables : source_removable list;
s_nics : source_nic list;
}
+and source_hypervisor =
+[ `QEmu | `KQemu | `KVM | `Xen | `LXC | `UML | `OpenVZ
+| `Test | `VMware | `HyperV | `VBox | `Phyp | `Parallels
+| `Bhyve
+| `Physical (* used by virt-p2v *)
+| `UnknownHV (* used by -i disk *)
+| `OtherHV of string ]
and source_disk = {
s_disk_id : int;
s_qemu_uri : string;
@@ -70,7 +77,7 @@ NICs:
%s
"
s.s_name
- s.s_hypervisor
+ (string_of_source_hypervisor s.s_hypervisor)
s.s_memory
s.s_vcpu
(String.concat "," s.s_features)
@@ -81,6 +88,44 @@ NICs:
(String.concat "\n" (List.map string_of_source_removable s.s_removables))
(String.concat "\n" (List.map string_of_source_nic s.s_nics))
+and string_of_source_hypervisor = function
+ | `QEmu -> "qemu"
+ | `KQemu -> "kqemu"
+ | `KVM -> "kvm"
+ | `Xen -> "xen"
+ | `LXC -> "lxc"
+ | `UML -> "uml"
+ | `OpenVZ -> "openvz"
+ | `Test -> "test"
+ | `VMware -> "vmware"
+ | `HyperV -> "hyperv"
+ | `VBox -> "vbox"
+ | `Phyp -> "phyp"
+ | `Parallels -> "parallels"
+ | `Bhyve -> "bhyve"
+ | `Physical -> "physical"
+ | `UnknownHV -> "unknown"
+ | `OtherHV s -> s
+
+and source_hypervisor_of_string = function
+ | "qemu" -> `QEmu
+ | "kqemu" -> `KQemu
+ | "kvm" -> `KVM
+ | "xen" -> `Xen
+ | "lxc" -> `LXC
+ | "uml" -> `UML
+ | "openvz" -> `OpenVZ
+ | "test" -> `Test
+ | "vmware" -> `VMware
+ | "hyperv" -> `HyperV
+ | "vbox" -> `VBox
+ | "phyp" -> `Phyp
+ | "parallels" -> `Parallels
+ | "bhyve" -> `Bhyve
+ | "physical" -> `Physical
+ | "unknown" -> `OtherHV "unknown" (* because `UnknownHV is for internal use *)
+ | s -> `OtherHV s
+
and string_of_source_disk { s_qemu_uri = qemu_uri; s_format = format;
s_target_dev = target_dev } =
sprintf "\t%s%s%s"
diff --git a/v2v/types.mli b/v2v/types.mli
index f02acb2..a308350 100644
--- a/v2v/types.mli
+++ b/v2v/types.mli
@@ -19,7 +19,7 @@
(** Types. *)
type source = {
- s_hypervisor : string; (** Source hypervisor, eg "vmware" *)
+ s_hypervisor : source_hypervisor; (** Source hypervisor. *)
s_name : string; (** Guest name. *)
s_orig_name : string; (** Original guest name (if we rename
the guest using -on, original is
@@ -34,6 +34,17 @@ type source = {
}
(** The source: metadata, disk images. *)
+and source_hypervisor =
+[ `QEmu | `KQemu | `KVM | `Xen | `LXC | `UML | `OpenVZ
+| `Test | `VMware | `HyperV | `VBox | `Phyp | `Parallels
+| `Bhyve
+| `Physical (** used by virt-p2v *)
+| `UnknownHV (** used by -i disk *)
+| `OtherHV of string ]
+(** Possible source hypervisors. See
+ [libvirt.git/docs/schemas/domaincommon.rng] for the list supported
+ by libvirt. *)
+
and source_disk = {
s_disk_id : int; (** A unique ID for each source disk. *)
s_qemu_uri : string; (** QEMU URI of source disk. *)
@@ -67,6 +78,9 @@ and source_display = {
val string_of_source : source -> string
val string_of_source_disk : source_disk -> string
+val string_of_source_hypervisor : source_hypervisor -> string
+val source_hypervisor_of_string : string -> source_hypervisor
+
type overlay = {
ov_overlay_file : string; (** Local overlay file (qcow2 format). *)
ov_sd : string; (** "sda", "sdb" etc - canonical device name. *)
diff --git a/v2v/v2v.ml b/v2v/v2v.ml
index 5b3bfa6..89287db 100644
--- a/v2v/v2v.ml
+++ b/v2v/v2v.ml
@@ -73,7 +73,12 @@ let rec main () =
if verbose then printf "%s%!" (string_of_source source);
- assert (source.s_hypervisor <> "");
+ (match source.s_hypervisor with
+ | `OtherHV hv ->
+ warning (f_"unknown source hypervisor ('%s') in metadata") hv
+ | _ -> ()
+ );
+
assert (source.s_name <> "");
assert (source.s_memory > 0L);
assert (source.s_vcpu >= 1);
--
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