]> git.proxmox.com Git - qemu-server.git/commitdiff
importovf: fix import of ovfs without default namespaces
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 23 Apr 2020 10:46:48 +0000 (12:46 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 27 Apr 2020 11:12:49 +0000 (13:12 +0200)
Some OVF files to not declare 'rasd' as a default namespace (in the
top level Envelope element), but inline in each element (e.g.
<rasd:HostResource xmlns:rasd="foo">...</rasd:HostResource>)

This trips up our relative findvalue with
> XPath error : Undefined namespace prefix

To avoid this, search in the global XPathContext (where we register
those namespaces ourselves) and pass the item_node as context
parameter.

This works then for both cases

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/QemuServer/OVF.pm

index 7ee4dc8568ee256b569580c41c50d6a49ef8f34d..536e0eb85c1ab217ebcda082ccd8886eab8e679e 100644 (file)
@@ -155,7 +155,7 @@ sub parse_ovf {
 
        # from Item, find corresponding Disk node
        # here the dot means the search should start from the current element in dom
-       my $host_resource = $item_node->findvalue('./rasd:HostResource');
+       my $host_resource = $xpc->findvalue('rasd:HostResource', $item_node);
        my $disk_section_path;
        my $disk_id;
 
@@ -194,7 +194,7 @@ ovf:Disk[\@ovf:diskId='%s']/\@ovf:fileRef", $disk_id);
        print "file path: $filepath\n" if $debug;
 
        # from Item, find owning Controller type
-       my $controller_id = $item_node->findvalue('./rasd:Parent');
+       my $controller_id = $xpc->findvalue('rasd:Parent', $item_node);
        my $xpath_find_parent_type = sprintf("/ovf:Envelope/ovf:VirtualSystem/ovf:VirtualHardwareSection/\
 ovf:Item[rasd:InstanceID='%s']/rasd:ResourceType", $controller_id);
        my $controller_type = $xpc->findvalue($xpath_find_parent_type);
@@ -205,7 +205,7 @@ ovf:Item[rasd:InstanceID='%s']/rasd:ResourceType", $controller_id);
        print "owning controller type: $controller_type\n" if $debug;
 
        # extract corresponding Controller node details
-       my $adress_on_controller = $item_node->findvalue('./rasd:AddressOnParent');
+       my $adress_on_controller = $xpc->findvalue('rasd:AddressOnParent', $item_node);
        my $pve_disk_address = id_to_pve($controller_type) . $adress_on_controller;
 
        # resolve symlinks and relative path components