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