From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 973D31FF15F for ; Mon, 18 Nov 2024 16:31:48 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1614313A68; Mon, 18 Nov 2024 16:30:11 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Mon, 18 Nov 2024 16:29:10 +0100 Message-Id: <20241118152928.858590-8-d.csapak@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241118152928.858590-1-d.csapak@proxmox.com> References: <20241118152928.858590-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.016 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH storage v7 07/11] ovf: implement parsing nics X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" 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 Reviewed-by: Fiona Ebner --- src/PVE/GuestImport/OVF.pm | 23 ++++++++++++++++++++++- src/PVE/Storage/DirPlugin.pm | 2 +- src/test/run_ovf_tests.pl | 5 +++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/PVE/GuestImport/OVF.pm b/src/PVE/GuestImport/OVF.pm index d08cc51..4af58ed 100644 --- a/src/PVE/GuestImport/OVF.pm +++ b/src/PVE/GuestImport/OVF.pm @@ -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; diff --git a/src/PVE/Storage/DirPlugin.pm b/src/PVE/Storage/DirPlugin.pm index 0c32242..fb23e0a 100644 --- a/src/PVE/Storage/DirPlugin.pm +++ b/src/PVE/Storage/DirPlugin.pm @@ -293,7 +293,7 @@ sub get_import_metadata { 'create-args' => $res->{qm}, 'disks' => $disks, warnings => $warnings, - net => [], + net => $res->{net}, }; } diff --git a/src/test/run_ovf_tests.pl b/src/test/run_ovf_tests.pl index 3b04100..b8fa4b1 100755 --- a/src/test/run_ovf_tests.pl +++ b/src/test/run_ovf_tests.pl @@ -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'); -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel