[Libguestfs] [PATCH v2 1/2] v2v: register also aliases of input/output modules

Pino Toscano ptoscano at redhat.com
Tue Jul 19 12:28:30 UTC 2016


Extend Modules_list to handle also aliases for input and output modules,
and use this to register the existing aliases.
---
 v2v/input_disk.ml    |  2 +-
 v2v/modules_list.ml  | 25 +++++++++++++++++++++----
 v2v/modules_list.mli |  8 ++++----
 v2v/output_local.ml  |  2 +-
 v2v/output_rhev.ml   |  2 +-
 5 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/v2v/input_disk.ml b/v2v/input_disk.ml
index 17ad61d..d21815d 100644
--- a/v2v/input_disk.ml
+++ b/v2v/input_disk.ml
@@ -101,4 +101,4 @@ class input_disk input_format disk = object
 end
 
 let input_disk = new input_disk
-let () = Modules_list.register_input_module "disk"
+let () = Modules_list.register_input_module ~alias:"local" "disk"
diff --git a/v2v/modules_list.ml b/v2v/modules_list.ml
index 36a08c0..5649b02 100644
--- a/v2v/modules_list.ml
+++ b/v2v/modules_list.ml
@@ -21,11 +21,28 @@ open Common_utils
 let input_modules = ref []
 and output_modules = ref []
 
-let register_input_module name = push_front name input_modules
-and register_output_module name = push_front name output_modules
+let rec register_input_module ?alias name = register ?alias name input_modules
+and register_output_module ?alias name = register ?alias name output_modules
+and register ?alias name l =
+  push_front (name, false) l;
+  (match alias with
+  | None -> ()
+  | Some alias -> push_front (alias, true) l
+  )
 
-let input_modules () = List.sort compare !input_modules
-and output_modules () = List.sort compare !output_modules
+let list_out ~with_alias l =
+  let l =
+    if with_alias then l
+    else
+      List.filter (
+        fun (_, is_alias) ->
+          not is_alias
+      ) l in
+  let l = List.map fst l in
+  List.sort compare l
+
+let input_modules ?(with_alias = false) () = list_out ~with_alias !input_modules
+and output_modules ?(with_alias = false) () = list_out ~with_alias !output_modules
 
 type conversion_fn =
   keep_serial_console:bool ->
diff --git a/v2v/modules_list.mli b/v2v/modules_list.mli
index 0560832..7f0af4b 100644
--- a/v2v/modules_list.mli
+++ b/v2v/modules_list.mli
@@ -18,16 +18,16 @@
 
 (** List of input, output and conversion modules. *)
 
-val register_input_module : string -> unit
+val register_input_module : ?alias:string -> string -> unit
 (** Register an input module by name. *)
 
-val register_output_module : string -> unit
+val register_output_module : ?alias:string -> string -> unit
 (** Register an output module by name. *)
 
-val input_modules : unit -> string list
+val input_modules : ?with_alias:bool -> unit -> string list
 (** Return the list of input modules. *)
 
-val output_modules : unit -> string list
+val output_modules : ?with_alias:bool -> unit -> string list
 (** Return the list of output modules. *)
 
 type conversion_fn =
diff --git a/v2v/output_local.ml b/v2v/output_local.ml
index 47da929..ccd52f2 100644
--- a/v2v/output_local.ml
+++ b/v2v/output_local.ml
@@ -61,4 +61,4 @@ class output_local dir = object
 end
 
 let output_local = new output_local
-let () = Modules_list.register_output_module "local"
+let () = Modules_list.register_output_module ~alias:"disk" "local"
diff --git a/v2v/output_rhev.ml b/v2v/output_rhev.ml
index e45043b..90ac307 100644
--- a/v2v/output_rhev.ml
+++ b/v2v/output_rhev.ml
@@ -282,4 +282,4 @@ object
 end
 
 let output_rhev = new output_rhev
-let () = Modules_list.register_output_module "rhev"
+let () = Modules_list.register_output_module ~alias:"ovirt" "rhev"
-- 
2.7.4




More information about the Libguestfs mailing list