Richard W.M. Jones
2016-Sep-09 14:09 UTC
[Libguestfs] [PATCH 0/2] v2v: -i ova: Derive the name from the OVA filename.
Don't use "default", choose a better default name if <Name> is not present in the OVF. Rich.
Richard W.M. Jones
2016-Sep-09 14:09 UTC
[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
Richard W.M. Jones
2016-Sep-09 14:09 UTC
[Libguestfs] [PATCH 2/2] v2v: -i ova: Derive the name from the OVA filename.
If the guest has no <Name> element in the OVF, previously we chose "default" as the name. This changes that so it uses a name derived from the basename of the OVA file instead. For example: virt-v2v -i ova /path/to/myguest.ova [...] would use "myguest" as the name (assuming no <Name> was present). Modifies the behaviour of commit 1ae4252c93c685cb8561b55c1231502b37212b5a. --- v2v/input_ova.ml | 3 ++- v2v/name_from_disk.ml | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/v2v/input_ova.ml b/v2v/input_ova.ml index 974caeb..c1dff71 100644 --- a/v2v/input_ova.ml +++ b/v2v/input_ova.ml @@ -23,6 +23,7 @@ open Common_utils open Types open Utils +open Name_from_disk class input_ova ova let tmpdir @@ -186,7 +187,7 @@ object match xpath_string "/ovf:Envelope/ovf:VirtualSystem/ovf:Name/text()" with | None | Some "" -> warning (f_"could not parse ovf:Name from OVF document"); - "default" + name_from_disk ova | Some name -> name in (* Search for memory. *) diff --git a/v2v/name_from_disk.ml b/v2v/name_from_disk.ml index 73caf34..878b7c6 100644 --- a/v2v/name_from_disk.ml +++ b/v2v/name_from_disk.ml @@ -26,6 +26,7 @@ let name_from_disk disk let suffixes = [ ".img"; ".qcow2"; ".raw"; ".vmdk"; "-sda"; + ".ova"; ] in let rec loop = function | suff :: xs -> -- 2.9.3
Pino Toscano
2016-Sep-09 14:26 UTC
Re: [Libguestfs] [PATCH 1/2] v2v: -i disk: Move code that creates name from disk to separate module.
On Friday, 9 September 2016 15:09:56 CEST Richard W.M. Jones wrote:> 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.mliLooks good -- I'd have put it in Utils though, instead of a new module with just a single simple function. -- Pino Toscano
Pino Toscano
2016-Sep-09 14:27 UTC
Re: [Libguestfs] [PATCH 2/2] v2v: -i ova: Derive the name from the OVA filename.
On Friday, 9 September 2016 15:09:57 CEST Richard W.M. Jones wrote:> diff --git a/v2v/name_from_disk.ml b/v2v/name_from_disk.ml > index 73caf34..878b7c6 100644 > --- a/v2v/name_from_disk.ml > +++ b/v2v/name_from_disk.ml > @@ -26,6 +26,7 @@ let name_from_disk disk > let suffixes = [ > ".img"; ".qcow2"; ".raw"; ".vmdk"; > "-sda"; > + ".ova";Minor niptick: can you please move the ".ova" element in the first line of suffixes, sorted up there? Eg ".img"; ".ova"; ".qcow2"; ".raw"; ".vmdk"; LGTM otherwise. -- Pino Toscano
Shahar Havivi
2016-Sep-11 07:27 UTC
Re: [Libguestfs] [PATCH 2/2] v2v: -i ova: Derive the name from the OVA filename.
On 09.09.16 15:09, Richard W.M. Jones wrote:> If the guest has no <Name> element in the OVF, previously we chose > "default" as the name. This changes that so it uses a name derived > from the basename of the OVA file instead. > > For example: > > virt-v2v -i ova /path/to/myguest.ova [...] > > would use "myguest" as the name (assuming no <Name> was present).+1
Possibly Parallel Threads
- [PATCH v2] v2v: disk: strip only common extension (RHBZ#1365005)
- [PATCH 0/2] v2v: -i ova: Derive the name from the OVA filename.
- [PATCH] sparsify, v2v: use Common_utils.absolute_path
- [PATCH] v2v: Support <listen type='socket'> and <listen type='none'> (RHBZ#1378022).
- [PATCH 2/2] v2v: -i ova: Derive the name from the OVA filename.