vagrant/plugins/guests/linux/cap/mount_nfs.rb

51 lines
1.6 KiB
Ruby
Raw Normal View History

require "vagrant/util/retryable"
2013-04-04 06:33:20 +00:00
module VagrantPlugins
module GuestLinux
module Cap
class MountNFS
extend Vagrant::Util::Retryable
def self.mount_nfs_folder(machine, ip, folders)
2016-06-05 19:03:12 +00:00
comm = machine.communicate
commands = []
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
2016-06-05 19:03:12 +00:00
commands << "mkdir -p '#{expanded_guest_path}'"
2013-04-04 06:33:20 +00:00
# Mount
hostpath = opts[:hostpath].dup
hostpath.gsub!("'", "'\\\\''")
2013-04-04 06:33:20 +00:00
# Figure out any options
mount_opts = ["vers=#{opts[:nfs_version]}"]
mount_opts << "udp" if opts[:nfs_udp]
if opts[:mount_options]
mount_opts = opts[:mount_options].dup
end
2016-06-05 19:03:12 +00:00
commands << "mount -o #{mount_opts.join(",")} '#{ip}:#{hostpath}' '#{expanded_guest_path}'"
# Emit a mount event
commands << <<-EOH.gsub(/^ {14}/, '')
if command -v /sbin/init &>/dev/null && /sbin/init --version | grep upstart &>/dev/null; then
/sbin/initctl emit --no-wait vagrant-mounted MOUNTPOINT='#{expanded_guest_path}'
fi
EOH
end
2016-06-05 19:03:12 +00:00
retryable(on: Vagrant::Errors::LinuxNFSMountFailed, tries: 8, sleep: 3) do
comm.sudo(commands.join("\n"), error_class: Vagrant::Errors::LinuxNFSMountFailed)
2013-04-04 06:33:20 +00:00
end
end
end
end
end
end