Class: VagrantPlugins::SyncedFolderNFSGuest::SyncedFolder

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-nfs_guest/synced_folder.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ SyncedFolder

Returns a new instance of SyncedFolder.



7
8
9
10
11
# File 'lib/vagrant-nfs_guest/synced_folder.rb', line 7

def initialize(*args)
  super

  @logger = Log4r::Logger.new("vagrant::synced_folders::nfs_guest")
end

Instance Method Details

#enable(machine, folders, nfsopts) ⇒ Object

Raises:

  • (Vagrant::Errors::NFSNoHostonlyNetwork)


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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/vagrant-nfs_guest/synced_folder.rb', line 24

def enable(machine, folders, nfsopts)
  if !machine.provider.capability?(:nfs_settings)
    raise Errors::ProviderNFSSettingsCapMissing
  end

  # I've abstracted this out to a plugin provided capability per
  # provider as it's impossible to resume a VM because the
  # PrepareNFSSettings action NEVER is trigger on a resume because
  # the host is exporting so therefore it's assumed to always be there.
  # Easier to maintain and add new providers this way.
  host_ip, machine_ip = machine.provider.capability(:nfs_settings)
  machine_ip = [machine_ip] if !machine_ip.is_a?(Array)

  raise Vagrant::Errors::NFSNoHostonlyNetwork if !host_ip || !machine_ip

  if machine.config.nfs_guest.verify_installed
    if machine.guest.capability?(:nfs_server_installed)
      installed = machine.guest.capability(:nfs_server_installed)
      if !installed
        can_install = machine.guest.capability?(:nfs_server_install)
        raise Errors::NFSServerNotInstalledInGuest if !can_install
        machine.ui.info I18n.t("vagrant_nfs_guest.guests.linux.nfs_server_installing")
        machine.guest.capability(:nfs_server_install)
      end
    end
  end

  # Prepare the folder, this means setting up various options
  # and such on the folder itself.
  folders.each { |id, opts| prepare_folder(machine, opts) }

  # Only mount folders that have a guest path specified.
  mount_folders = {}
  folders.each do |id, opts|
    mount_folders[id] = opts.dup if opts[:guestpath]
  end

  machine.ui.info I18n.t("vagrant_nfs_guest.actions.vm.nfs.exporting")
  machine.guest.capability(:nfs_export, Array(host_ip), mount_folders)
end

#usable?(machine, raise_error = false) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (Vagrant::Errors::NFSNotSupported)


13
14
15
16
17
18
19
20
21
22
# File 'lib/vagrant-nfs_guest/synced_folder.rb', line 13

def usable?(machine, raise_error=false)
  # If the machine explicitly said NFS is not supported, then
  # it isn't supported.
  if !machine.config.nfs_guest.functional
    return false
  end
  return true if machine.env.host.capability(:nfs_installed)
  return false if !raise_error
  raise Vagrant::Errors::NFSNotSupported
end