From 7000ed6d790313a927c8845bc17d684661973507 Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Mon, 11 Jul 2016 15:25:13 +0300 Subject: [PATCH 1/2] driver: Skip fetching DHCP details in #read_host_only_interfaces This data is not needed in 'action/network', so we can skip it. --- lib/vagrant-parallels/driver/base.rb | 9 +++++++++ lib/vagrant-parallels/driver/pd_10.rb | 11 ----------- lib/vagrant-parallels/driver/pd_8.rb | 11 ----------- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/lib/vagrant-parallels/driver/base.rb b/lib/vagrant-parallels/driver/base.rb index 814f0a9a..5837cd8b 100644 --- a/lib/vagrant-parallels/driver/base.rb +++ b/lib/vagrant-parallels/driver/base.rb @@ -406,6 +406,15 @@ def read_host_info end # Returns a list of available host only interfaces. + # Each interface is represented as a Hash with the following details: + # + # { + # name: 'Host-Only', # Parallels Network ID + # bound_to: 'vnic1', # interface name + # ip: '10.37.129.2', # IP address of the interface + # netmask: '255.255.255.0', # netmask associated with the interface + # status: 'Up' # status of the interface + # } # # @return [Array String>] def read_host_only_interfaces diff --git a/lib/vagrant-parallels/driver/pd_10.rb b/lib/vagrant-parallels/driver/pd_10.rb index ba56fdbd..f3daed38 100644 --- a/lib/vagrant-parallels/driver/pd_10.rb +++ b/lib/vagrant-parallels/driver/pd_10.rb @@ -149,17 +149,6 @@ def read_host_only_interfaces iface[:status] = 'Up' end - # There may be a fake DHCPv4 parameters - # We can trust them only if adapter IP and DHCP IP are in the same subnet - dhcp_info = net_info['DHCPv4 server'] - if dhcp_info && (network_address(iface[:ip], iface[:netmask]) == - network_address(dhcp_info['Server address'], iface[:netmask])) - iface[:dhcp] = { - ip: dhcp_info['Server address'], - lower: dhcp_info['IP scope start address'], - upper: dhcp_info['IP scope end address'] - } - end hostonly_ifaces << iface end hostonly_ifaces diff --git a/lib/vagrant-parallels/driver/pd_8.rb b/lib/vagrant-parallels/driver/pd_8.rb index 986b4b5c..0b9e3456 100644 --- a/lib/vagrant-parallels/driver/pd_8.rb +++ b/lib/vagrant-parallels/driver/pd_8.rb @@ -115,17 +115,6 @@ def read_host_only_interfaces iface[:status] = 'Up' end - # There may be a fake DHCPv4 parameters - # We can trust them only if adapter IP and DHCP IP are in the same subnet - dhcp_info = net_info['DHCPv4 server'] - if dhcp_info && (network_address(iface[:ip], iface[:netmask]) == - network_address(dhcp_info['Server address'], iface[:netmask])) - iface[:dhcp] = { - ip: dhcp_info['Server address'], - lower: dhcp_info['IP scope start address'], - upper: dhcp_info['IP scope end address'] - } - end hostonly_ifaces << iface end hostonly_ifaces From 2cda6561a57ad81930fd317a23056be5769025ec Mon Sep 17 00:00:00 2001 From: Mikhail Zholobov Date: Mon, 11 Jul 2016 15:29:16 +0300 Subject: [PATCH 2/2] action/network: Fix an exception when the host is not connected to host-only interface --- lib/vagrant-parallels/action/network.rb | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/vagrant-parallels/action/network.rb b/lib/vagrant-parallels/action/network.rb index 0539d25d..ac6b9737 100644 --- a/lib/vagrant-parallels/action/network.rb +++ b/lib/vagrant-parallels/action/network.rb @@ -444,20 +444,18 @@ def hostonly_create_network(config) # This finds a matching host only network for the given configuration. def hostonly_find_matching_network(config) - existing = @env[:machine].provider.driver.read_host_only_interfaces + this_netaddr = network_address(config[:ip], config[:netmask]) - if config[:name] - # Search networks strongly by specified name - matched_iface = existing.detect { |i| config[:name] == i[:name] } - else - # Name is not specified - search by network address - this_netaddr = network_address(config[:ip], config[:netmask]) - matched_iface = existing.detect do |i| - this_netaddr == network_address(i[:ip], i[:netmask]) + @env[:machine].provider.driver.read_host_only_interfaces.each do |interface| + return interface if config[:name] && config[:name] == interface[:name] + + if interface[:ip] + return interface if this_netaddr == \ + network_address(interface[:ip], interface[:netmask]) end end - matched_iface || nil + nil end end end