Distro dispatch for Host classes
This commit is contained in:
parent
5f62231bac
commit
1c2f80fab4
|
@ -8,7 +8,6 @@ module Vagrant
|
|||
# The {Environment} which this host belongs to.
|
||||
attr_reader :env
|
||||
|
||||
class << self
|
||||
# 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.
|
||||
|
@ -16,7 +15,7 @@ module Vagrant
|
|||
# @param [Environment] env
|
||||
# @param [String] klass
|
||||
# @return [Base]
|
||||
def load(env, klass)
|
||||
def self.load(env, klass)
|
||||
klass = detect if klass.nil? || klass == :detect
|
||||
return nil if !klass
|
||||
return klass.new(env)
|
||||
|
@ -26,23 +25,22 @@ module Vagrant
|
|||
# the class.
|
||||
#
|
||||
# @return [Class]
|
||||
def detect
|
||||
# More coming soon
|
||||
classes = {
|
||||
:darwin => BSD,
|
||||
:bsd => BSD,
|
||||
:arch => Arch,
|
||||
:linux => Linux
|
||||
}
|
||||
|
||||
classes.each do |type, klass|
|
||||
return klass if Util::Platform.send("#{type}?")
|
||||
def self.detect
|
||||
[BSD, Linux].each do |type|
|
||||
result = type.distro_dispatch
|
||||
return result if result
|
||||
end
|
||||
|
||||
nil
|
||||
rescue Exception
|
||||
nil
|
||||
end
|
||||
|
||||
# This must be implemented by subclasses to dispatch to the proper
|
||||
# distro-specific class for the host. If this returns nil then it is
|
||||
# an invalid host class.
|
||||
def self.distro_dispatch
|
||||
nil
|
||||
end
|
||||
|
||||
# Initialzes a new host. This method shouldn't be called directly,
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'vagrant/util/platform'
|
||||
|
||||
module Vagrant
|
||||
module Hosts
|
||||
# Represents a BSD host, such as FreeBSD and Darwin (Mac OS X).
|
||||
|
@ -5,6 +7,10 @@ module Vagrant
|
|||
include Util
|
||||
include Util::Retryable
|
||||
|
||||
def self.distro_dispatch
|
||||
return self if Util::Platform.darwin? || Util::Platform.bsd?
|
||||
end
|
||||
|
||||
def nfs?
|
||||
retryable(:tries => 10, :on => TypeError) do
|
||||
system("which nfsd > /dev/null 2>&1")
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'vagrant/util/platform'
|
||||
|
||||
module Vagrant
|
||||
module Hosts
|
||||
# Represents a Linux based host, such as Ubuntu.
|
||||
|
@ -5,6 +7,12 @@ module Vagrant
|
|||
include Util
|
||||
include Util::Retryable
|
||||
|
||||
def self.distro_dispatch
|
||||
return nil if !Util::Platform.linux?
|
||||
return Arch if File.exist?("/etc/rc.conf") && File.exist?("/etc/pacman.conf")
|
||||
return self
|
||||
end
|
||||
|
||||
def nfs?
|
||||
retryable(:tries => 10, :on => TypeError) do
|
||||
# Check procfs to see if NFSd is a supported filesystem
|
||||
|
|
|
@ -27,13 +27,6 @@ module Vagrant
|
|||
false
|
||||
end
|
||||
|
||||
def arch?
|
||||
linux? &&
|
||||
File.exist?('/etc/rc.conf') &&
|
||||
File.exist?('/etc/pacman.conf') &&
|
||||
File.exist?('/etc/rc.d/')
|
||||
end
|
||||
|
||||
# Returns boolean noting whether this is a 64-bit CPU. This
|
||||
# is not 100% accurate and there could easily be false negatives.
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue