1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
require_relative "../../../synced_folders/unix_mount_helpers"
module VagrantPlugins
module GuestLinux
module Cap
class NFS
extend SyncedFolder::UnixMountHelpers
def self.nfs_client_installed(machine)
machine.communicate.test("test -x /sbin/mount.nfs")
end
def self.mount_nfs_folder(machine, ip, folders)
comm = machine.communicate
# Mount each folder separately so we can retry.
folders.each do |name, opts|
# Shellescape the paths in case they do not have special characters.
guest_path = Shellwords.escape(opts[:guestpath])
host_path = Shellwords.escape(opts[:hostpath])
# Build the list of mount options.
mount_opts = []
mount_opts << "vers=#{opts[:nfs_version]}" if opts[:nfs_version]
mount_opts << "udp" if opts[:nfs_udp]
if opts[:mount_options]
mount_opts = mount_opts + opts[:mount_options].dup
end
mount_opts = mount_opts.join(",")
machine.communicate.sudo("mkdir -p #{guest_path}")
command = "mount -o #{mount_opts} #{ip}:#{host_path} #{guest_path}"
# Run the command, raising a specific error.
retryable(on: Vagrant::Errors::NFSMountFailed, tries: 3, sleep: 5) do
machine.communicate.sudo(command,
error_class: Vagrant::Errors::NFSMountFailed,
)
end
emit_upstart_notification(machine, guest_path)
end
end
end
end
end
end
|