NFS allows access from all networks on VM [GH-1204]

This commit is contained in:
Mitchell Hashimoto 2013-07-18 00:01:49 -04:00
parent 62c1bea7d3
commit 3028940adb
9 changed files with 22 additions and 11 deletions

View File

@ -15,6 +15,7 @@ BUG FIXES:
longer all just use the last value. [GH-1935]
- NFS export fsid's are now 32-bit integers, rather than UUIDs. This
lets NFS exports work with Linux kernels older than 2.6.20. [GH-1127]
- NFS export allows access from all private networks on the VM. [GH-1204]
## 1.2.4 (July 16, 2013)

View File

@ -65,13 +65,16 @@ module Vagrant
raise Errors::NFSNoHostIP if !env[:nfs_host_ip]
raise Errors::NFSNoGuestIP if !env[:nfs_machine_ip]
machine_ip = env[:nfs_machine_ip]
machine_ip = [machine_ip] if !machine_ip.is_a?(Array)
# Prepare the folder, this means setting up various options
# and such on the folder itself.
folders.each { |id, opts| prepare_folder(opts) }
# Export the folders
env[:ui].info I18n.t("vagrant.actions.vm.nfs.exporting")
env[:host].nfs_export(env[:machine].id, env[:nfs_machine_ip], folders)
env[:host].nfs_export(env[:machine].id, machine_ip, folders)
# Mount
env[:ui].info I18n.t("vagrant.actions.vm.nfs.mounting")

View File

@ -23,10 +23,10 @@ module VagrantPlugins
5
end
def nfs_export(id, ip, folders)
def nfs_export(id, ips, folders)
output = TemplateRenderer.render('nfs/exports_linux',
:uuid => id,
:ip => ip,
:ips => ips,
:folders => folders)
@ui.info I18n.t("vagrant.hosts.arch.nfs_export.prepare")

View File

@ -34,7 +34,7 @@ module VagrantPlugins
end
end
def nfs_export(id, ip, folders)
def nfs_export(id, ips, folders)
# We need to build up mapping of directories that are enclosed
# within each other because the exports file has to have subdirectories
# of an exported directory on the same line. e.g.:
@ -83,7 +83,7 @@ module VagrantPlugins
output = TemplateRenderer.render(@nfs_exports_template,
:uuid => id,
:ip => ip,
:ips => ips,
:folders => dirmap)
# The sleep ensures that the output is truly flushed before any `sudo`

View File

@ -34,10 +34,10 @@ module VagrantPlugins
end
end
def nfs_export(id, ip, folders)
def nfs_export(id, ips, folders)
output = TemplateRenderer.render('nfs/exports_linux',
:uuid => id,
:ip => ip,
:ips => ips,
:folders => folders)
@ui.info I18n.t("vagrant.hosts.linux.nfs_export")

View File

@ -50,13 +50,18 @@ module VagrantPlugins
#
# @return [String]
def read_machine_ip(machine)
ips = []
machine.config.vm.networks.each do |type, options|
if type == :private_network && options[:ip].is_a?(String)
return options[:ip]
ips << options[:ip]
end
end
nil
if ips.empty?
return nil
end
ips
end
end
end

View File

@ -1,5 +1,5 @@
# VAGRANT-BEGIN: <%= uuid %>
<% folders.each do |dirs, opts| %>
<%= dirs.map { |d| "\"#{d}\"" }.join(" ") %> <%= ip %><% if opts[:map_uid] -%> -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%>
<%= dirs.map { |d| "\"#{d}\"" }.join(" ") %> <%= ips.join(" ") %><% if opts[:map_uid] -%> -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%>
<% end %>
# VAGRANT-END: <%= uuid %>

View File

@ -1,5 +1,5 @@
# VAGRANT-BEGIN: <%= uuid %>
<% folders.each do |dirs, opts| %>
<%= dirs.map { |d| "\"#{d}\"" }.join(" ") %> <%= ip %><% if opts[:map_uid] -%> -alldirs -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%>
<%= dirs.map { |d| "\"#{d}\"" }.join(" ") %> <%= ips.join(" ") %><% if opts[:map_uid] -%> -alldirs -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%>
<% end %>
# VAGRANT-END: <%= uuid %>

View File

@ -1,5 +1,7 @@
# VAGRANT-BEGIN: <%= uuid %>
<% ips.each do |ip| %>
<% folders.each do |name, opts| %>
"<%= opts[:hostpath] %>" <%= ip %>(rw,no_subtree_check,all_squash<% if opts[:map_uid] %>,anonuid=<%= opts[:map_uid] %><% end %><% if opts[:map_gid] %>,anongid=<%= opts[:map_gid] %><% end %>,fsid=<%= opts[:uuid] %>)
<% end %>
<% end %>
# VAGRANT-END: <%= uuid %>