mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
v2v: -o libvirt: switch away from virsh
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.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user