mirror of
git://git.proxmox.com/git/pve-storage.git
synced 2025-03-11 16:58:28 +03:00
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>
This commit is contained in:
parent
d4fe3eeacc
commit
0fdbc2845a
@ -119,6 +119,12 @@ sub get_ostype {
|
||||
return $ostype_ids->{$id} // 'other';
|
||||
}
|
||||
|
||||
my $allowed_nic_models = [
|
||||
'e1000',
|
||||
'e1000e',
|
||||
'vmxnet3',
|
||||
];
|
||||
|
||||
sub find_by {
|
||||
my ($key, $param) = @_;
|
||||
foreach my $resource (@resources) {
|
||||
@ -359,7 +365,22 @@ ovf:Item[rasd:InstanceID='%s']/rasd:ResourceType", $controller_id);
|
||||
|
||||
$qm->{boot} = "order=" . join(';', @$boot_order) if scalar(@$boot_order) > 0;
|
||||
|
||||
return {qm => $qm, disks => \@disks};
|
||||
my $nic_id = dtmf_name_to_id('Ethernet Adapter');
|
||||
my $xpath_find_nics = "/ovf:Envelope/ovf:VirtualSystem/ovf:VirtualHardwareSection/ovf:Item[rasd:ResourceType=${nic_id}]";
|
||||
my @nic_items = $xpc->findnodes($xpath_find_nics);
|
||||
|
||||
my $net = {};
|
||||
|
||||
my $net_count = 0;
|
||||
for my $item_node (@nic_items) {
|
||||
my $model = $xpc->findvalue('rasd:ResourceSubType', $item_node);
|
||||
$model = lc($model);
|
||||
$model = 'e1000' if ! grep { $_ eq $model } @$allowed_nic_models;
|
||||
$net->{"net${net_count}"} = { model => $model };
|
||||
$net_count++;
|
||||
}
|
||||
|
||||
return {qm => $qm, disks => \@disks, net => $net};
|
||||
}
|
||||
|
||||
1;
|
||||
|
@ -293,7 +293,7 @@ sub get_import_metadata {
|
||||
'create-args' => $res->{qm},
|
||||
'disks' => $disks,
|
||||
warnings => $warnings,
|
||||
net => [],
|
||||
net => $res->{net},
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,11 @@ is($win10noNs->{disks}->[0]->{disk_address}, 'scsi0', 'single disk vm (no defaul
|
||||
is($win10noNs->{disks}->[0]->{backing_file}, "$test_manifests/Win10-Liz-disk1.vmdk", 'single disk vm (no default rasd NS) has the correct disk backing device');
|
||||
is($win10noNs->{disks}->[0]->{virtual_size}, 2048, 'single disk vm (no default rasd NS) has the correct size');
|
||||
|
||||
print "testing nics\n";
|
||||
is($win2008->{net}->{net0}->{model}, 'e1000', 'win2008 has correct nic model');
|
||||
is($win10->{net}->{net0}->{model}, 'e1000e', 'win10 has correct nic model');
|
||||
is($win10noNs->{net}->{net0}->{model}, 'e1000e', 'win10 (no default rasd NS) has correct nic model');
|
||||
|
||||
print "\ntesting vm.conf extraction\n";
|
||||
|
||||
is($win2008->{qm}->{boot}, 'order=scsi0;scsi1', 'win2008 VM boot is correct');
|
||||
|
Loading…
x
Reference in New Issue
Block a user