I think we should do this slightly differently for consistency with
other classes. See here for example:
https://github.com/libguestfs/libguestfs/blob/dea9636c596acd030c995505786...
(1) Declare a val mutable in the object:
val mutable delete_disks_on_exit = true
@@ -275,6 +290,13 @@ object
if Python_script.run_command vmcheck_script json_params [] <> 0 then
error (f_"failed vmchecks, see earlier errors");
+ (* Set up an at-exit handler so we delete the orphan disks on failure. *)
+ at_exit (
+ fun () ->
+ if disks_uuids <> [] then
(2) Change this check to:
if delete_disks_on_exit then
+ delete_disks disks_uuids
+ );
+
(* Create an nbdkit instance for each disk and set the
* target URI to point to the NBD socket.
*)
@@ -419,7 +441,12 @@ If the messages above are not sufficient to diagnose the problem
then add the
with_open_out ovf_file (fun chan -> output_string chan ovf);
if Python_script.run_command createvm_script json_params [ovf_file] <> 0
then
- error (f_"failed to create virtual machine, see earlier errors")
+ error (f_"failed to create virtual machine, see earlier errors");
+
+ (* The virtual machine was created successfully, so there are no disks
+ * to remove manually.
+ *)
+ disks_uuids <- []
(3) Remove this hunk.
I would be happy with this patch if it was change in the way described
above.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW