[Libguestfs] [PATCH] RFC: v2v: add and use libvirt connection objects

Richard W.M. Jones rjones at redhat.com
Mon Sep 11 09:27:18 UTC 2017


On Fri, Sep 08, 2017 at 05:44:17PM +0200, Pino Toscano wrote:
> diff --git a/v2v/libvirt_utils.mli b/v2v/libvirt_utils.mli
> index 53dfd48e5..11a83b9a2 100644
> --- a/v2v/libvirt_utils.mli
> +++ b/v2v/libvirt_utils.mli
> @@ -24,32 +24,42 @@
>      password prompt to stdout, which is the same place we would be
>      reading the XML from.  This file works around this brokenness. *)
>  
> -val dumpxml : ?password:string -> ?conn:string -> string -> string
> -(** [dumpxml ?password ?conn dom] returns the libvirt XML of domain [dom].
> -    The optional [?conn] parameter is the libvirt connection URI.
> +type conn
> +(** The type of a compiled regular expression. *)
> +
> +val connect_ro : ?conn:string -> unit -> conn
> +(** Connect in read-only mode to the specified URI. *)
> +
> +val connect_rw : ?password:string -> ?conn:string -> unit -> conn
> +(** Connect in read-only mode to the specified URI. *)

^                 read-write mode

It's not exactly obvious, but read-write connections only need to be
used if you're going to call this function.  A read-only connection
will not return passwords in the XML ...

> +val dumpxml : conn -> string -> string
> +(** [dumpxml conn dom] returns the libvirt XML of domain [dom]
> +    in the libvirt connection [conn].
>      [dom] may be a guest name or UUID. *)

... because for libvirt "read-write" connection means "secure" or
something.

Anyway, in the ocaml-libvirt bindings we use phantom types to
statically ensure that the right sort of connection is used, and it
would be worth doing the same thing here.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/




More information about the Libguestfs mailing list