Merge branch 'nfs-per-user' of https://github.com/davedevelopment/vagrant into davedevelopment-nfs-per-user

Conflicts:
	plugins/hosts/arch/host.rb
	plugins/hosts/bsd/host.rb
	plugins/hosts/linux/host.rb
	templates/nfs/exports.erb
	templates/nfs/exports_freebsd.erb
	templates/nfs/exports_linux.erb
This commit is contained in:
Mitchell Hashimoto 2013-09-01 11:44:00 -07:00
commit 65ef8d2477
6 changed files with 23 additions and 15 deletions

View File

@ -26,8 +26,9 @@ module VagrantPlugins
def nfs_export(id, ips, folders) def nfs_export(id, ips, folders)
output = TemplateRenderer.render('nfs/exports_linux', output = TemplateRenderer.render('nfs/exports_linux',
:uuid => id, :uuid => id,
:ips => ips, :ip => ips,
:folders => folders) :folders => folders,
:user => Process.uid)
@ui.info I18n.t("vagrant.hosts.arch.nfs_export.prepare") @ui.info I18n.t("vagrant.hosts.arch.nfs_export.prepare")
sleep 0.5 sleep 0.5

View File

@ -84,7 +84,8 @@ module VagrantPlugins
output = TemplateRenderer.render(@nfs_exports_template, output = TemplateRenderer.render(@nfs_exports_template,
:uuid => id, :uuid => id,
:ips => ips, :ips => ips,
:folders => dirmap) :folders => dirmap,
:user => Process.uid)
# The sleep ensures that the output is truly flushed before any `sudo` # The sleep ensures that the output is truly flushed before any `sudo`
# commands are issued. # commands are issued.
@ -112,9 +113,10 @@ module VagrantPlugins
@logger.info("Pruning invalid NFS entries...") @logger.info("Pruning invalid NFS entries...")
output = false output = false
user = Process.uid
File.read("/etc/exports").lines.each do |line| File.read("/etc/exports").lines.each do |line|
if id = line[/^# VAGRANT-BEGIN: (.+?)$/, 1] if id = line[/^# VAGRANT-BEGIN:( #{user})? ([A-Za-z0-9-]+?)$/, 2]
if valid_ids.include?(id) if valid_ids.include?(id)
@logger.debug("Valid ID: #{id}") @logger.debug("Valid ID: #{id}")
else else
@ -142,9 +144,11 @@ module VagrantPlugins
id = id.gsub("/", "\\/") id = id.gsub("/", "\\/")
id = id.gsub(".", "\\.") id = id.gsub(".", "\\.")
user = Process.uid
# Use sed to just strip out the block of code which was inserted # Use sed to just strip out the block of code which was inserted
# by Vagrant, and restart NFS. # by Vagrant, and restart NFS.
system("sudo sed -e '/^# VAGRANT-BEGIN: #{id}/,/^# VAGRANT-END: #{id}/ d' -ibak /etc/exports") system("sudo sed -e '/^# VAGRANT-BEGIN:\\( #{user}\\)\\? #{id}/,/^# VAGRANT-END:\\( #{user}\\)\\? #{id}/ d' -ibak /etc/exports")
end end
end end
end end

View File

@ -37,8 +37,9 @@ module VagrantPlugins
def nfs_export(id, ips, folders) def nfs_export(id, ips, folders)
output = TemplateRenderer.render('nfs/exports_linux', output = TemplateRenderer.render('nfs/exports_linux',
:uuid => id, :uuid => id,
:ips => ips, :ip => ip,
:folders => folders) :folders => folders,
:user => Process.uid)
@ui.info I18n.t("vagrant.hosts.linux.nfs_export") @ui.info I18n.t("vagrant.hosts.linux.nfs_export")
sleep 0.5 sleep 0.5
@ -62,9 +63,10 @@ module VagrantPlugins
@logger.info("Pruning invalid NFS entries...") @logger.info("Pruning invalid NFS entries...")
output = false output = false
user = Process.uid
File.read("/etc/exports").lines.each do |line| File.read("/etc/exports").lines.each do |line|
if id = line[/^# VAGRANT-BEGIN: (.+?)$/, 1] if id = line[/^# VAGRANT-BEGIN:( #{user})? ([A-Za-z0-9-]+?)$/, 2]
if valid_ids.include?(id) if valid_ids.include?(id)
@logger.debug("Valid ID: #{id}") @logger.debug("Valid ID: #{id}")
else else
@ -86,9 +88,10 @@ module VagrantPlugins
def nfs_cleanup(id) def nfs_cleanup(id)
return if !File.exist?("/etc/exports") return if !File.exist?("/etc/exports")
user = Process.uid
# Use sed to just strip out the block of code which was inserted # Use sed to just strip out the block of code which was inserted
# by Vagrant # by Vagrant
system("sudo sed -e '/^# VAGRANT-BEGIN: #{id}/,/^# VAGRANT-END: #{id}/ d' -ibak /etc/exports") system("sudo sed -e '/^# VAGRANT-BEGIN:\\( #{user}\\)\\? #{id}/,/^# VAGRANT-END:\\( #{user}\\)\\? #{id}/ d' -ibak /etc/exports")
end end
end end
end end

View File

@ -1,5 +1,5 @@
# VAGRANT-BEGIN: <%= uuid %> # VAGRANT-BEGIN: <%= user %> <%= uuid %>
<% folders.each do |dirs, opts| %> <% folders.each do |dirs, opts| %>
<%= dirs.map { |d| "\"#{d}\"" }.join(" ") %> <%= ips.join(" ") %><% 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 %> <% end %>
# VAGRANT-END: <%= uuid %> # VAGRANT-END: <%= user %> <%= uuid %>

View File

@ -1,5 +1,5 @@
# VAGRANT-BEGIN: <%= uuid %> # VAGRANT-BEGIN: <%= user %> <%= uuid %>
<% folders.each do |dirs, opts| %> <% folders.each do |dirs, opts| %>
<%= dirs.map { |d| "\"#{d}\"" }.join(" ") %> <%= ips.join(" ") %><% 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 %> <% end %>
# VAGRANT-END: <%= uuid %> # VAGRANT-END: <%= user %> <%= uuid %>

View File

@ -1,7 +1,7 @@
# VAGRANT-BEGIN: <%= uuid %> # VAGRANT-BEGIN: <%= user %> <%= uuid %>
<% ips.each do |ip| %> <% ips.each do |ip| %>
<% folders.each do |name, opts| %> <% 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] %>) "<%= 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 %>
<% end %> <% end %>
# VAGRANT-END: <%= uuid %> # VAGRANT-END: <%= user %> <%= uuid %>