Add support for "upgrade safe" config classes to plugins.
These are classes that use NO core classes of Vagrant, and are therefore safe to load for upgrades. i.e. a V2 core can load a V1 config class that is deemed upgrade safe without crashing Vagrant.
This commit is contained in:
parent
68923ff556
commit
59d5c5ed92
|
@ -42,6 +42,25 @@ module Vagrant
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This returns all the registered configuration classes that were
|
||||||
|
# marked as "upgrade safe."
|
||||||
|
#
|
||||||
|
# @return [Hash]
|
||||||
|
def config_upgrade_safe
|
||||||
|
result = {}
|
||||||
|
|
||||||
|
@registered.each do |plugin|
|
||||||
|
configs = plugin.data[:config_upgrade_safe]
|
||||||
|
if configs
|
||||||
|
configs.each do |key|
|
||||||
|
result[key] = plugin.config.get(key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
# This returns all the registered guests.
|
# This returns all the registered guests.
|
||||||
#
|
#
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
|
|
|
@ -126,7 +126,16 @@ module Vagrant
|
||||||
data[:config] ||= Registry.new
|
data[:config] ||= Registry.new
|
||||||
|
|
||||||
# Register a new config class only if a name was given.
|
# Register a new config class only if a name was given.
|
||||||
data[:config].register(name.to_sym, &block) if name != UNSET_VALUE
|
if name != UNSET_VALUE
|
||||||
|
data[:config].register(name.to_sym, &block)
|
||||||
|
|
||||||
|
# If we were told this is an upgrade safe configuration class
|
||||||
|
# then we add it to the set.
|
||||||
|
if upgrade_safe
|
||||||
|
data[:config_upgrade_safe] ||= Set.new
|
||||||
|
data[:config_upgrade_safe].add(name.to_sym)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Return the registry
|
# Return the registry
|
||||||
data[:config]
|
data[:config]
|
||||||
|
@ -218,18 +227,19 @@ module Vagrant
|
||||||
data[:provisioners]
|
data[:provisioners]
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
# Returns the internal data associated with this plugin. This
|
||||||
|
# should NOT be called by the general public.
|
||||||
# Sentinel value denoting that a value has not been set.
|
|
||||||
UNSET_VALUE = Object.new
|
|
||||||
|
|
||||||
# Returns the internal data associated with this plugin.
|
|
||||||
#
|
#
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
def self.data
|
def self.data
|
||||||
@data ||= {}
|
@data ||= {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
protected
|
||||||
|
|
||||||
|
# Sentinel value denoting that a value has not been set.
|
||||||
|
UNSET_VALUE = Object.new
|
||||||
|
|
||||||
# Helper method that will set a value if a value is given, or otherwise
|
# Helper method that will set a value if a value is given, or otherwise
|
||||||
# return the already set value.
|
# return the already set value.
|
||||||
#
|
#
|
||||||
|
|
|
@ -45,6 +45,22 @@ describe Vagrant::Plugin::V1::Manager do
|
||||||
instance.config[:bar].should == "baz"
|
instance.config[:bar].should == "baz"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should enumerate registered upgrade safe config classes" do
|
||||||
|
pA = plugin do |p|
|
||||||
|
p.config("foo", true) { "bar" }
|
||||||
|
end
|
||||||
|
|
||||||
|
pB = plugin do |p|
|
||||||
|
p.config("bar") { "baz" }
|
||||||
|
end
|
||||||
|
|
||||||
|
instance.register(pA)
|
||||||
|
instance.register(pB)
|
||||||
|
|
||||||
|
instance.config_upgrade_safe.length.should == 1
|
||||||
|
instance.config_upgrade_safe[:foo].should == "bar"
|
||||||
|
end
|
||||||
|
|
||||||
it "should enumerate registered guest classes" do
|
it "should enumerate registered guest classes" do
|
||||||
pA = plugin do |p|
|
pA = plugin do |p|
|
||||||
p.guest("foo") { "bar" }
|
p.guest("foo") { "bar" }
|
||||||
|
|
Loading…
Reference in New Issue