Class: Vagrant::Hosts::Linux

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

Overview

Represents a Linux based host, such as Ubuntu.

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
13
# File 'lib/vagrant/hosts/linux.rb', line 8

def nfs?
  retryable(:tries => 10, :on => TypeError) do
    # Check procfs to see if NFSd is a supported filesystem
    system("cat /proc/filesystems | grep nfsd > /dev/null 2>&1")
  end
end

#nfs_cleanupObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/vagrant/hosts/linux.rb', line 35

def nfs_cleanup
  return if !File.exist?("/etc/exports")
  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

#nfs_export(ip, folders) ⇒ Object



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

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

  env.ui.info I18n.t("vagrant.hosts.linux.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.
    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 /etc/init.d/nfs-kernel-server restart")
end