Class: VagrantPlugins::ProviderVeertu::Action::NetworkFixIPv6
- Inherits:
-
Object
- Object
- VagrantPlugins::ProviderVeertu::Action::NetworkFixIPv6
- Includes:
- Vagrant::Util::Presence, Vagrant::Util::ScopedHashOverride
- Defined in:
- lib/vagrant-veertu/action/network_fix_ipv6.rb
Overview
This middleware works around a bug in Veertu where booting a VM with an IPv6 host-only network will someties lose the route to that machine.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#host_only_interface_names(env) ⇒ Array<String>
The list of interface names for host-only adapters.
-
#host_only_interfaces(env) ⇒ Array
The list of host_only_interfaces that are tied to a host-only adapter.
-
#initialize(app, env) ⇒ NetworkFixIPv6
constructor
A new instance of NetworkFixIPv6.
Constructor Details
#initialize(app, env) ⇒ NetworkFixIPv6
Returns a new instance of NetworkFixIPv6.
19 20 21 22 |
# File 'lib/vagrant-veertu/action/network_fix_ipv6.rb', line 19 def initialize(app, env) @logger = Log4r::Logger.new("vagrant::plugins::veertu::network") @app = app end |
Instance Method Details
#call(env) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vagrant-veertu/action/network_fix_ipv6.rb', line 24 def call(env) @env = env # Determine if we have an IPv6 network has_v6 = false env[:machine].config.vm.networks.each do |type, | next if type != :private_network = scoped_hash_override(, :veertu) next if [:ip].to_s.strip == "" if IPAddr.new([:ip]).ipv6? has_v6 = true break end end # Call up @app.call(env) # If we have no IPv6, forget it return if !has_v6 host_only_interfaces(env).each do |interface| next if !present?(interface[:ipv6]) next if interface[:status] != "Up" ip = IPAddr.new(interface[:ipv6]) ip |= ("1" * (128 - interface[:ipv6_prefix].to_i)).to_i(2) @logger.info("testing IPv6: #{ip}") begin UDPSocket.new(Socket::AF_INET6).connect(ip.to_s, 80) rescue Errno::EHOSTUNREACH @logger.info("IPv6 host unreachable. Fixing: #{ip}") env[:machine].provider.driver.reconfig_host_only(interface) end end end |
#host_only_interface_names(env) ⇒ Array<String>
The list of interface names for host-only adapters.
66 67 68 69 |
# File 'lib/vagrant-veertu/action/network_fix_ipv6.rb', line 66 def host_only_interface_names(env) env[:machine].provider.driver.read_network_interfaces .map { |_, i| i[:hostonly] if i[:type] == :hostonly }.compact end |
#host_only_interfaces(env) ⇒ Array
The list of host_only_interfaces that are tied to a host-only adapter.
73 74 75 76 77 |
# File 'lib/vagrant-veertu/action/network_fix_ipv6.rb', line 73 def host_only_interfaces(env) iface_names = self.host_only_interface_names(env) env[:machine].provider.driver.read_host_only_interfaces .select { |interface| iface_names.include?(interface[:name]) } end |