From 05fbb4ced2e717e0255da2bf04f30a408aac5cf8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 1 Oct 2015 08:50:47 -0400 Subject: [PATCH] providers/virtualbox: more support --- .../virtualbox/driver/version_4_0.rb | 26 ++++++++++++++--- .../virtualbox/driver/version_4_1.rb | 26 ++++++++++++++--- .../virtualbox/driver/version_4_2.rb | 28 +++++++++++++++---- 3 files changed, 67 insertions(+), 13 deletions(-) diff --git a/plugins/providers/virtualbox/driver/version_4_0.rb b/plugins/providers/virtualbox/driver/version_4_0.rb index 53361bbbb..66e9a37be 100644 --- a/plugins/providers/virtualbox/driver/version_4_0.rb +++ b/plugins/providers/virtualbox/driver/version_4_0.rb @@ -48,10 +48,19 @@ module VagrantPlugins interface = execute("hostonlyif", "create") name = interface[/^Interface '(.+?)' was successfully created$/, 1] - # Configure it - execute("hostonlyif", "ipconfig", name, - "--ip", options[:adapter_ip], - "--netmask", options[:netmask]) + # Get the IP so we can determine v4 vs v6 + ip = IPAddr.new(options[:adapter_ip]) + + # Configure + if ip.ipv4? + execute("hostonlyif", "ipconfig", name, + "--ip", options[:adapter_ip], + "--netmask", options[:netmask]) + elsif ip.ipv6? + execute("hostonlyif", "ipconfig", name, + "--ipv6", options[:adapter_ip], + "--netmasklengthv6", options[:netmask].to_s) + end # Return the details return { @@ -320,6 +329,10 @@ module VagrantPlugins info[:ip] = ip elsif netmask = line[/^NetworkMask:\s+(.+?)$/, 1] info[:netmask] = netmask + elsif line =~ /^IPV6Address:\s+(.+?)$/ + info[:ipv6] = $1.to_s.strip + elsif line =~ /^IPV6NetworkMaskPrefixLength:\s+(.+?)$/ + info[:ipv6_prefix] = $1.to_s.strip elsif status = line[/^Status:\s+(.+?)$/, 1] info[:status] = status end @@ -429,6 +442,11 @@ module VagrantPlugins results end + def reconfig_host_only(interface) + execute("hostonlyif", "ipconfig", interface[:name], + "--ipv6", interface[:ipv6]) + end + def remove_dhcp_server(network_name) execute("dhcpserver", "remove", "--netname", network_name) end diff --git a/plugins/providers/virtualbox/driver/version_4_1.rb b/plugins/providers/virtualbox/driver/version_4_1.rb index ae1830019..8830297ba 100644 --- a/plugins/providers/virtualbox/driver/version_4_1.rb +++ b/plugins/providers/virtualbox/driver/version_4_1.rb @@ -48,10 +48,19 @@ module VagrantPlugins interface = execute("hostonlyif", "create") name = interface[/^Interface '(.+?)' was successfully created$/, 1] - # Configure it - execute("hostonlyif", "ipconfig", name, - "--ip", options[:adapter_ip], - "--netmask", options[:netmask]) + # Get the IP so we can determine v4 vs v6 + ip = IPAddr.new(options[:adapter_ip]) + + # Configure + if ip.ipv4? + execute("hostonlyif", "ipconfig", name, + "--ip", options[:adapter_ip], + "--netmask", options[:netmask]) + elsif ip.ipv6? + execute("hostonlyif", "ipconfig", name, + "--ipv6", options[:adapter_ip], + "--netmasklengthv6", options[:netmask].to_s) + end # Return the details return { @@ -325,6 +334,10 @@ module VagrantPlugins info[:ip] = ip elsif netmask = line[/^NetworkMask:\s+(.+?)$/, 1] info[:netmask] = netmask + elsif line =~ /^IPV6Address:\s+(.+?)$/ + info[:ipv6] = $1.to_s.strip + elsif line =~ /^IPV6NetworkMaskPrefixLength:\s+(.+?)$/ + info[:ipv6_prefix] = $1.to_s.strip elsif status = line[/^Status:\s+(.+?)$/, 1] info[:status] = status end @@ -434,6 +447,11 @@ module VagrantPlugins results end + def reconfig_host_only(interface) + execute("hostonlyif", "ipconfig", interface[:name], + "--ipv6", interface[:ipv6]) + end + def remove_dhcp_server(network_name) execute("dhcpserver", "remove", "--netname", network_name) end diff --git a/plugins/providers/virtualbox/driver/version_4_2.rb b/plugins/providers/virtualbox/driver/version_4_2.rb index dc7da430a..0f1f79698 100644 --- a/plugins/providers/virtualbox/driver/version_4_2.rb +++ b/plugins/providers/virtualbox/driver/version_4_2.rb @@ -46,12 +46,21 @@ module VagrantPlugins def create_host_only_network(options) # Create the interface execute("hostonlyif", "create") =~ /^Interface '(.+?)' was successfully created$/ - name = $1.to_s + name = $1.to_s - # Configure it - execute("hostonlyif", "ipconfig", name, - "--ip", options[:adapter_ip], - "--netmask", options[:netmask]) + # Get the IP so we can determine v4 vs v6 + ip = IPAddr.new(options[:adapter_ip]) + + # Configure + if ip.ipv4? + execute("hostonlyif", "ipconfig", name, + "--ip", options[:adapter_ip], + "--netmask", options[:netmask]) + elsif ip.ipv6? + execute("hostonlyif", "ipconfig", name, + "--ipv6", options[:adapter_ip], + "--netmasklengthv6", options[:netmask].to_s) + end # Return the details return { @@ -356,6 +365,10 @@ module VagrantPlugins info[:ip] = $1.to_s elsif line =~ /^NetworkMask:\s+(.+?)$/ info[:netmask] = $1.to_s + elsif line =~ /^IPV6Address:\s+(.+?)$/ + info[:ipv6] = $1.to_s.strip + elsif line =~ /^IPV6NetworkMaskPrefixLength:\s+(.+?)$/ + info[:ipv6_prefix] = $1.to_s.strip elsif line =~ /^Status:\s+(.+?)$/ info[:status] = $1.to_s end @@ -465,6 +478,11 @@ module VagrantPlugins results end + def reconfig_host_only(interface) + execute("hostonlyif", "ipconfig", interface[:name], + "--ipv6", interface[:ipv6]) + end + def remove_dhcp_server(network_name) execute("dhcpserver", "remove", "--netname", network_name) end