Move host base class to a plugin component
This commit is contained in:
parent
214b29888a
commit
70bdd9f56e
|
@ -90,6 +90,7 @@ module Vagrant
|
||||||
c.register([:"1", :command]) { Plugin::V1::Command }
|
c.register([:"1", :command]) { Plugin::V1::Command }
|
||||||
c.register([:"1", :config]) { Plugin::V1::Config }
|
c.register([:"1", :config]) { Plugin::V1::Config }
|
||||||
c.register([:"1", :guest]) { Plugin::V1::Guest }
|
c.register([:"1", :guest]) { Plugin::V1::Guest }
|
||||||
|
c.register([:"1", :host]) { Plugin::V1::Host }
|
||||||
c.register([:"1", :provisioner]) { Plugin::V1::Provisioner }
|
c.register([:"1", :provisioner]) { Plugin::V1::Provisioner }
|
||||||
|
|
||||||
# Returns a `Vagrant::Registry` object that contains all the built-in
|
# Returns a `Vagrant::Registry` object that contains all the built-in
|
||||||
|
|
|
@ -176,7 +176,7 @@ module Vagrant
|
||||||
|
|
||||||
# Returns the host object associated with this environment.
|
# Returns the host object associated with this environment.
|
||||||
#
|
#
|
||||||
# @return [Hosts::Base]
|
# @return [Class]
|
||||||
def host
|
def host
|
||||||
return @host if defined?(@host)
|
return @host if defined?(@host)
|
||||||
|
|
||||||
|
@ -194,10 +194,9 @@ module Vagrant
|
||||||
# Get the flattened list of available hosts
|
# Get the flattened list of available hosts
|
||||||
host_klass = Hosts.detect(hosts)
|
host_klass = Hosts.detect(hosts)
|
||||||
end
|
end
|
||||||
host_klass = Vagrant.hosts.get(host_klass) if host_klass.is_a?(Symbol)
|
|
||||||
|
|
||||||
# If no host class is detected, we use the base class.
|
# If no host class is detected, we use the base class.
|
||||||
host_klass ||= Hosts::Base
|
host_klass ||= Vagrant.plugin("1", :host)
|
||||||
|
|
||||||
@host ||= host_klass.new(@ui)
|
@host ||= host_klass.new(@ui)
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,68 +24,5 @@ module Vagrant
|
||||||
# No matches found...
|
# No matches found...
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Interface for classes which house behavior that is specific
|
|
||||||
# to the host OS that is running Vagrant.
|
|
||||||
#
|
|
||||||
# By default, Vagrant will attempt to choose the best option
|
|
||||||
# for your machine, but the host may also be explicitly set
|
|
||||||
# via the `config.vagrant.host` parameter.
|
|
||||||
class Base
|
|
||||||
# This returns true/false depending on if the current running system
|
|
||||||
# matches the host class.
|
|
||||||
#
|
|
||||||
# @return [Boolean]
|
|
||||||
def self.match?
|
|
||||||
nil
|
|
||||||
end
|
|
||||||
|
|
||||||
# The precedence of the host when checking for matches. This is to
|
|
||||||
# allow certain host such as generic OS's ("Linux", "BSD", etc.)
|
|
||||||
# to be specified last.
|
|
||||||
#
|
|
||||||
# The hosts with the higher numbers will be checked first.
|
|
||||||
#
|
|
||||||
# If you're implementing a basic host, you can probably ignore this.
|
|
||||||
def self.precedence
|
|
||||||
5
|
|
||||||
end
|
|
||||||
|
|
||||||
# Initializes a new host class.
|
|
||||||
#
|
|
||||||
# The only required parameter is a UI object so that the host
|
|
||||||
# objects have some way to communicate with the outside world.
|
|
||||||
#
|
|
||||||
# @param [UI] ui UI for the hosts to output to.
|
|
||||||
def initialize(ui)
|
|
||||||
@ui = ui
|
|
||||||
end
|
|
||||||
|
|
||||||
# Returns true of false denoting whether or not this host supports
|
|
||||||
# NFS shared folder setup. This method ideally should verify that
|
|
||||||
# NFS is installed.
|
|
||||||
#
|
|
||||||
# @return [Boolean]
|
|
||||||
def nfs?
|
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
# Exports the given hash of folders via NFS.
|
|
||||||
#
|
|
||||||
# @param [String] id A unique ID that is guaranteed to be unique to
|
|
||||||
# match these sets of folders.
|
|
||||||
# @param [String] ip IP of the guest machine.
|
|
||||||
# @param [Hash] folders Shared folders to sync.
|
|
||||||
def nfs_export(id, ip, folders)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Prunes any NFS exports made by Vagrant which aren't in the set
|
|
||||||
# of valid ids given.
|
|
||||||
#
|
|
||||||
# @param [Array<String>] valid_ids Valid IDs that should not be
|
|
||||||
# pruned.
|
|
||||||
def nfs_prune(valid_ids)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,6 +8,7 @@ module Vagrant
|
||||||
autoload :Command, "vagrant/plugin/v1/command"
|
autoload :Command, "vagrant/plugin/v1/command"
|
||||||
autoload :Config, "vagrant/plugin/v1/config"
|
autoload :Config, "vagrant/plugin/v1/config"
|
||||||
autoload :Guest, "vagrant/plugin/v1/guest"
|
autoload :Guest, "vagrant/plugin/v1/guest"
|
||||||
|
autoload :Host, "vagrant/plugin/v1/host"
|
||||||
autoload :Plugin, "vagrant/plugin/v1/plugin"
|
autoload :Plugin, "vagrant/plugin/v1/plugin"
|
||||||
autoload :Provisioner, "vagrant/plugin/v1/provisioner"
|
autoload :Provisioner, "vagrant/plugin/v1/provisioner"
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
module Vagrant
|
||||||
|
module Plugin
|
||||||
|
module V1
|
||||||
|
# Base class for a host in Vagrant. A host class contains functionality
|
||||||
|
# that is specific to a specific OS that is running Vagrant. This
|
||||||
|
# abstraction is done becauase there is some host-specific logic that
|
||||||
|
# Vagrant must do in some cases.
|
||||||
|
class Host
|
||||||
|
# This returns true/false depending on if the current running system
|
||||||
|
# matches the host class.
|
||||||
|
#
|
||||||
|
# @return [Boolean]
|
||||||
|
def self.match?
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
# The precedence of the host when checking for matches. This is to
|
||||||
|
# allow certain host such as generic OS's ("Linux", "BSD", etc.)
|
||||||
|
# to be specified last.
|
||||||
|
#
|
||||||
|
# The hosts with the higher numbers will be checked first.
|
||||||
|
#
|
||||||
|
# If you're implementing a basic host, you can probably ignore this.
|
||||||
|
def self.precedence
|
||||||
|
5
|
||||||
|
end
|
||||||
|
|
||||||
|
# Initializes a new host class.
|
||||||
|
#
|
||||||
|
# The only required parameter is a UI object so that the host
|
||||||
|
# objects have some way to communicate with the outside world.
|
||||||
|
#
|
||||||
|
# @param [UI] ui UI for the hosts to output to.
|
||||||
|
def initialize(ui)
|
||||||
|
@ui = ui
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns true of false denoting whether or not this host supports
|
||||||
|
# NFS shared folder setup. This method ideally should verify that
|
||||||
|
# NFS is installed.
|
||||||
|
#
|
||||||
|
# @return [Boolean]
|
||||||
|
def nfs?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
# Exports the given hash of folders via NFS.
|
||||||
|
#
|
||||||
|
# @param [String] id A unique ID that is guaranteed to be unique to
|
||||||
|
# match these sets of folders.
|
||||||
|
# @param [String] ip IP of the guest machine.
|
||||||
|
# @param [Hash] folders Shared folders to sync.
|
||||||
|
def nfs_export(id, ip, folders)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Prunes any NFS exports made by Vagrant which aren't in the set
|
||||||
|
# of valid ids given.
|
||||||
|
#
|
||||||
|
# @param [Array<String>] valid_ids Valid IDs that should not be
|
||||||
|
# pruned.
|
||||||
|
def nfs_prune(valid_ids)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -6,7 +6,7 @@ require 'vagrant/util/platform'
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module HostBSD
|
module HostBSD
|
||||||
# Represents a BSD host, such as FreeBSD and Darwin (Mac OS X).
|
# Represents a BSD host, such as FreeBSD and Darwin (Mac OS X).
|
||||||
class Host < Vagrant::Hosts::Base
|
class Host < Vagrant.plugin("1", :host)
|
||||||
include Vagrant::Util
|
include Vagrant::Util
|
||||||
include Vagrant::Util::Retryable
|
include Vagrant::Util::Retryable
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ require 'vagrant/util/platform'
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module HostLinux
|
module HostLinux
|
||||||
# Represents a Linux based host, such as Ubuntu.
|
# Represents a Linux based host, such as Ubuntu.
|
||||||
class Host < Vagrant::Hosts::Base
|
class Host < Vagrant.plugin("1", :host)
|
||||||
include Vagrant::Util
|
include Vagrant::Util
|
||||||
include Vagrant::Util::Retryable
|
include Vagrant::Util::Retryable
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ require 'vagrant/util/platform'
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module HostWindows
|
module HostWindows
|
||||||
class Host < Vagrant::Hosts::Base
|
class Host < Vagrant.plugin("1", :host)
|
||||||
def self.match?
|
def self.match?
|
||||||
Vagrant::Util::Platform.windows?
|
Vagrant::Util::Platform.windows?
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,13 +2,14 @@ require File.expand_path("../../base", __FILE__)
|
||||||
|
|
||||||
describe Vagrant::Hosts do
|
describe Vagrant::Hosts do
|
||||||
let(:registry) { Hash.new }
|
let(:registry) { Hash.new }
|
||||||
|
let(:base_class) { Vagrant::Plugin::V1::Host }
|
||||||
|
|
||||||
it "detects the host that matches true" do
|
it "detects the host that matches true" do
|
||||||
foo_klass = Class.new(Vagrant::Hosts::Base) do
|
foo_klass = Class.new(base_class) do
|
||||||
def self.match?; false; end
|
def self.match?; false; end
|
||||||
end
|
end
|
||||||
|
|
||||||
bar_klass = Class.new(Vagrant::Hosts::Base) do
|
bar_klass = Class.new(base_class) do
|
||||||
def self.match?; true; end
|
def self.match?; true; end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,11 +20,11 @@ describe Vagrant::Hosts do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "detects the host that matches true with the highest precedence first" do
|
it "detects the host that matches true with the highest precedence first" do
|
||||||
foo_klass = Class.new(Vagrant::Hosts::Base) do
|
foo_klass = Class.new(base_class) do
|
||||||
def self.match?; true; end
|
def self.match?; true; end
|
||||||
end
|
end
|
||||||
|
|
||||||
bar_klass = Class.new(Vagrant::Hosts::Base) do
|
bar_klass = Class.new(base_class) do
|
||||||
def self.match?; true; end
|
def self.match?; true; end
|
||||||
def self.precedence; 9; end
|
def self.precedence; 9; end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
require File.expand_path("../../../../base", __FILE__)
|
||||||
|
|
||||||
|
describe Vagrant::Plugin::V1::Host do
|
||||||
|
# No tests.
|
||||||
|
end
|
|
@ -15,6 +15,7 @@ describe Vagrant do
|
||||||
described_class.plugin("1", :command).should == Vagrant::Plugin::V1::Command
|
described_class.plugin("1", :command).should == Vagrant::Plugin::V1::Command
|
||||||
described_class.plugin("1", :config).should == Vagrant::Plugin::V1::Config
|
described_class.plugin("1", :config).should == Vagrant::Plugin::V1::Config
|
||||||
described_class.plugin("1", :guest).should == Vagrant::Plugin::V1::Guest
|
described_class.plugin("1", :guest).should == Vagrant::Plugin::V1::Guest
|
||||||
|
described_class.plugin("1", :host).should == Vagrant::Plugin::V1::Host
|
||||||
described_class.plugin("1", :provisioner).should == Vagrant::Plugin::V1::Provisioner
|
described_class.plugin("1", :provisioner).should == Vagrant::Plugin::V1::Provisioner
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue