Separate logic into other functions for readability
This commit is contained in:
parent
bcf61d001b
commit
9ba8cfcd50
|
@ -3,6 +3,7 @@ require "socket"
|
||||||
|
|
||||||
require "log4r"
|
require "log4r"
|
||||||
|
|
||||||
|
require "vagrant/util/presence"
|
||||||
require "vagrant/util/scoped_hash_override"
|
require "vagrant/util/scoped_hash_override"
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
|
@ -12,6 +13,7 @@ module VagrantPlugins
|
||||||
# a VM with an IPv6 host-only network will someties lose the
|
# a VM with an IPv6 host-only network will someties lose the
|
||||||
# route to that machine.
|
# route to that machine.
|
||||||
class NetworkFixIPv6
|
class NetworkFixIPv6
|
||||||
|
include Vagrant::Util::Presence
|
||||||
include Vagrant::Util::ScopedHashOverride
|
include Vagrant::Util::ScopedHashOverride
|
||||||
|
|
||||||
def initialize(app, env)
|
def initialize(app, env)
|
||||||
|
@ -41,17 +43,15 @@ module VagrantPlugins
|
||||||
# If we have no IPv6, forget it
|
# If we have no IPv6, forget it
|
||||||
return if !has_v6
|
return if !has_v6
|
||||||
|
|
||||||
ifaces = env[:machine].provider.driver.read_network_interfaces
|
networks(env).each do |network|
|
||||||
ifaces.select! { |id, iface| iface[:type] == :hostonly }
|
next if !present?(network[:ipv6])
|
||||||
iface_names = ifaces.values.map { |iface| iface[:hostonly] }
|
next if network[:status] != "Up"
|
||||||
networks = env[:machine].provider.driver.read_host_only_interfaces
|
|
||||||
networks.select! { |network| iface_names.include?(network[:name]) }
|
ip = IPAddr.new(network[:ipv6])
|
||||||
networks.each do |network|
|
ip |= ("1" * (128 - network[:ipv6_prefix].to_i)).to_i(2)
|
||||||
next if network[:ipv6] == ""
|
|
||||||
next if network[:status] != 'Up'
|
|
||||||
ip = IPAddr.new(network[:ipv6]) |
|
|
||||||
('1' * (128 - network[:ipv6_prefix].to_i)).to_i(2)
|
|
||||||
@logger.info("testing IPv6: #{ip}")
|
@logger.info("testing IPv6: #{ip}")
|
||||||
|
|
||||||
begin
|
begin
|
||||||
UDPSocket.new(Socket::AF_INET6).connect(ip.to_s, 80)
|
UDPSocket.new(Socket::AF_INET6).connect(ip.to_s, 80)
|
||||||
rescue Errno::EHOSTUNREACH
|
rescue Errno::EHOSTUNREACH
|
||||||
|
@ -60,6 +60,21 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# The list of interface names for host-only adapters.
|
||||||
|
# @return [Array<String>]
|
||||||
|
def host_only_interface_names(env)
|
||||||
|
env[:machine].provider.driver.read_network_interfaces
|
||||||
|
.map { |_, i| i[:hostonly] if i[:type] == :hostonly }.compact
|
||||||
|
end
|
||||||
|
|
||||||
|
# The list of networks that are tied to a host-only adapter.
|
||||||
|
# @return [Array]
|
||||||
|
def networks(env)
|
||||||
|
iface_names = self.host_only_interface_names(env)
|
||||||
|
env[:machine].provider.driver.read_host_only_interfaces
|
||||||
|
.select { |network| iface_names.include?(network[:name]) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue