Sha256: de2cdf2e2c0dab8f08165bec154cc1220c5ecbe3ba426535919c01a311846b84

Contents?: true

Size: 1.54 KB

Versions: 48

Compression:

Stored size: 1.54 KB

Contents

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

          # 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 << "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.
            machine.communicate.sudo("mkdir -p #{guest_path}")

            # Perform the mount operation.
            command = "/sbin/mount -t nfs -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,
                shell: "sh",
              )
            end
          end
        end
      end
    end
  end
end

Version data entries

48 entries across 44 versions & 5 rubygems

Version Path
vagrant-unbundled-2.3.6.0 plugins/guests/bsd/cap/nfs.rb
tamtam-vagrant-reload-1.2.1 vendor/cache/vagrant-2092df529ae7/plugins/guests/bsd/cap/nfs.rb
vagrant-unbundled-2.3.3.0 plugins/guests/bsd/cap/nfs.rb
vagrant-unbundled-2.3.2.0 plugins/guests/bsd/cap/nfs.rb
vagrant-unbundled-2.2.19.0 plugins/guests/bsd/cap/nfs.rb
vagrant-unbundled-2.2.18.0 plugins/guests/bsd/cap/nfs.rb
vagrant-unbundled-2.2.16.0 plugins/guests/bsd/cap/nfs.rb
vagrant-unbundled-2.2.14.0 plugins/guests/bsd/cap/nfs.rb
vagrant-aws-mkubenka-0.7.2.pre.24 vendor/bundle/ruby/2.7.0/bundler/gems/vagrant-22795b161bf6/plugins/guests/bsd/cap/nfs.rb
vagrant-unbundled-2.2.10.0 plugins/guests/bsd/cap/nfs.rb
vagrant-unbundled-2.2.9.0 plugins/guests/bsd/cap/nfs.rb
vagrant-unbundled-2.2.8.0 plugins/guests/bsd/cap/nfs.rb
vagrant-unbundled-2.2.7.0 plugins/guests/bsd/cap/nfs.rb
vagrant-unbundled-2.2.6.2 plugins/guests/bsd/cap/nfs.rb
vagrant-unbundled-2.2.6.1 plugins/guests/bsd/cap/nfs.rb
vagrant-unbundled-2.2.6.0 plugins/guests/bsd/cap/nfs.rb
vagrant-unbundled-2.2.5.0 plugins/guests/bsd/cap/nfs.rb
vagrant-unbundled-2.2.4.0 plugins/guests/bsd/cap/nfs.rb
vagrant-unbundled-2.2.3.0 plugins/guests/bsd/cap/nfs.rb
vagrant-unbundled-2.2.2.0 plugins/guests/bsd/cap/nfs.rb