Class: Vagrant::Solaris10::Cap::MountNFSFolder

Inherits:
Object
  • Object
show all
Extended by:
Util::Retryable
Defined in:
lib/vagrant-solaris10/cap/mount_nfs_folder.rb

Class Method Summary collapse

Class Method Details

.mount_nfs_folder(machine, ip, folders) ⇒ Object



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
49
# File 'lib/vagrant-solaris10/cap/mount_nfs_folder.rb', line 18

def self.mount_nfs_folder(machine, ip, folders)
  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])
  
    # clear prior symlink
    if machine.communicate.test("test -L \"#{expanded_guest_path}\"", sudo: true)
      machine.communicate.sudo("rm -f \"#{expanded_guest_path}\"")
    end
  
    # Create the folder if doesn't exist
    if !machine.communicate.test("test -d \"#{expanded_guest_path}\"", sudo: true)
      machine.communicate.sudo("mkdir -p #{expanded_guest_path}")
    end

    # Figure out any options
    mount_opts = ["vers=#{opts[:nfs_version]}"]
    if opts[:mount_options]
      mount_opts = opts[:mount_options].dup
    end
  
    mount_command = "mount -F nfs " +
      "-o '#{mount_opts.join(",")}' " +
      "'#{ip}:#{opts[:hostpath]}' '#{expanded_guest_path}'"
    retryable(on: Vagrant::Errors::SolarisNFSMountFailed, tries: 10, sleep: 5) do
      machine.communicate.sudo(
        mount_command,
        error_class: Vagrant::Errors::SolarisNFSMountFailed)
    end
  end
end