Pino Toscano
2019-Sep-19 12:30 UTC
[Libguestfs] [PATCH 1/2] v2v: add optional tmpdir parameter for Python_script
Add an optional parameter for Python_script.create, to specific the
temporary directory to use instead of creating a new one.
---
v2v/python_script.ml | 13 ++++++++-----
v2v/python_script.mli | 5 ++++-
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/v2v/python_script.ml b/v2v/python_script.ml
index 3159373a1..6bb14ec1f 100644
--- a/v2v/python_script.ml
+++ b/v2v/python_script.ml
@@ -31,12 +31,15 @@ type script = {
path : string; (* Path to script. *)
}
-let create ?(name = "script.py") code +let create ?(name =
"script.py") ?tmpdir code let tmpdir - let base_dir =
(open_guestfs ())#get_cachedir () in
- let t = Mkdtemp.temp_dir ~base_dir "v2v." in
- rmdir_on_exit t;
- t in
+ match tmpdir with
+ | None ->
+ let base_dir = (open_guestfs ())#get_cachedir () in
+ let t = Mkdtemp.temp_dir ~base_dir "v2v." in
+ rmdir_on_exit t;
+ t
+ | Some dir -> dir in
let path = tmpdir // name in
with_open_out path (fun chan -> output_string chan code);
{ tmpdir; path }
diff --git a/v2v/python_script.mli b/v2v/python_script.mli
index c008eec1a..496ac60d0 100644
--- a/v2v/python_script.mli
+++ b/v2v/python_script.mli
@@ -20,11 +20,14 @@
type script
-val create : ?name:string -> string -> script
+val create : ?name:string -> ?tmpdir:string -> string -> script
(** Create a Python script object.
The optional parameter [?name] is a hint for the name of the script.
+ The optional parameter [?tmpdir] is the temporary directory to use
+ (instead of creating a new one).
+
The parameter is the Python code. Usually this is
[Some_source.code] where [some_source.ml] is generated from
the Python file by [v2v/embed.sh] (see also [v2v/Makefile.am]). *)
--
2.21.0
Pino Toscano
2019-Sep-19 12:30 UTC
[Libguestfs] [PATCH 2/2] v2v: -o rhv-upload: use same tmpdir for Python scripts
Make use of the temporary directory of the rhv-upload mode also for the
Python scripts that the mode creates, instead of creating new
directories.
---
v2v/output_rhv_upload.ml | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/v2v/output_rhv_upload.ml b/v2v/output_rhv_upload.ml
index eec9c5c79..78e9145c6 100644
--- a/v2v/output_rhv_upload.ml
+++ b/v2v/output_rhv_upload.ml
@@ -106,19 +106,19 @@ class output_rhv_upload output_alloc output_conn
(* Create Python scripts for precheck, vmcheck, plugin and create VM. *)
let precheck_script - Python_script.create
~name:"rhv-upload-precheck.py"
+ Python_script.create ~name:"rhv-upload-precheck.py" ~tmpdir
Output_rhv_upload_precheck_source.code in
let vmcheck_script - Python_script.create
~name:"rhv-upload-vmcheck.py"
+ Python_script.create ~name:"rhv-upload-vmcheck.py" ~tmpdir
Output_rhv_upload_vmcheck_source.code in
let plugin_script - Python_script.create
~name:"rhv-upload-plugin.py"
+ Python_script.create ~name:"rhv-upload-plugin.py" ~tmpdir
Output_rhv_upload_plugin_source.code in
let createvm_script - Python_script.create
~name:"rhv-upload-createvm.py"
+ Python_script.create ~name:"rhv-upload-createvm.py" ~tmpdir
Output_rhv_upload_createvm_source.code in
let deletedisks_script - Python_script.create
~name:"rhv-upload-deletedisks.py"
+ Python_script.create ~name:"rhv-upload-deletedisks.py" ~tmpdir
Output_rhv_upload_deletedisks_source.code in
(* Check that the 'ovirtsdk4' Python module is available. *)
--
2.21.0
Richard W.M. Jones
2019-Sep-19 18:50 UTC
Re: [Libguestfs] [PATCH 2/2] v2v: -o rhv-upload: use same tmpdir for Python scripts
On Thu, Sep 19, 2019 at 02:30:05PM +0200, Pino Toscano wrote:> Make use of the temporary directory of the rhv-upload mode also for the > Python scripts that the mode creates, instead of creating new > directories. > --- > v2v/output_rhv_upload.ml | 10 +++++----- > 1 file changed, 5 insertions(+), 5 deletions(-) > > diff --git a/v2v/output_rhv_upload.ml b/v2v/output_rhv_upload.ml > index eec9c5c79..78e9145c6 100644 > --- a/v2v/output_rhv_upload.ml > +++ b/v2v/output_rhv_upload.ml > @@ -106,19 +106,19 @@ class output_rhv_upload output_alloc output_conn > > (* Create Python scripts for precheck, vmcheck, plugin and create VM. *) > let precheck_script > - Python_script.create ~name:"rhv-upload-precheck.py" > + Python_script.create ~name:"rhv-upload-precheck.py" ~tmpdir > Output_rhv_upload_precheck_source.code in > let vmcheck_script > - Python_script.create ~name:"rhv-upload-vmcheck.py" > + Python_script.create ~name:"rhv-upload-vmcheck.py" ~tmpdir > Output_rhv_upload_vmcheck_source.code in > let plugin_script > - Python_script.create ~name:"rhv-upload-plugin.py" > + Python_script.create ~name:"rhv-upload-plugin.py" ~tmpdir > Output_rhv_upload_plugin_source.code in > let createvm_script > - Python_script.create ~name:"rhv-upload-createvm.py" > + Python_script.create ~name:"rhv-upload-createvm.py" ~tmpdir > Output_rhv_upload_createvm_source.code in > let deletedisks_script > - Python_script.create ~name:"rhv-upload-deletedisks.py" > + Python_script.create ~name:"rhv-upload-deletedisks.py" ~tmpdir > Output_rhv_upload_deletedisks_source.code inNice change, ACK. It could even be shorter with: let create = Python_script.create ~tmpdir in let precheck_script = create "rhv-upload-precheck.py" Output_rhv_upload_precheck_source.code in etc. (Labels can be omitted where they are non-ambiguous) 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
Seemingly Similar Threads
- [PATCH 1/2] v2v: add optional tmpdir parameter for Python_script
- [PATCH 2/2] v2v: -o rhv-upload: use same tmpdir for Python scripts
- [PATCH 0/8] v2v: various fixed for -o rhv-upload
- [PATCH virt-v2v v2 0/2] v2v: Large temporary directory handling.
- [PATCH virt-v2v v2 2/2] v2v: Allow large temporary directory to be set on a global basis.