From b9f9ffcc573a7757da2df95ef6b3a86bec90202b Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 18 Nov 2024 20:48:06 +0100 Subject: [PATCH] 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 --- src/PVE/GuestImport/OVF.pm | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/PVE/GuestImport/OVF.pm b/src/PVE/GuestImport/OVF.pm index 264ee6f..7dc4b24 100644 --- a/src/PVE/GuestImport/OVF.pm +++ b/src/PVE/GuestImport/OVF.pm @@ -204,9 +204,19 @@ sub parse_ovf { # easy xpath # walk down the dom until we find the matching XML element - my $xpath_find_name = "/ovf:Envelope/ovf:VirtualSystem/ovf:Name"; - my $ovf_name = $xpc->findvalue($xpath_find_name); - + my $ovf_name = $xpc->findvalue("/ovf:Envelope/ovf:VirtualSystem/ovf:Name"); + if (!$ovf_name) { + # this is a bit of a hack, but best-effort and can only win here + my @nodes = $xpc->findnodes("/ovf:Envelope/ovf:VirtualSystem"); + if (my $virtual_system_node = shift @nodes) { + for my $attr ($virtual_system_node->attributes()) { + if ($attr->nodeName() eq 'ovf:id') { + $ovf_name = $attr->getValue(); + last; + } + } + } + } if ($ovf_name) { # PVE::QemuServer::confdesc requires a valid DNS name $ovf_name =~ s/\s+/-/g;