Class: VagrantPlugins::GuestEsxi::Cap::MountNFSFolder

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

Class Method Summary collapse

Class Method Details

.mount_nfs_folder(machine, ip, folders) ⇒ Object



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

def self.mount_nfs_folder(machine, ip, folders)
  folders.each do |name, opts|
    guestpath = opts[:guestpath]
    volume = guestpath.gsub("/", "_")
    machine.communicate.tap do |comm|
      if comm.test("localcli storage nfs list | grep '^#{volume}'")
        comm.execute("localcli storage nfs remove -v #{volume}")
      end
      mount_command = "localcli storage nfs add -H #{ip} -s '#{opts[:hostpath]}' -v '#{volume}'"
      retryable(:on => Vagrant::Errors::LinuxNFSMountFailed, :tries => 5, :sleep => 2) do
        comm.execute(mount_command,
                     :error_class => Vagrant::Errors::LinuxNFSMountFailed)
      end

      # symlink vmfs volume to :guestpath
      if comm.test("test -L '#{guestpath}'")
        comm.execute("rm '#{guestpath}'")
      end
      if comm.test("test -d '#{guestpath}'")
        comm.execute("rmdir '#{guestpath}'")
      end
      dir = File.dirname(guestpath)
      if !comm.test("test -d '#{dir}'")
        comm.execute("mkdir -p '#{dir}'")
      end

      comm.execute("ln -s '/vmfs/volumes/#{volume}' '#{guestpath}'")
    end
  end
end