From 28574348b99365651477bac1ae20f64816743a78 Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 12 Jan 2023 11:52:14 -0800 Subject: [PATCH] Read only machine port forward info In the VM config file port forward information is captured in the Snapshot defition as well as the VM definition. This causes duplicates in port forward entries if the file is queried for all available network adapters. Querying the VM config file for the the Network Adapters only part of the Machine definition resolves this and yields the most up to date port forward info. --- .../virtualbox/driver/version_7_0.rb | 2 +- .../virtualbox/driver/version_7_0_test.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/plugins/providers/virtualbox/driver/version_7_0.rb b/plugins/providers/virtualbox/driver/version_7_0.rb index febf529d2..fcb6cbdfb 100644 --- a/plugins/providers/virtualbox/driver/version_7_0.rb +++ b/plugins/providers/virtualbox/driver/version_7_0.rb @@ -257,7 +257,7 @@ module VagrantPlugins File.open(result[:path], "r") do |f| doc = REXML::Document.new(f) - networks = REXML::XPath.each(doc.root, "//Adapter") + networks = REXML::XPath.each(doc.root, "Machine/Hardware/Network/Adapter") networks.each do |net| REXML::XPath.each(doc.root, net.xpath + "/NAT/Forwarding") do |fwd| # Result Array values: diff --git a/test/unit/plugins/providers/virtualbox/driver/version_7_0_test.rb b/test/unit/plugins/providers/virtualbox/driver/version_7_0_test.rb index df6519c30..7fed25b4a 100644 --- a/test/unit/plugins/providers/virtualbox/driver/version_7_0_test.rb +++ b/test/unit/plugins/providers/virtualbox/driver/version_7_0_test.rb @@ -683,6 +683,25 @@ end VBOX_VMCONFIG_FILE=%( + + + + + + + + + + + + + + + + + + +