diff --git a/lib/vagrant.rb b/lib/vagrant.rb index fe3b5eaf1..747214e85 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -90,6 +90,7 @@ module Vagrant c.register([:"1", :command]) { Plugin::V1::Command } c.register([:"1", :config]) { Plugin::V1::Config } c.register([:"1", :guest]) { Plugin::V1::Guest } + c.register([:"1", :host]) { Plugin::V1::Host } c.register([:"1", :provisioner]) { Plugin::V1::Provisioner } # Returns a `Vagrant::Registry` object that contains all the built-in diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index ff0d156a7..f73678023 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -176,7 +176,7 @@ module Vagrant # Returns the host object associated with this environment. # - # @return [Hosts::Base] + # @return [Class] def host return @host if defined?(@host) @@ -194,10 +194,9 @@ module Vagrant # Get the flattened list of available hosts host_klass = Hosts.detect(hosts) 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. - host_klass ||= Hosts::Base + host_klass ||= Vagrant.plugin("1", :host) @host ||= host_klass.new(@ui) end diff --git a/lib/vagrant/hosts.rb b/lib/vagrant/hosts.rb index 86d94827b..aa333d3d0 100644 --- a/lib/vagrant/hosts.rb +++ b/lib/vagrant/hosts.rb @@ -24,68 +24,5 @@ module Vagrant # No matches found... return nil 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] valid_ids Valid IDs that should not be - # pruned. - def nfs_prune(valid_ids) - end - end end end diff --git a/lib/vagrant/plugin/v1.rb b/lib/vagrant/plugin/v1.rb index 0c095c4c3..6c4c6d339 100644 --- a/lib/vagrant/plugin/v1.rb +++ b/lib/vagrant/plugin/v1.rb @@ -8,6 +8,7 @@ module Vagrant autoload :Command, "vagrant/plugin/v1/command" autoload :Config, "vagrant/plugin/v1/config" autoload :Guest, "vagrant/plugin/v1/guest" + autoload :Host, "vagrant/plugin/v1/host" autoload :Plugin, "vagrant/plugin/v1/plugin" autoload :Provisioner, "vagrant/plugin/v1/provisioner" end diff --git a/lib/vagrant/plugin/v1/host.rb b/lib/vagrant/plugin/v1/host.rb new file mode 100644 index 000000000..1017f1d41 --- /dev/null +++ b/lib/vagrant/plugin/v1/host.rb @@ -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] valid_ids Valid IDs that should not be + # pruned. + def nfs_prune(valid_ids) + end + end + end + end +end diff --git a/plugins/hosts/bsd/host.rb b/plugins/hosts/bsd/host.rb index aefd9defa..28c9a62f3 100644 --- a/plugins/hosts/bsd/host.rb +++ b/plugins/hosts/bsd/host.rb @@ -6,7 +6,7 @@ require 'vagrant/util/platform' module VagrantPlugins module HostBSD # 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::Retryable diff --git a/plugins/hosts/linux/host.rb b/plugins/hosts/linux/host.rb index 30cb025a0..b846d7a9b 100644 --- a/plugins/hosts/linux/host.rb +++ b/plugins/hosts/linux/host.rb @@ -6,7 +6,7 @@ require 'vagrant/util/platform' module VagrantPlugins module HostLinux # 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::Retryable diff --git a/plugins/hosts/windows/host.rb b/plugins/hosts/windows/host.rb index 1a5e05065..9f5ed6c44 100644 --- a/plugins/hosts/windows/host.rb +++ b/plugins/hosts/windows/host.rb @@ -3,7 +3,7 @@ require 'vagrant/util/platform' module VagrantPlugins module HostWindows - class Host < Vagrant::Hosts::Base + class Host < Vagrant.plugin("1", :host) def self.match? Vagrant::Util::Platform.windows? end diff --git a/test/unit/vagrant/hosts_test.rb b/test/unit/vagrant/hosts_test.rb index c046b37e3..6c7f460c6 100644 --- a/test/unit/vagrant/hosts_test.rb +++ b/test/unit/vagrant/hosts_test.rb @@ -2,13 +2,14 @@ require File.expand_path("../../base", __FILE__) describe Vagrant::Hosts do let(:registry) { Hash.new } + let(:base_class) { Vagrant::Plugin::V1::Host } 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 end - bar_klass = Class.new(Vagrant::Hosts::Base) do + bar_klass = Class.new(base_class) do def self.match?; true; end end @@ -19,11 +20,11 @@ describe Vagrant::Hosts do end 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 end - bar_klass = Class.new(Vagrant::Hosts::Base) do + bar_klass = Class.new(base_class) do def self.match?; true; end def self.precedence; 9; end end diff --git a/test/unit/vagrant/plugin/v1/host_test.rb b/test/unit/vagrant/plugin/v1/host_test.rb new file mode 100644 index 000000000..bfc0fee78 --- /dev/null +++ b/test/unit/vagrant/plugin/v1/host_test.rb @@ -0,0 +1,5 @@ +require File.expand_path("../../../../base", __FILE__) + +describe Vagrant::Plugin::V1::Host do + # No tests. +end diff --git a/test/unit/vagrant_test.rb b/test/unit/vagrant_test.rb index 33241eb32..4985761fa 100644 --- a/test/unit/vagrant_test.rb +++ b/test/unit/vagrant_test.rb @@ -15,6 +15,7 @@ describe Vagrant do described_class.plugin("1", :command).should == Vagrant::Plugin::V1::Command described_class.plugin("1", :config).should == Vagrant::Plugin::V1::Config 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 end end