implement nfs shared folders for ipv6
This commit is contained in:
parent
c6b42a04cd
commit
7ac5ab8f14
|
@ -1,3 +1,4 @@
|
|||
require "ipaddr"
|
||||
require_relative "../../../synced_folders/unix_mount_helpers"
|
||||
|
||||
module VagrantPlugins
|
||||
|
@ -30,7 +31,13 @@ module VagrantPlugins
|
|||
|
||||
machine.communicate.sudo("mkdir -p #{guest_path}")
|
||||
|
||||
command = "mount -o #{mount_opts} #{ip}:#{host_path} #{guest_path}"
|
||||
addr = IPAddr.new(ip)
|
||||
|
||||
if addr.ipv6?
|
||||
command = "mount -o #{mount_opts} [#{ip}]:#{host_path} #{guest_path}"
|
||||
else
|
||||
command = "mount -o #{mount_opts} #{ip}:#{host_path} #{guest_path}"
|
||||
end
|
||||
|
||||
# Run the command, raising a specific error.
|
||||
retryable(on: Vagrant::Errors::NFSMountFailed, tries: 3, sleep: 5) do
|
||||
|
|
|
@ -37,8 +37,8 @@ module VagrantPlugins
|
|||
#
|
||||
# The ! indicates that this method modifies its argument.
|
||||
def add_ips_to_env!(env)
|
||||
adapter, host_ip = find_host_only_adapter
|
||||
machine_ip = read_static_machine_ips
|
||||
adapter, host_ip, is_ipv6 = find_host_only_adapter
|
||||
machine_ip = read_static_machine_ips
|
||||
|
||||
if !machine_ip
|
||||
# No static IP, attempt to use the dynamic IP.
|
||||
|
@ -62,9 +62,17 @@ module VagrantPlugins
|
|||
|
||||
if host_ip && !machine_ip.empty?
|
||||
interface = @machine.provider.driver.read_host_only_interfaces.detect do |iface|
|
||||
iface[:ip] == host_ip
|
||||
if is_ipv6
|
||||
iface[:ipv6] == host_ip
|
||||
else
|
||||
iface[:ip] == host_ip
|
||||
end
|
||||
end
|
||||
if is_ipv6
|
||||
host_ipaddr = IPAddr.new("#{host_ip}/#{interface.fetch(:ipv6_prefix, "64")}")
|
||||
else
|
||||
host_ipaddr = IPAddr.new("#{host_ip}/#{interface.fetch(:netmask, "0.0.0.0")}")
|
||||
end
|
||||
host_ipaddr = IPAddr.new("#{host_ip}/#{interface.fetch(:netmask, "0.0.0.0")}")
|
||||
|
||||
case machine_ip
|
||||
when String
|
||||
|
@ -92,7 +100,11 @@ module VagrantPlugins
|
|||
if opts[:type] == :hostonly
|
||||
@machine.provider.driver.read_host_only_interfaces.each do |interface|
|
||||
if interface[:name] == opts[:hostonly]
|
||||
return adapter, interface[:ip]
|
||||
if interface[:ipv6]
|
||||
return adapter, interface[:ipv6], true
|
||||
else
|
||||
return adapter, interface[:ip], false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,6 +32,24 @@ describe "VagrantPlugins::GuestLinux::Cap::MountNFS" do
|
|||
)
|
||||
end
|
||||
|
||||
context "with ipv6" do
|
||||
let(:ip) { "fd63:acd4:5c42:0530::1" }
|
||||
|
||||
it "mounts the folder" do
|
||||
folders = {
|
||||
"/vagrant-nfs" => {
|
||||
type: :nfs,
|
||||
guestpath: "/guest",
|
||||
hostpath: "/host",
|
||||
}
|
||||
}
|
||||
cap.mount_nfs_folder(machine, ip, folders)
|
||||
|
||||
expect(comm.received_commands[0]).to match(/mkdir -p #{guestpath}/)
|
||||
expect(comm.received_commands[1]).to match(/\[fd63:acd4:5c42:0530::1\]:#{hostpath} #{guestpath}/)
|
||||
end
|
||||
end
|
||||
|
||||
it "mounts the folder" do
|
||||
folders = {
|
||||
"/vagrant-nfs" => {
|
||||
|
|
|
@ -53,6 +53,10 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSSettings do
|
|||
[{name: "vmnet2", ip: "1.2.3.4"}]
|
||||
}
|
||||
|
||||
let(:guest_ip) {
|
||||
"2.3.4.5"
|
||||
}
|
||||
|
||||
before do
|
||||
# We can't be on Windows, because NFS gets disabled on Windows
|
||||
allow(Vagrant::Util::Platform).to receive(:windows?).and_return(false)
|
||||
|
@ -65,13 +69,30 @@ describe VagrantPlugins::ProviderVirtualBox::Action::PrepareNFSSettings do
|
|||
2 => {type: :hostonly, hostonly: "vmnet2"},
|
||||
})
|
||||
allow(driver).to receive(:read_host_only_interfaces).and_return(host_only_interfaces)
|
||||
allow(driver).to receive(:read_guest_ip).with(1).and_return("2.3.4.5")
|
||||
allow(driver).to receive(:read_guest_ip).with(1).and_return(guest_ip)
|
||||
|
||||
# override sleep to 0 so test does not take seconds
|
||||
retry_options = subject.retry_options
|
||||
allow(subject).to receive(:retry_options).and_return(retry_options.merge(sleep: 0))
|
||||
end
|
||||
|
||||
context "with ipv6 addresses" do
|
||||
let(:host_only_interfaces) {
|
||||
[{name: "vmnet2", ipv6: "fd63:acd4:5c42:0530::1"}]
|
||||
}
|
||||
|
||||
let(:guest_ip) {
|
||||
"fd63:acd4:5c42:0530::2"
|
||||
}
|
||||
|
||||
it "sets nfs_host_ip and nfs_machine_ip properly" do
|
||||
subject.call(env)
|
||||
|
||||
expect(env[:nfs_host_ip]).to eq("fd63:acd4:5c42:0530::1")
|
||||
expect(env[:nfs_machine_ip]).to eq("fd63:acd4:5c42:0530::2")
|
||||
end
|
||||
end
|
||||
|
||||
context "with host interface netmask defined" do
|
||||
context "with machine IP included within host interface range" do
|
||||
let(:host_only_interfaces) {
|
||||
|
|
Loading…
Reference in New Issue