Skip to content

Commit

Permalink
v2v: Add RHEV target.
Browse files Browse the repository at this point in the history
Use:

  virt-v2v [..] -o rhev -os nfs:/export

or:

  virt-v2v [..] -o rhev -os /mountpoint

to write to a RHEV-M / oVirt Export Storage Domain.
  • Loading branch information
rwmjones committed Aug 5, 2014
1 parent 9ae2600 commit b6189a8
Show file tree
Hide file tree
Showing 11 changed files with 803 additions and 12 deletions.
97 changes: 97 additions & 0 deletions v2v/DOM.ml
@@ -0,0 +1,97 @@
(* virt-v2v
* Copyright (C) 2009-2014 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)

(* Poor man's XML DOM, mutable for easy of modification. *)

open Common_utils
open Utils

open Printf

type node =
| PCData of string
| Element of element
and element = {
e_name : string; (* Name of element. *)
mutable e_attrs : attr list; (* Attributes. *)
mutable e_children : node list; (* Child elements. *)
}
and attr = string * string
and doc = element

let doc name attrs children =
{ e_name = name; e_attrs = attrs; e_children = children }

let e name attrs children =
Element { e_name = name; e_attrs = attrs; e_children = children }

let rec node_to_chan chan = function
| PCData str -> output_string chan (xml_quote_pcdata str)
| Element e -> element_to_chan chan e
and element_to_chan chan
{ e_name = name; e_attrs = attrs; e_children = children } =
fprintf chan "<%s" name;
List.iter (fun (n, v) -> fprintf chan " %s='%s'" n (xml_quote_attr v)) attrs;
output_char chan '>';
List.iter (node_to_chan chan) children;
fprintf chan "</%s>" name

let doc_to_chan chan doc =
fprintf chan "<?xml version='1.0' encoding='utf-8'?>\n";
element_to_chan chan doc

let path_to_nodes doc path =
match path with
| [] -> invalid_arg "path_to_nodes: empty path"
| top_name :: path ->
if doc.e_name <> top_name then []
else (
let rec loop nodes path =
match path with
| [] -> []
| [p] ->
List.filter (
function
| PCData _ -> false
| Element e when e.e_name = p -> true
| Element _ -> false
) nodes
| p :: ps ->
let children =
filter_map (
function
| PCData _ -> None
| Element e when e.e_name = p -> Some e.e_children
| Element _ -> None
) nodes in
List.concat (List.map (fun nodes -> loop nodes ps) children)
in
loop doc.e_children path
)

let filter_node_list_by_attr nodes attr =
List.filter (
function
| Element { e_attrs = attrs } when List.mem attr attrs -> true
| Element _ | PCData _ -> false
) nodes

let find_node_by_attr nodes attr =
match filter_node_list_by_attr nodes attr with
| [] -> raise Not_found
| x::_ -> x
52 changes: 52 additions & 0 deletions v2v/DOM.mli
@@ -0,0 +1,52 @@
(* virt-v2v
* Copyright (C) 2009-2014 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)

(** Poor man's XML DOM, mutable for easy of modification. *)

type node =
| PCData of string
| Element of element
and element = {
e_name : string; (** Name of element. *)
mutable e_attrs : attr list; (** Attributes. *)
mutable e_children : node list; (** Child elements. *)
}
and attr = string * string
and doc = element

val doc : string -> attr list -> node list -> doc
(** A quick way to create a document. *)

val e : string -> attr list -> node list -> node
(** A quick way to create elements. *)

val doc_to_chan : out_channel -> doc -> unit
(** Write the XML document to an output channel. *)

val path_to_nodes : doc -> string list -> node list
(** Search down the path and return a list of all matching elements.
Returns an empty list if none were found. *)

val filter_node_list_by_attr : node list -> attr -> node list
(** Find DOM elements which have a particular attribute name=value (not
recursively). If not found, returns an empty list. *)

val find_node_by_attr : node list -> attr -> node
(** Find the first DOM element which has a particular attribute
name=value (not recursively). If not found, raises
[Not_found]. *)
6 changes: 6 additions & 0 deletions v2v/Makefile.am
Expand Up @@ -26,9 +26,11 @@ CLEANFILES = *~ *.cmi *.cmo *.cmx *.cmxa *.o virt-v2v
SOURCES_MLI = \
convert_linux.mli \
convert_windows.mli \
DOM.mli \
lib_linux.mli \
source_libvirt.mli \
target_local.mli \
target_RHEV.mli \
types.mli \
xml.mli

Expand All @@ -37,18 +39,21 @@ SOURCES_ML = \
types.ml \
utils.ml \
xml.ml \
DOM.ml \
lib_linux.ml \
cmdline.ml \
source_libvirt.ml \
convert_linux.ml \
convert_windows.ml \
target_local.ml \
target_RHEV.ml \
v2v.ml

SOURCES_C = \
$(top_builddir)/fish/progress.c \
$(top_builddir)/mllib/tty-c.c \
$(top_builddir)/mllib/progress-c.c \
$(top_builddir)/mllib/mkdtemp-c.c \
$(top_builddir)/customize/crypt-c.c \
utils-c.c \
xml-c.c
Expand All @@ -73,6 +78,7 @@ BOBJECTS = \
$(top_builddir)/mllib/tTY.cmo \
$(top_builddir)/mllib/progress.cmo \
$(top_builddir)/mllib/config.cmo \
$(top_builddir)/mllib/mkdtemp.cmo \
$(top_builddir)/customize/urandom.cmo \
$(top_builddir)/customize/random_seed.cmo \
$(top_builddir)/customize/hostname.cmo \
Expand Down
15 changes: 14 additions & 1 deletion v2v/cmdline.ml
Expand Up @@ -42,6 +42,7 @@ let parse_cmdline () =
let quiet = ref false in
let verbose = ref false in
let trace = ref false in
let vmtype = ref "" in

let input_mode = ref `Libvirt in
let set_input_mode = function
Expand Down Expand Up @@ -98,6 +99,7 @@ let parse_cmdline () =
"--verbose", Arg.Set verbose, ditto;
"-V", Arg.Unit display_version, " " ^ s_"Display version and exit";
"--version", Arg.Unit display_version, ditto;
"--vmtype", Arg.Set_string vmtype, "server|desktop " ^ s_"Set vmtype (for RHEV)";
"-x", Arg.Set trace, " " ^ s_"Enable tracing of libguestfs calls";
] in
long_options := argspec;
Expand Down Expand Up @@ -139,6 +141,13 @@ read the man page virt-v2v(1).
let root_choice = !root_choice in
let verbose = !verbose in
let trace = !trace in
let vmtype =
match !vmtype with
| "server" -> Some `Server
| "desktop" -> Some `Desktop
| "" -> None
| _ ->
error (f_"unknown --vmtype option, must be \"server\" or \"desktop\"") in

(* No arguments and machine-readable mode? Print out some facts
* about what this binary supports.
Expand Down Expand Up @@ -177,18 +186,22 @@ read the man page virt-v2v(1).
| `Libvirt ->
if output_storage <> "" then
error (f_"-o libvirt: do not use the -os option");
if vmtype <> None then
error (f_"--vmtype option can only be used with '-o rhev'");
OutputLibvirt output_conn
| `Local ->
if output_storage = "" then
error (f_"-o local: output directory was not specified, use '-os /dir'");
if not (is_directory output_storage) then
error (f_"-os %s: output directory does not exist or is not a directory")
output_storage;
if vmtype <> None then
error (f_"--vmtype option can only be used with '-o rhev'");
OutputLocal output_storage
| `RHEV ->
if output_storage = "" then
error (f_"-o local: output storage was not specified, use '-os'");
OutputRHEV output_storage in
OutputRHEV (output_storage, vmtype) in

input, output,
debug_gc, output_alloc, output_format, output_name,
Expand Down

0 comments on commit b6189a8

Please sign in to comment.