Major guests have been moved to plugins
This commit is contained in:
parent
d6d5475762
commit
7766eb6098
|
@ -1,9 +0,0 @@
|
||||||
module Vagrant
|
|
||||||
module Guest
|
|
||||||
class Linux < Vagrant::Guest::Base
|
|
||||||
class LinuxError < Errors::VagrantError
|
|
||||||
error_namespace("vagrant.guest.linux")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -50,6 +50,20 @@ module Vagrant
|
||||||
data[:config]
|
data[:config]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Defines an additionally available guest implementation with
|
||||||
|
# the given key.
|
||||||
|
#
|
||||||
|
# @param [String] name Name of the guest.
|
||||||
|
def self.guest(name=UNSET_VALUE, &block)
|
||||||
|
data[:guests] ||= Registry.new
|
||||||
|
|
||||||
|
# Register a new guest class only if a name was given
|
||||||
|
data[:guests].register(name.to_sym, &block) if name != UNSET_VALUE
|
||||||
|
|
||||||
|
# Return the registry
|
||||||
|
data[:guests]
|
||||||
|
end
|
||||||
|
|
||||||
# Registers the plugin. This makes the plugin actually work with
|
# Registers the plugin. This makes the plugin actually work with
|
||||||
# Vagrant. Prior to registering, the plugin is merely a skeleton.
|
# Vagrant. Prior to registering, the plugin is merely a skeleton.
|
||||||
def self.register!(plugin=nil)
|
def self.register!(plugin=nil)
|
||||||
|
|
|
@ -32,6 +32,13 @@ module Vagrant
|
||||||
end
|
end
|
||||||
alias :[] :get
|
alias :[] :get
|
||||||
|
|
||||||
|
# Checks if the given key is registered with the registry.
|
||||||
|
#
|
||||||
|
# @return [Boolean]
|
||||||
|
def has_key?(key)
|
||||||
|
@actions.has_key?(key)
|
||||||
|
end
|
||||||
|
|
||||||
# Iterate over the keyspace.
|
# Iterate over the keyspace.
|
||||||
def each(&block)
|
def each(&block)
|
||||||
@actions.each do |key, _|
|
@actions.each do |key, _|
|
||||||
|
|
|
@ -52,7 +52,15 @@ module Vagrant
|
||||||
raise Errors::VMGuestError, :_key => :invalid_class, :guest => guest.to_s if !(guest <= Guest::Base)
|
raise Errors::VMGuestError, :_key => :invalid_class, :guest => guest.to_s if !(guest <= Guest::Base)
|
||||||
@guest = guest.new(self)
|
@guest = guest.new(self)
|
||||||
elsif guest.is_a?(Symbol)
|
elsif guest.is_a?(Symbol)
|
||||||
guest_klass = Vagrant.guests.get(guest)
|
# Look for the guest as a registered plugin
|
||||||
|
guest_klass = nil
|
||||||
|
Vagrant.plugin("1").registered.each do |plugin|
|
||||||
|
if plugin.guest.has_key?(guest)
|
||||||
|
guest_klass = plugin.guest[guest]
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
raise Errors::VMGuestError, :_key => :unknown_type, :guest => guest.to_s if !guest_klass
|
raise Errors::VMGuestError, :_key => :unknown_type, :guest => guest.to_s if !guest_klass
|
||||||
@guest = guest_klass.new(self)
|
@guest = guest_klass.new(self)
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
require 'vagrant/util/template_renderer'
|
require 'vagrant/util/template_renderer'
|
||||||
|
|
||||||
module Vagrant
|
module VagrantPlugins
|
||||||
module Guest
|
module GuestFreeBSD
|
||||||
# A general Vagrant system implementation for "freebsd".
|
# A general Vagrant system implementation for "freebsd".
|
||||||
#
|
#
|
||||||
# Contributed by Kenneth Vestergaard <kvs@binarysolutions.dk>
|
# Contributed by Kenneth Vestergaard <kvs@binarysolutions.dk>
|
||||||
class FreeBSD < Base
|
class Guest < Vagrant::Guest::Base
|
||||||
# Here for whenever it may be used.
|
# Here for whenever it may be used.
|
||||||
class FreeBSDError < Errors::VagrantError
|
class FreeBSDError < Vagrant::Errors::VagrantError
|
||||||
error_namespace("vagrant.guest.freebsd")
|
error_namespace("vagrant.guest.freebsd")
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,11 +3,14 @@ require "vagrant"
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module GuestFreeBSD
|
module GuestFreeBSD
|
||||||
autoload :Config, File.expand_path("../config", __FILE__)
|
autoload :Config, File.expand_path("../config", __FILE__)
|
||||||
|
autoload :Guest, File.expand_path("../guest", __FILE__)
|
||||||
|
|
||||||
class Plugin < Vagrant.plugin("1")
|
class Plugin < Vagrant.plugin("1")
|
||||||
name "FreeBSD guest"
|
name "FreeBSD guest"
|
||||||
description "FreeBSD guest support."
|
description "FreeBSD guest support."
|
||||||
|
|
||||||
config("freebsd") { Config }
|
config("freebsd") { Config }
|
||||||
|
guest("freebsd") { Guest }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,9 +2,13 @@ require 'log4r'
|
||||||
|
|
||||||
require 'vagrant/guest/linux/error'
|
require 'vagrant/guest/linux/error'
|
||||||
|
|
||||||
module Vagrant
|
module VagrantPlugins
|
||||||
module Guest
|
module GuestLinux
|
||||||
class Linux < Base
|
class Guest < Vagrant::Guest::Base
|
||||||
|
class LinuxError < Vagrant::Errors::VagrantError
|
||||||
|
error_namespace("vagrant.guest.linux")
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
super
|
super
|
||||||
|
|
|
@ -3,11 +3,14 @@ require "vagrant"
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module GuestLinux
|
module GuestLinux
|
||||||
autoload :Config, File.expand_path("../config", __FILE__)
|
autoload :Config, File.expand_path("../config", __FILE__)
|
||||||
|
autoload :Guest, File.expand_path("../guest", __FILE__)
|
||||||
|
|
||||||
class Plugin < Vagrant.plugin("1")
|
class Plugin < Vagrant.plugin("1")
|
||||||
name "Linux guest."
|
name "Linux guest."
|
||||||
description "Linux guest support."
|
description "Linux guest support."
|
||||||
|
|
||||||
config("linux") { Config }
|
config("linux") { Config }
|
||||||
|
guest("linux") { Guest }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
module Vagrant
|
module VagrantPlugins
|
||||||
module Guest
|
module GuestSolaris
|
||||||
# A general Vagrant system implementation for "solaris".
|
# A general Vagrant system implementation for "solaris".
|
||||||
#
|
#
|
||||||
# Contributed by Blake Irvin <b.irvin@modcloth.com>
|
# Contributed by Blake Irvin <b.irvin@modcloth.com>
|
||||||
class Solaris < Base
|
class Guest < Vagrant::Guest::Base
|
||||||
# Here for whenever it may be used.
|
# Here for whenever it may be used.
|
||||||
class SolarisError < Errors::VagrantError
|
class SolarisError < Vagrant::Errors::VagrantError
|
||||||
error_namespace("vagrant.guest.solaris")
|
error_namespace("vagrant.guest.solaris")
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,11 +3,14 @@ require "vagrant"
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module GuestSolaris
|
module GuestSolaris
|
||||||
autoload :Config, File.expand_path("../config", __FILE__)
|
autoload :Config, File.expand_path("../config", __FILE__)
|
||||||
|
autoload :Guest, File.expand_path("../guest", __FILE__)
|
||||||
|
|
||||||
class Plugin < Vagrant.plugin("1")
|
class Plugin < Vagrant.plugin("1")
|
||||||
name "Solaris guest."
|
name "Solaris guest."
|
||||||
description "Solaris guest support."
|
description "Solaris guest support."
|
||||||
|
|
||||||
config("solaris") { Config }
|
config("solaris") { Config }
|
||||||
|
guest("solaris") { Guest }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,30 +23,60 @@ describe Vagrant::Plugin::V1 do
|
||||||
plugin.description.should == "bar"
|
plugin.description.should == "bar"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should register configuration classes" do
|
describe "configuration" do
|
||||||
plugin = Class.new(described_class) do
|
it "should register configuration classes" do
|
||||||
config("foo") { "bar" }
|
plugin = Class.new(described_class) do
|
||||||
|
config("foo") { "bar" }
|
||||||
|
end
|
||||||
|
|
||||||
|
plugin.config[:foo].should == "bar"
|
||||||
end
|
end
|
||||||
|
|
||||||
plugin.config[:foo].should == "bar"
|
it "should lazily register configuration classes" do
|
||||||
|
# Below would raise an error if the value of the config class was
|
||||||
|
# evaluated immediately. By asserting that this does not raise an
|
||||||
|
# error, we verify that the value is actually lazily loaded
|
||||||
|
plugin = nil
|
||||||
|
expect {
|
||||||
|
plugin = Class.new(described_class) do
|
||||||
|
config("foo") { raise StandardError, "FAIL!" }
|
||||||
|
end
|
||||||
|
}.to_not raise_error
|
||||||
|
|
||||||
|
# Now verify when we actually get the configuration key that
|
||||||
|
# a proper error is raised.
|
||||||
|
expect {
|
||||||
|
plugin.config[:foo]
|
||||||
|
}.to raise_error(StandardError)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should lazily register configuration classes" do
|
describe "guests" do
|
||||||
# Below would raise an error if the value of the config class was
|
it "should register guest classes" do
|
||||||
# evaluated immediately. By asserting that this does not raise an
|
|
||||||
# error, we verify that the value is actually lazily loaded
|
|
||||||
plugin = nil
|
|
||||||
expect {
|
|
||||||
plugin = Class.new(described_class) do
|
plugin = Class.new(described_class) do
|
||||||
config("foo") { raise StandardError, "FAIL!" }
|
guest("foo") { "bar" }
|
||||||
end
|
end
|
||||||
}.to_not raise_error
|
|
||||||
|
|
||||||
# Now verify when we actually get the configuration key that
|
plugin.guest[:foo].should == "bar"
|
||||||
# a proper error is raised.
|
end
|
||||||
expect {
|
|
||||||
plugin.config[:foo]
|
it "should lazily register configuration classes" do
|
||||||
}.to raise_error(StandardError)
|
# Below would raise an error if the value of the config class was
|
||||||
|
# evaluated immediately. By asserting that this does not raise an
|
||||||
|
# error, we verify that the value is actually lazily loaded
|
||||||
|
plugin = nil
|
||||||
|
expect {
|
||||||
|
plugin = Class.new(described_class) do
|
||||||
|
guest("foo") { raise StandardError, "FAIL!" }
|
||||||
|
end
|
||||||
|
}.to_not raise_error
|
||||||
|
|
||||||
|
# Now verify when we actually get the configuration key that
|
||||||
|
# a proper error is raised.
|
||||||
|
expect {
|
||||||
|
plugin.guest[:foo]
|
||||||
|
}.to raise_error(StandardError)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "plugin registration" do
|
describe "plugin registration" do
|
||||||
|
|
|
@ -47,6 +47,12 @@ describe Vagrant::Registry do
|
||||||
instance.get("foo").should == ["value"]
|
instance.get("foo").should == ["value"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should be able to check if a key exists" do
|
||||||
|
instance.register("foo", "bar")
|
||||||
|
instance.should have_key("foo")
|
||||||
|
instance.should_not have_key("bar")
|
||||||
|
end
|
||||||
|
|
||||||
it "should be enumerable" do
|
it "should be enumerable" do
|
||||||
instance.register("foo", "foovalue")
|
instance.register("foo", "foovalue")
|
||||||
instance.register("bar", "barvalue")
|
instance.register("bar", "barvalue")
|
||||||
|
|
Loading…
Reference in New Issue