[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 1/2] v2v: -i disk: Move code that creates name from disk to separate module.



Simple code motion.
---
 v2v/Makefile.am        |  2 ++
 v2v/input_disk.ml      | 21 ++-------------------
 v2v/name_from_disk.ml  | 41 +++++++++++++++++++++++++++++++++++++++++
 v2v/name_from_disk.mli | 24 ++++++++++++++++++++++++
 4 files changed, 69 insertions(+), 19 deletions(-)
 create mode 100644 v2v/name_from_disk.ml
 create mode 100644 v2v/name_from_disk.mli

diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index 5c147ee..9b2f955 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -42,6 +42,7 @@ SOURCES_MLI = \
 	linux.mli \
 	linux_bootloaders.mli \
 	modules_list.mli \
+	name_from_disk.mli \
 	output_glance.mli \
 	output_libvirt.mli \
 	output_local.mli \
@@ -64,6 +65,7 @@ SOURCES_ML = \
 	xml.ml \
 	uefi.ml \
 	utils.ml \
+	name_from_disk.ml \
 	vCenter.ml \
 	domainxml.ml \
 	DOM.ml \
diff --git a/v2v/input_disk.ml b/v2v/input_disk.ml
index 3926602..e07222f 100644
--- a/v2v/input_disk.ml
+++ b/v2v/input_disk.ml
@@ -23,6 +23,7 @@ open Common_utils
 
 open Types
 open Utils
+open Name_from_disk
 
 class input_disk input_format disk = object
   inherit input
@@ -42,25 +43,7 @@ class input_disk input_format disk = object
      * the filename passed in.  Users can override this using the
      * `-on name' option.
      *)
-    let name =
-      let name = Filename.basename disk in
-      (* Remove the extension (or suffix), only if it's one usually
-       * used for disk images. *)
-      let suffixes = [
-        ".img"; ".qcow2"; ".raw"; ".vmdk";
-        "-sda";
-      ] in
-      let rec loop = function
-        | suff :: xs ->
-          if Filename.check_suffix name suff then
-            Filename.chop_suffix name suff
-          else
-            loop xs
-        | [] -> name
-      in
-      loop suffixes in
-    if name = "" then
-      error (f_"-i disk: invalid input filename (%s)") disk;
+    let name = name_from_disk disk in
 
     (* Get the absolute path to the disk file. *)
     let disk_absolute = absolute_path disk in
diff --git a/v2v/name_from_disk.ml b/v2v/name_from_disk.ml
new file mode 100644
index 0000000..73caf34
--- /dev/null
+++ b/v2v/name_from_disk.ml
@@ -0,0 +1,41 @@
+(* virt-v2v
+ * Copyright (C) 2009-2016 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+open Common_gettext.Gettext
+open Common_utils
+
+let name_from_disk disk =
+  let name = Filename.basename disk in
+  (* Remove the extension (or suffix), only if it's one usually
+   * used for disk images. *)
+  let suffixes = [
+    ".img"; ".qcow2"; ".raw"; ".vmdk";
+    "-sda";
+  ] in
+  let rec loop = function
+    | suff :: xs ->
+       if Filename.check_suffix name suff then
+         Filename.chop_suffix name suff
+       else
+         loop xs
+    | [] -> name
+  in
+  let name = loop suffixes in
+  if name = "" then
+    error (f_"invalid input filename (%s)") disk;
+  name
diff --git a/v2v/name_from_disk.mli b/v2v/name_from_disk.mli
new file mode 100644
index 0000000..db3ee17
--- /dev/null
+++ b/v2v/name_from_disk.mli
@@ -0,0 +1,24 @@
+(* virt-v2v
+ * Copyright (C) 2009-2016 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+(** Derive the source name from a disk name. *)
+
+val name_from_disk : string -> string
+(** Take a disk name and derive from it a suitable source name.
+
+    Used in particular by [-i disk] mode. *)
-- 
2.9.3


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]