2016-06-18 00:56:04 +00:00
|
|
|
require "shellwords"
|
|
|
|
require "vagrant/util/retryable"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module GuestBSD
|
|
|
|
module Cap
|
|
|
|
class NFS
|
|
|
|
extend Vagrant::Util::Retryable
|
|
|
|
|
|
|
|
# Mount the given NFS folder.
|
|
|
|
def self.mount_nfs_folder(machine, ip, folders)
|
|
|
|
comm = machine.communicate
|
|
|
|
|
2016-10-24 17:06:59 +00:00
|
|
|
# Mount each folder separately so we can retry.
|
2016-06-18 00:56:04 +00:00
|
|
|
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 << "nfsv#{opts[:nfs_version]}" if opts[:nfs_version]
|
|
|
|
mount_opts << "mntudp" if opts[:nfs_udp]
|
|
|
|
if opts[:mount_options]
|
|
|
|
mount_opts = mount_opts + opts[:mount_options].dup
|
|
|
|
end
|
|
|
|
mount_opts = mount_opts.join(",")
|
|
|
|
|
|
|
|
# Make the directory on the guest.
|
2016-10-24 17:06:59 +00:00
|
|
|
machine.communicate.sudo("mkdir -p #{guest_path}")
|
2016-06-18 00:56:04 +00:00
|
|
|
|
|
|
|
# Perform the mount operation.
|
2016-10-24 17:06:59 +00:00
|
|
|
command = "/sbin/mount -t nfs -o '#{mount_opts}' #{ip}:#{host_path} #{guest_path}"
|
2016-06-18 00:56:04 +00:00
|
|
|
|
|
|
|
# Run the command, raising a specific error.
|
|
|
|
retryable(on: Vagrant::Errors::NFSMountFailed, tries: 3, sleep: 5) do
|
2016-10-24 17:06:59 +00:00
|
|
|
machine.communicate.sudo(command,
|
2016-06-18 00:56:04 +00:00
|
|
|
error_class: Vagrant::Errors::NFSMountFailed,
|
|
|
|
shell: "sh",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|