Commit Graph

16 Commits

Author SHA1 Message Date
5a66c27cc6 auto-format code using perltidy with Proxmox style guide
using the new top-level `make tidy` target, which calls perltidy via
our wrapper to enforce the desired style as closely as possible.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2025-06-11 10:03:21 +02:00
936fbe3f35 file size info: prepare to make format parameter mandatory
In almost all cases, there already is an expected format. Allow
setting a special value 'auto-detect' to opt-in to automatic format
detection by 'qemu-img' for the exceptions.

Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
2024-12-09 08:55:10 +01:00
b9f9ffcc57 ovf import: guest name: fallback to the id from the VirtualSystem node
Seems that some OVF do not have a ovf:Name element, but do have a
ovf:id attribute inside the ovf:VirtualSystem node that spells out
what the archive contains. So fallback to this attributes value if we
could not find any explicit name, can only win here, and the user
still can override this anyway.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-11-18 20:48:07 +01:00
af83df01a8 ovf import: guest name: normalize whitespace to minus
This is nicer from a readability POV, but replace a arbitrary amount
of whitespace by a single minus character to avoid making it look odd.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-11-18 20:46:36 +01:00
628bd29082 ovf import: disks: allow whitespaces in file path
Add a SAFE_CHAR_WITH_WHITESPACE_CLASS_RE sister variant of the shared
SAFE_CHAR_CLASS_RE shared regex to the base storage module, this use
case exist is a generic one after all, and use swap the untaint method
that parses the file a disk references to it.

Note that this is only the disk file name from inside the archive and
thus during the extraction to a staging/working directory, from there
it will be imported as volume allocated by the common storage system,
and thus follow our ordinary volume name scheme.

Improves disk detection when importing, e.g., the from upstream
provided GNS3 OVA.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-11-18 20:43:53 +01:00
f2a6bd2788 ovf import: disks: mave ovf namespace in resource path optional
Some OVFs like for example the one from the GNS3 OVA doesn't has that
namespace/prefix, and does't really hurts us to make it optional as
long as the rest is correct.

Brings us nearer to have working disks with GNS3.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-11-18 19:56:51 +01:00
426b0cc3aa ovf import: small code style cleanups
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-11-18 19:56:24 +01:00
5ae7d10fdc ovf import: regisiter "vmw" namespace
This is used when finding the firmware type, so register it here or
libxml/xpath will complain about an "Undefined namespace prefix"

The schema URL was taken from some OVFs found in the wild.

Reported-by: Filip Schauer <f.schauer@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-11-18 19:25:02 +01:00
0fdbc2845a ovf: implement parsing nics
by iterating over the relevant parts and trying to parse out the
'ResourceSubType'. The content of that is not standardized, but I only
ever found examples that are compatible with vmware, meaning it's
either 'e1000', 'e1000e' or 'vmxnet3' (in various capitalizations; thus
the `lc()`)

As a fallback i used e1000, since that is our default too, and should
work for most guest operating systems.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
2024-11-18 18:35:54 +01:00
d4fe3eeacc ovf: implement rudimentary boot order
simply add all parsed disks to the boot order in the order we encounter
them (similar to the esxi plugin).

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
2024-11-18 18:35:54 +01:00
468b39fa6c ovf: implement parsing out firmware type
it seems there is no part of the ovf standard that handles which type of
bios there is (at least i could not find it). Every ovf/ova i tested
either has no info about it, or has it in a vmware specific property
which we parse here.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
2024-11-18 18:35:54 +01:00
61e1576c5c ovf: implement parsing the ostype
use the standards info about the ostypes to map to our own
(see comment for link to the relevant part of the dmtf schema)

every type that is not listed we map to 'other', so no need to have it
in a list.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
2024-11-18 18:35:54 +01:00
cbf788754d ovf: improve and simplify path checking code
moves the filepath code a bit more closer to where it's actually used
checks the contained path before trying to find it's absolute path
properly add error handling to realpath

instead of checking the combined ovf_path + filepath, just make sure
filepath can't point to anythign besides a file in this directory
by checking for '.' and '..' (slashes are not allowed in SAFE_CHAR_CLASS_RE)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
2024-11-18 18:35:54 +01:00
d482cc1c52 plugin: dir: handle ova files for import
since we want to handle ova files (which are only ovf+images bundled in
a tar file) for import, add code that handles that.

we introduce a valid volname for files contained in ovas like this:

 storage:import/archive.ova/disk-1.vmdk

by basically treating the last part of the path as the name for the
contained disk we want.

in that case we return 'import' as type with 'vmdk/qcow2/raw' as format
(we cannot use something like 'ova+vmdk' without extending the 'format'
parsing to that for all storages/formats. This is because it runs
though a verify format check at least once)

we then provide a function to use for that:

* extract_disk_from_import_file: this actually extracts the file from
  the archive. Currently only ova is supported, so the extraction with
  'tar' is hardcoded, but again we can easily extend/modify that should
  we need to.

  we currently extract into the either the import storage or a given
  target storage in the images directory so if the cleanup does not
  happen, the user can still see and interact with the image via
  api/cli/gui

we have to modify the `parse_ovf` a bit to handle the missing disk
images, and we parse the size out of the ovf part (since this is
informal only, it should be no problem if we cannot parse it sometimes)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
2024-11-18 18:35:54 +01:00
d955a46a32 plugin: dir: implement import content type
in DirPlugin and not Plugin (because of cyclic dependency of
Plugin -> OVF -> Storage -> Plugin otherwise)

only ovf is currently supported (though ova will be shown in import
listing), expects the files to not be in a subdir, and adjacent to the
ovf file.

listed will be all ovf/qcow2/raw/vmdk files.
ovf because it can be imported, and the rest because they can be used
in the 'import-from' part of qemu-server.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Reviewed-by: Fiona Ebner <f.ebner@proxmox.com>
2024-11-18 18:35:54 +01:00
5005ff5ab9 move OVF module over from qemu-server
Copy over the PVE::QemuServer::OVF module and relevant OVF tests from
the qemu-server package/repo.

We need it here for implementing the import content type support to
generic directory based plugins.
So it will also use PVE::Storage modules and thus anything higher, or
a different package, makes things only harder for now.

Put the OVF module under the new PVE::GuestImport module namespace.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
 [ TL: rework commit message to avoid file endings and clarify
   intentions ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2024-11-17 16:30:44 +01:00