2013-04-04 06:46:39 +00:00
|
|
|
require "vagrant/util/retryable"
|
|
|
|
|
2013-04-04 06:33:20 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module GuestLinux
|
|
|
|
module Cap
|
|
|
|
class MountNFS
|
2013-04-04 06:46:39 +00:00
|
|
|
extend Vagrant::Util::Retryable
|
|
|
|
|
|
|
|
def self.mount_nfs_folder(machine, ip, folders)
|
2013-04-04 06:33:20 +00:00
|
|
|
folders.each do |name, opts|
|
|
|
|
# Expand the guest path so we can handle things like "~/vagrant"
|
|
|
|
expanded_guest_path = machine.guest.capability(
|
|
|
|
:shell_expand_guest_path, opts[:guestpath])
|
|
|
|
|
|
|
|
# Do the actual creating and mounting
|
|
|
|
machine.communicate.sudo("mkdir -p #{expanded_guest_path}")
|
|
|
|
|
|
|
|
# Mount
|
2013-07-16 23:23:33 +00:00
|
|
|
hostpath = opts[:hostpath].dup
|
|
|
|
hostpath.gsub!("'", "'\\\\''")
|
2013-04-04 06:33:20 +00:00
|
|
|
|
2013-09-01 19:25:21 +00:00
|
|
|
# Figure out any options
|
2013-11-23 21:43:48 +00:00
|
|
|
mount_opts = ["vers=#{opts[:nfs_version]}"]
|
|
|
|
mount_opts << "udp" if opts[:nfs_udp]
|
2013-09-01 19:25:21 +00:00
|
|
|
if opts[:mount_options]
|
|
|
|
mount_opts = opts[:mount_options].dup
|
|
|
|
end
|
|
|
|
|
|
|
|
mount_command = "mount -o '#{mount_opts.join(",")}' #{ip}:'#{hostpath}' #{expanded_guest_path}"
|
2014-05-22 16:35:12 +00:00
|
|
|
retryable(on: Vagrant::Errors::LinuxNFSMountFailed, tries: 8, sleep: 3) do
|
2013-04-04 06:33:20 +00:00
|
|
|
machine.communicate.sudo(mount_command,
|
2014-05-22 16:35:12 +00:00
|
|
|
error_class: Vagrant::Errors::LinuxNFSMountFailed)
|
2013-04-04 06:33:20 +00:00
|
|
|
end
|
2013-12-22 11:46:24 +00:00
|
|
|
|
|
|
|
# Emit an upstart event if we can
|
2015-04-22 13:18:34 +00:00
|
|
|
if machine.communicate.test("test -x /sbin/initctl && test 'upstart' = $(basename $(sudo readlink /proc/1/exe))")
|
2013-12-22 11:46:24 +00:00
|
|
|
machine.communicate.sudo(
|
|
|
|
"/sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT=#{expanded_guest_path}")
|
|
|
|
end
|
2013-04-04 06:33:20 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|