|
|
aa0300 |
From 2ddaafb1b90169e4cb35b2e47116a95ff9045f6b Mon Sep 17 00:00:00 2001
|
|
|
aa0300 |
From: "Richard W.M. Jones" <rjones@redhat.com>
|
|
|
aa0300 |
Date: Fri, 9 Sep 2016 14:45:05 +0100
|
|
|
aa0300 |
Subject: [PATCH] v2v: -i disk: Move code that creates name from disk to
|
|
|
aa0300 |
separate module.
|
|
|
aa0300 |
|
|
|
aa0300 |
Simple code motion.
|
|
|
aa0300 |
|
|
|
aa0300 |
(cherry picked from commit 312379c8a61cd4a16aa7c80c1adda3081e601d43)
|
|
|
aa0300 |
---
|
|
|
aa0300 |
v2v/Makefile.am | 2 ++
|
|
|
aa0300 |
v2v/input_disk.ml | 21 ++-------------------
|
|
|
aa0300 |
v2v/name_from_disk.ml | 41 +++++++++++++++++++++++++++++++++++++++++
|
|
|
aa0300 |
v2v/name_from_disk.mli | 24 ++++++++++++++++++++++++
|
|
|
aa0300 |
4 files changed, 69 insertions(+), 19 deletions(-)
|
|
|
aa0300 |
create mode 100644 v2v/name_from_disk.ml
|
|
|
aa0300 |
create mode 100644 v2v/name_from_disk.mli
|
|
|
aa0300 |
|
|
|
aa0300 |
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
|
|
|
aa0300 |
index c1ebb17..f9a0796 100644
|
|
|
aa0300 |
--- a/v2v/Makefile.am
|
|
|
aa0300 |
+++ b/v2v/Makefile.am
|
|
|
aa0300 |
@@ -62,6 +62,7 @@ SOURCES_MLI = \
|
|
|
aa0300 |
inspect_source.mli \
|
|
|
aa0300 |
linux.mli \
|
|
|
aa0300 |
modules_list.mli \
|
|
|
aa0300 |
+ name_from_disk.mli \
|
|
|
aa0300 |
output_glance.mli \
|
|
|
aa0300 |
output_libvirt.mli \
|
|
|
aa0300 |
output_local.mli \
|
|
|
aa0300 |
@@ -84,6 +85,7 @@ SOURCES_ML = \
|
|
|
aa0300 |
xml.ml \
|
|
|
aa0300 |
uefi.ml \
|
|
|
aa0300 |
utils.ml \
|
|
|
aa0300 |
+ name_from_disk.ml \
|
|
|
aa0300 |
vCenter.ml \
|
|
|
aa0300 |
domainxml.ml \
|
|
|
aa0300 |
DOM.ml \
|
|
|
aa0300 |
diff --git a/v2v/input_disk.ml b/v2v/input_disk.ml
|
|
|
aa0300 |
index b6c9089..9a2ef08 100644
|
|
|
aa0300 |
--- a/v2v/input_disk.ml
|
|
|
aa0300 |
+++ b/v2v/input_disk.ml
|
|
|
aa0300 |
@@ -23,6 +23,7 @@ open Common_utils
|
|
|
aa0300 |
|
|
|
aa0300 |
open Types
|
|
|
aa0300 |
open Utils
|
|
|
aa0300 |
+open Name_from_disk
|
|
|
aa0300 |
|
|
|
aa0300 |
class input_disk input_format disk = object
|
|
|
aa0300 |
inherit input
|
|
|
aa0300 |
@@ -42,25 +43,7 @@ class input_disk input_format disk = object
|
|
|
aa0300 |
* the filename passed in. Users can override this using the
|
|
|
aa0300 |
* `-on name' option.
|
|
|
aa0300 |
*)
|
|
|
aa0300 |
- let name =
|
|
|
aa0300 |
- let name = Filename.basename disk in
|
|
|
aa0300 |
- (* Remove the extension (or suffix), only if it's one usually
|
|
|
aa0300 |
- * used for disk images. *)
|
|
|
aa0300 |
- let suffixes = [
|
|
|
aa0300 |
- ".img"; ".qcow2"; ".raw"; ".vmdk";
|
|
|
aa0300 |
- "-sda";
|
|
|
aa0300 |
- ] in
|
|
|
aa0300 |
- let rec loop = function
|
|
|
aa0300 |
- | suff :: xs ->
|
|
|
aa0300 |
- if Filename.check_suffix name suff then
|
|
|
aa0300 |
- Filename.chop_suffix name suff
|
|
|
aa0300 |
- else
|
|
|
aa0300 |
- loop xs
|
|
|
aa0300 |
- | [] -> name
|
|
|
aa0300 |
- in
|
|
|
aa0300 |
- loop suffixes in
|
|
|
aa0300 |
- if name = "" then
|
|
|
aa0300 |
- error (f_"-i disk: invalid input filename (%s)") disk;
|
|
|
aa0300 |
+ let name = name_from_disk disk in
|
|
|
aa0300 |
|
|
|
aa0300 |
(* Get the absolute path to the disk file. *)
|
|
|
aa0300 |
let disk_absolute = absolute_path disk in
|
|
|
aa0300 |
diff --git a/v2v/name_from_disk.ml b/v2v/name_from_disk.ml
|
|
|
aa0300 |
new file mode 100644
|
|
|
aa0300 |
index 0000000..73caf34
|
|
|
aa0300 |
--- /dev/null
|
|
|
aa0300 |
+++ b/v2v/name_from_disk.ml
|
|
|
aa0300 |
@@ -0,0 +1,41 @@
|
|
|
aa0300 |
+(* virt-v2v
|
|
|
aa0300 |
+ * Copyright (C) 2009-2016 Red Hat Inc.
|
|
|
aa0300 |
+ *
|
|
|
aa0300 |
+ * This program is free software; you can redistribute it and/or modify
|
|
|
aa0300 |
+ * it under the terms of the GNU General Public License as published by
|
|
|
aa0300 |
+ * the Free Software Foundation; either version 2 of the License, or
|
|
|
aa0300 |
+ * (at your option) any later version.
|
|
|
aa0300 |
+ *
|
|
|
aa0300 |
+ * This program is distributed in the hope that it will be useful,
|
|
|
aa0300 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
aa0300 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
aa0300 |
+ * GNU General Public License for more details.
|
|
|
aa0300 |
+ *
|
|
|
aa0300 |
+ * You should have received a copy of the GNU General Public License along
|
|
|
aa0300 |
+ * with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
aa0300 |
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
aa0300 |
+ *)
|
|
|
aa0300 |
+
|
|
|
aa0300 |
+open Common_gettext.Gettext
|
|
|
aa0300 |
+open Common_utils
|
|
|
aa0300 |
+
|
|
|
aa0300 |
+let name_from_disk disk =
|
|
|
aa0300 |
+ let name = Filename.basename disk in
|
|
|
aa0300 |
+ (* Remove the extension (or suffix), only if it's one usually
|
|
|
aa0300 |
+ * used for disk images. *)
|
|
|
aa0300 |
+ let suffixes = [
|
|
|
aa0300 |
+ ".img"; ".qcow2"; ".raw"; ".vmdk";
|
|
|
aa0300 |
+ "-sda";
|
|
|
aa0300 |
+ ] in
|
|
|
aa0300 |
+ let rec loop = function
|
|
|
aa0300 |
+ | suff :: xs ->
|
|
|
aa0300 |
+ if Filename.check_suffix name suff then
|
|
|
aa0300 |
+ Filename.chop_suffix name suff
|
|
|
aa0300 |
+ else
|
|
|
aa0300 |
+ loop xs
|
|
|
aa0300 |
+ | [] -> name
|
|
|
aa0300 |
+ in
|
|
|
aa0300 |
+ let name = loop suffixes in
|
|
|
aa0300 |
+ if name = "" then
|
|
|
aa0300 |
+ error (f_"invalid input filename (%s)") disk;
|
|
|
aa0300 |
+ name
|
|
|
aa0300 |
diff --git a/v2v/name_from_disk.mli b/v2v/name_from_disk.mli
|
|
|
aa0300 |
new file mode 100644
|
|
|
aa0300 |
index 0000000..db3ee17
|
|
|
aa0300 |
--- /dev/null
|
|
|
aa0300 |
+++ b/v2v/name_from_disk.mli
|
|
|
aa0300 |
@@ -0,0 +1,24 @@
|
|
|
aa0300 |
+(* virt-v2v
|
|
|
aa0300 |
+ * Copyright (C) 2009-2016 Red Hat Inc.
|
|
|
aa0300 |
+ *
|
|
|
aa0300 |
+ * This program is free software; you can redistribute it and/or modify
|
|
|
aa0300 |
+ * it under the terms of the GNU General Public License as published by
|
|
|
aa0300 |
+ * the Free Software Foundation; either version 2 of the License, or
|
|
|
aa0300 |
+ * (at your option) any later version.
|
|
|
aa0300 |
+ *
|
|
|
aa0300 |
+ * This program is distributed in the hope that it will be useful,
|
|
|
aa0300 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
aa0300 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
aa0300 |
+ * GNU General Public License for more details.
|
|
|
aa0300 |
+ *
|
|
|
aa0300 |
+ * You should have received a copy of the GNU General Public License along
|
|
|
aa0300 |
+ * with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
aa0300 |
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
aa0300 |
+ *)
|
|
|
aa0300 |
+
|
|
|
aa0300 |
+(** Derive the source name from a disk name. *)
|
|
|
aa0300 |
+
|
|
|
aa0300 |
+val name_from_disk : string -> string
|
|
|
aa0300 |
+(** Take a disk name and derive from it a suitable source name.
|
|
|
aa0300 |
+
|
|
|
aa0300 |
+ Used in particular by [-i disk] mode. *)
|
|
|
aa0300 |
--
|
|
|
aa0300 |
2.7.4
|
|
|
aa0300 |
|