5
0
mirror of git://git.proxmox.com/git/pve-storage.git synced 2024-12-22 13:34:16 +03:00

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>
This commit is contained in:
Thomas Lamprecht 2024-11-18 20:48:06 +01:00
parent af83df01a8
commit b9f9ffcc57

View File

@ -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;