[Libguestfs] [PATCH] v2v: move open_guestfs to Types

Richard W.M. Jones rjones at redhat.com
Wed Oct 21 18:32:28 UTC 2015


On Wed, Oct 21, 2015 at 03:53:32PM +0200, Pino Toscano wrote:
> Move most of open_guestfs to Types, so a common function to open a
> Guestfs handle is available.  Since it does not do all the things the
> old open_guestfs did, the two operations have been moved to the only
> place requiring them.
> 
> This function has been placed in Types and not Utils, as will be needed
> by other functions in Types; Utils uses Types, so this avoids a circular
> dependency.

ACK.

Rich.

>  v2v/types.ml  | 10 ++++++++++
>  v2v/types.mli |  5 +++++
>  v2v/v2v.ml    | 11 ++---------
>  3 files changed, 17 insertions(+), 9 deletions(-)
> 
> diff --git a/v2v/types.ml b/v2v/types.ml
> index cc417bc..a295172 100644
> --- a/v2v/types.ml
> +++ b/v2v/types.ml
> @@ -18,6 +18,9 @@
>  
>  open Printf
>  
> +open Common_gettext.Gettext
> +open Common_utils
> +
>  (* Types.  See types.mli for documentation. *)
>  
>  type source = {
> @@ -379,6 +382,13 @@ let string_of_target_buses buses =
>    string_of_target_bus_slots "ide" buses.target_ide_bus ^
>    string_of_target_bus_slots "scsi" buses.target_scsi_bus
>  
> +let open_guestfs () =
> +  (* Open the guestfs handle. *)
> +  let g = new Guestfs.guestfs () in
> +  if trace () then g#set_trace true;
> +  if verbose () then g#set_verbose true;
> +  g
> +
>  class virtual input = object
>    method virtual as_options : string
>    method virtual source : unit -> source
> diff --git a/v2v/types.mli b/v2v/types.mli
> index 55fb09a..9e8932e 100644
> --- a/v2v/types.mli
> +++ b/v2v/types.mli
> @@ -253,3 +253,8 @@ type output_allocation = Sparse | Preallocated
>  
>  type vmtype = Desktop | Server
>  (** Type of [--vmtype] option. *)
> +
> +val open_guestfs : unit -> Guestfs.guestfs
> +(* Create a new Guestfs handle, with common options (e.g. debug, tracing)
> + * already set.
> + *)
> diff --git a/v2v/v2v.ml b/v2v/v2v.ml
> index 333ece0..88ae409 100644
> --- a/v2v/v2v.ml
> +++ b/v2v/v2v.ml
> @@ -76,6 +76,8 @@ let rec main () =
>    );
>  
>    let g = open_guestfs () in
> +  g#set_identifier "v2v";
> +  g#set_network true;
>    (match conversion_mode with
>     | Copying (overlays, _) -> populate_overlays g overlays
>     | In_place -> populate_disks g source.s_disks
> @@ -284,15 +286,6 @@ and init_targets overlays source output output_format =
>  
>    output#prepare_targets source targets
>  
> -and open_guestfs () =
> -  (* Open the guestfs handle. *)
> -  let g = new G.guestfs () in
> -  g#set_identifier "v2v";
> -  if trace () then g#set_trace true;
> -  if verbose () then g#set_verbose true;
> -  g#set_network true;
> -  g
> -
>  and populate_overlays g overlays =
>    (* Populate guestfs handle with qcow2 overlays. *)
>    List.iter (
> -- 
> 2.1.0
> 
> _______________________________________________
> Libguestfs mailing list
> Libguestfs at redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top




More information about the Libguestfs mailing list