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]
|
||||
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
|
||||
# Vagrant. Prior to registering, the plugin is merely a skeleton.
|
||||
def self.register!(plugin=nil)
|
||||
|
|
|
@ -32,6 +32,13 @@ module Vagrant
|
|||
end
|
||||
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.
|
||||
def each(&block)
|
||||
@actions.each do |key, _|
|
||||
|
|
|
@ -52,7 +52,15 @@ module Vagrant
|
|||
raise Errors::VMGuestError, :_key => :invalid_class, :guest => guest.to_s if !(guest <= Guest::Base)
|
||||
@guest = guest.new(self)
|
||||
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
|
||||
@guest = guest_klass.new(self)
|
||||
else
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
require 'vagrant/util/template_renderer'
|
||||
|
||||
module Vagrant
|
||||
module Guest
|
||||
module VagrantPlugins
|
||||
module GuestFreeBSD
|
||||
# A general Vagrant system implementation for "freebsd".
|
||||
#
|
||||
# Contributed by Kenneth Vestergaard <kvs@binarysolutions.dk>
|
||||
class FreeBSD < Base
|
||||
class Guest < Vagrant::Guest::Base
|
||||
# Here for whenever it may be used.
|
||||
class FreeBSDError < Errors::VagrantError
|
||||
class FreeBSDError < Vagrant::Errors::VagrantError
|
||||
error_namespace("vagrant.guest.freebsd")
|
||||
end
|
||||
|
|
@ -3,11 +3,14 @@ require "vagrant"
|
|||
module VagrantPlugins
|
||||
module GuestFreeBSD
|
||||
autoload :Config, File.expand_path("../config", __FILE__)
|
||||
autoload :Guest, File.expand_path("../guest", __FILE__)
|
||||
|
||||
class Plugin < Vagrant.plugin("1")
|
||||
name "FreeBSD guest"
|
||||
description "FreeBSD guest support."
|
||||
|
||||
config("freebsd") { Config }
|
||||
guest("freebsd") { Guest }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,9 +2,13 @@ require 'log4r'
|
|||
|
||||
require 'vagrant/guest/linux/error'
|
||||
|
||||
module Vagrant
|
||||
module Guest
|
||||
class Linux < Base
|
||||
module VagrantPlugins
|
||||
module GuestLinux
|
||||
class Guest < Vagrant::Guest::Base
|
||||
class LinuxError < Vagrant::Errors::VagrantError
|
||||
error_namespace("vagrant.guest.linux")
|
||||
end
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
|
|
@ -3,11 +3,14 @@ require "vagrant"
|
|||
module VagrantPlugins
|
||||
module GuestLinux
|
||||
autoload :Config, File.expand_path("../config", __FILE__)
|
||||
autoload :Guest, File.expand_path("../guest", __FILE__)
|
||||
|
||||
class Plugin < Vagrant.plugin("1")
|
||||
name "Linux guest."
|
||||
description "Linux guest support."
|
||||
|
||||
config("linux") { Config }
|
||||
guest("linux") { Guest }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
module Vagrant
|
||||
module Guest
|
||||
module VagrantPlugins
|
||||
module GuestSolaris
|
||||
# A general Vagrant system implementation for "solaris".
|
||||
#
|
||||
# Contributed by Blake Irvin <b.irvin@modcloth.com>
|
||||
class Solaris < Base
|
||||
class Guest < Vagrant::Guest::Base
|
||||
# Here for whenever it may be used.
|
||||
class SolarisError < Errors::VagrantError
|
||||
class SolarisError < Vagrant::Errors::VagrantError
|
||||
error_namespace("vagrant.guest.solaris")
|
||||
end
|
||||
|
|
@ -3,11 +3,14 @@ require "vagrant"
|
|||
module VagrantPlugins
|
||||
module GuestSolaris
|
||||
autoload :Config, File.expand_path("../config", __FILE__)
|
||||
autoload :Guest, File.expand_path("../guest", __FILE__)
|
||||
|
||||
class Plugin < Vagrant.plugin("1")
|
||||
name "Solaris guest."
|
||||
description "Solaris guest support."
|
||||
|
||||
config("solaris") { Config }
|
||||
guest("solaris") { Guest }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,30 +23,60 @@ describe Vagrant::Plugin::V1 do
|
|||
plugin.description.should == "bar"
|
||||
end
|
||||
|
||||
it "should register configuration classes" do
|
||||
plugin = Class.new(described_class) do
|
||||
config("foo") { "bar" }
|
||||
describe "configuration" do
|
||||
it "should register configuration classes" do
|
||||
plugin = Class.new(described_class) do
|
||||
config("foo") { "bar" }
|
||||
end
|
||||
|
||||
plugin.config[:foo].should == "bar"
|
||||
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
|
||||
|
||||
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 {
|
||||
describe "guests" do
|
||||
it "should register guest classes" do
|
||||
plugin = Class.new(described_class) do
|
||||
config("foo") { raise StandardError, "FAIL!" }
|
||||
guest("foo") { "bar" }
|
||||
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)
|
||||
plugin.guest[:foo].should == "bar"
|
||||
end
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
describe "plugin registration" do
|
||||
|
|
|
@ -47,6 +47,12 @@ describe Vagrant::Registry do
|
|||
instance.get("foo").should == ["value"]
|
||||
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
|
||||
instance.register("foo", "foovalue")
|
||||
instance.register("bar", "barvalue")
|
||||
|
|
Loading…
Reference in New Issue