[Libguestfs] [PATCH v4 5/7] v2v: -o libvirt: switch away from virsh
Richard W.M. Jones
rjones at redhat.com
Wed Apr 10 13:17:59 UTC 2019
On Mon, Apr 08, 2019 at 02:49:58PM +0200, Pino Toscano wrote:
> Now that we have a proper libvirt connection object, use it directly to
> refresh the storage pool, and define the final guest. This avoids
> spawning a new virsh process twice, with no possibility to even share a
> possible authentication required.
> ---
> v2v/output_libvirt.ml | 35 ++++++++++++++++-------------------
> 1 file changed, 16 insertions(+), 19 deletions(-)
>
> diff --git a/v2v/output_libvirt.ml b/v2v/output_libvirt.ml
> index e62e43bb8..e82e95cd9 100644
> --- a/v2v/output_libvirt.ml
> +++ b/v2v/output_libvirt.ml
> @@ -160,14 +160,14 @@ object (self)
> (* We copied directly into the final pool directory. However we
> * have to tell libvirt.
> *)
> - let cmd = [ "virsh" ] @
> - (if quiet () then [ "-q" ] else []) @
> - (match oc with
> - | None -> []
> - | Some uri -> [ "-c"; uri; ]) @
> - [ "pool-refresh"; output_pool ] in
> - if run_command cmd <> 0 then
> - warning (f_"could not refresh libvirt pool %s") output_pool;
> + (try
> + let pool = Libvirt_utils.get_pool self#conn output_pool in
> + Libvirt.Pool.refresh (Libvirt.Pool.const pool)
> + with
> + Libvirt.Virterror { message } ->
> + warning (f_"could not refresh libvirt pool ‘%s’: %s")
> + output_pool (Option.default "" message)
> + );
>
> let pool_name =
> match pool_name with
> @@ -198,17 +198,14 @@ object (self)
> );
>
> (* Define the domain in libvirt. *)
> - let cmd = [ "virsh" ] @
> - (if quiet () then [ "-q" ] else []) @
> - (match oc with
> - | None -> []
> - | Some uri -> [ "-c"; uri; ]) @
> - [ "define"; tmpfile ] in
> - if run_command cmd = 0 then (
> - try Unix.unlink tmpfile with _ -> ()
> - ) else (
> - warning (f_"could not define libvirt domain. The libvirt XML is still available in ‘%s’. Try running ‘virsh define %s’ yourself instead.")
> - tmpfile tmpfile
> + (try
> + ignore (Libvirt.Domain.define_xml self#conn (DOM.doc_to_string doc));
> + (try Unix.unlink tmpfile with _ -> ())
> + with
> + Libvirt.Virterror { message } ->
> + warning (f_"could not define libvirt domain: %s.\nThe libvirt XML is still available in ‘%s’. Try running ‘virsh -c %s define %s’ yourself instead.")
> + (Option.default "" message) tmpfile
> + (Libvirt.Connect.get_uri self#conn) tmpfile
> );
> end
Sensible change, ACK
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v
More information about the Libguestfs
mailing list