Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move host base class to a plugin component

  • Loading branch information...
commit 70bdd9f56e46d509415dcbbc90ce790d1c3e720a 1 parent 214b298
@mitchellh authored
View
1  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
View
5 lib/vagrant/environment.rb
@@ -176,7 +176,7 @@ def cli(*args)
# Returns the host object associated with this environment.
#
- # @return [Hosts::Base]
+ # @return [Class]
def host
return @host if defined?(@host)
@@ -194,10 +194,9 @@ def host
# 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
View
63 lib/vagrant/hosts.rb
@@ -24,68 +24,5 @@ def self.detect(registry)
# 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<String>] valid_ids Valid IDs that should not be
- # pruned.
- def nfs_prune(valid_ids)
- end
- end
end
end
View
1  lib/vagrant/plugin/v1.rb
@@ -8,6 +8,7 @@ module V1
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
View
66 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<String>] valid_ids Valid IDs that should not be
+ # pruned.
+ def nfs_prune(valid_ids)
+ end
+ end
+ end
+ end
+end
View
2  plugins/hosts/bsd/host.rb
@@ -6,7 +6,7 @@
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
View
2  plugins/hosts/linux/host.rb
@@ -6,7 +6,7 @@
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
View
2  plugins/hosts/windows/host.rb
@@ -3,7 +3,7 @@
module VagrantPlugins
module HostWindows
- class Host < Vagrant::Hosts::Base
+ class Host < Vagrant.plugin("1", :host)
def self.match?
Vagrant::Util::Platform.windows?
end
View
9 test/unit/vagrant/hosts_test.rb
@@ -2,13 +2,14 @@
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 @@ def self.match?; true; end
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
View
5 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
View
1  test/unit/vagrant_test.rb
@@ -15,6 +15,7 @@
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
Please sign in to comment.
Something went wrong with that request. Please try again.