Class: Vagrant::Hosts::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/hosts/base.rb

Overview

Base class representing a host machine. These classes define methods which may have host-specific (Mac OS X, Windows, Linux, etc) behavior. The class is automatically determined by default but may be explicitly set via config.vagrant.host.

Direct Known Subclasses

BSD, Linux

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Base

Initialzes a new host. This method shouldn't be called directly, typically, since it will be called by Environment#load!.

Parameters:



51
52
53
# File 'lib/vagrant/hosts/base.rb', line 51

def initialize(env)
  @env = env
end

Instance Attribute Details

#envObject (readonly)

The Environment which this host belongs to.



9
10
11
# File 'lib/vagrant/hosts/base.rb', line 9

def env
  @env
end

Class Method Details

.detectClass

Detects the proper host class for current platform and returns the class.

Returns:

  • (Class)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vagrant/hosts/base.rb', line 29

def detect
  # More coming soon
  classes = {
    :darwin => BSD,
    :bsd => BSD,
    :linux => Linux
  }

  classes.each do |type, klass|
    return klass if Util::Platform.send("#{type}?")
  end

  nil
rescue Exception
  nil
end

.load(env, klass) ⇒ Base

Loads the proper host for the given value. If the value is nil or is the symbol :detect, then the host class will be detected using the RUBY_PLATFORM constant.

Parameters:

Returns:



19
20
21
22
23
# File 'lib/vagrant/hosts/base.rb', line 19

def load(env, klass)
  klass = detect if klass.nil? || klass == :detect
  return nil if !klass
  return klass.new(env)
end

Instance Method Details

#nfs?Boolean

Returns true of false denoting whether or not this host supports NFS shared folder setup. This method ideally should verify that NFS is installed.

Returns:

  • (Boolean)


60
61
62
# File 'lib/vagrant/hosts/base.rb', line 60

def nfs?
  false
end

#nfs_cleanupObject

Cleans up the exports for the current VM.



73
74
# File 'lib/vagrant/hosts/base.rb', line 73

def nfs_cleanup
end

#nfs_export(ip, folders) ⇒ Object

Exports the given hash of folders via NFS. This method will raise an Action::ActionException if anything goes wrong.

Parameters:

  • ip (String)

    IP of the guest machine.

  • folders (Hash)

    Shared folders to sync.



69
70
# File 'lib/vagrant/hosts/base.rb', line 69

def nfs_export(ip, folders)
end