Class: Vagrant::Hosts::BSD

Inherits:
Base
  • Object
show all
Includes:
Util, Util::Retryable
Defined in:
lib/vagrant/hosts/bsd.rb

Overview

Represents a BSD host, such as FreeBSD and Darwin (Mac OS X).

Instance Attribute Summary

Attributes inherited from Base

#env

Instance Method Summary collapse

Methods included from Util::Retryable

#retryable

Methods inherited from Base

detect, #initialize, load

Constructor Details

This class inherits a constructor from Vagrant::Hosts::Base

Instance Method Details

#nfs?Boolean

Returns:

  • (Boolean)


8
9
10
11
12
# File 'lib/vagrant/hosts/bsd.rb', line 8

def nfs?
  retryable(:tries => 10, :on => TypeError) do
    system("which nfsd > /dev/null 2>&1")
  end
end

#nfs_cleanupObject



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vagrant/hosts/bsd.rb', line 37

def nfs_cleanup
  return if !File.exist?("/etc/exports")

  retryable(:tries => 10, :on => TypeError) do
    system("cat /etc/exports | grep 'VAGRANT-BEGIN: #{env.vm.uuid}' > /dev/null 2>&1")

    if $?.to_i == 0
      # Use sed to just strip out the block of code which was inserted
      # by Vagrant
      system("sudo sed -e '/^# VAGRANT-BEGIN: #{env.vm.uuid}/,/^# VAGRANT-END: #{env.vm.uuid}/ d' -ibak /etc/exports")
    end
  end
end

#nfs_export(ip, folders) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vagrant/hosts/bsd.rb', line 14

def nfs_export(ip, folders)
  output = TemplateRenderer.render('nfs/exports',
                                   :uuid => env.vm.uuid,
                                   :ip => ip,
                                   :folders => folders)

  # The sleep ensures that the output is truly flushed before any `sudo`
  # commands are issued.
  env.ui.info I18n.t("vagrant.hosts.bsd.nfs_export.prepare")
  sleep 0.5

  output.split("\n").each do |line|
    # This should only ask for administrative permission once, even
    # though its executed in multiple subshells.
    line = line.gsub('"', '\"')
    system(%Q[sudo su root -c "echo '#{line}' >> /etc/exports"])
  end

  # We run restart here instead of "update" just in case nfsd
  # is not starting
  system("sudo nfsd restart")
end