Add disk class function for provider layers
This commit is contained in:
parent
98a2d0f723
commit
34673fe5f9
|
@ -49,19 +49,47 @@ module VagrantPlugins
|
||||||
# - Hopefully in general the top-scope disk options are enough for the general
|
# - Hopefully in general the top-scope disk options are enough for the general
|
||||||
# case that most people won't need provider specific options except for very specific cases
|
# case that most people won't need provider specific options except for very specific cases
|
||||||
#
|
#
|
||||||
# @return [Hash]
|
# @return [Object]
|
||||||
attr_accessor :options
|
attr_accessor :config
|
||||||
|
|
||||||
def initialize(type)
|
def initialize(type)
|
||||||
@logger = Log4r::Logger.new("vagrant::config::vm::trigger::config")
|
@logger = Log4r::Logger.new("vagrant::config::vm::trigger::config")
|
||||||
|
|
||||||
@name = UNSET_VALUE
|
@name = UNSET_VALUE
|
||||||
@type = UNSET_VALUE
|
@type = UNSET_VALUE
|
||||||
|
@provider_type = UNSET_VALUE
|
||||||
@size = UNSET_VALUE
|
@size = UNSET_VALUE
|
||||||
@options = UNSET_VALUE
|
@config = nil
|
||||||
|
@invalid = false
|
||||||
|
|
||||||
# Internal options
|
# Internal options
|
||||||
@id = SecureRandom.uuid
|
@id = SecureRandom.uuid
|
||||||
|
|
||||||
|
# find disk provider plugin
|
||||||
|
@config_class = nil
|
||||||
|
# @invalid = true if provider not found
|
||||||
|
if !@config_class
|
||||||
|
@logger.info(
|
||||||
|
"Disk config for '#{@provider_type}' not found. Ignoring config.")
|
||||||
|
@config_class = Vagrant::Config::V2::DummyConfig
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_config(**options, &block)
|
||||||
|
return if invalid?
|
||||||
|
|
||||||
|
current = @config_class.new
|
||||||
|
current.set_options(options) if options
|
||||||
|
block.call(current) if block
|
||||||
|
current = @config.merge(current) if @config
|
||||||
|
@config = current
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns true or false if disk provider is found
|
||||||
|
#
|
||||||
|
# @return [Bool]
|
||||||
|
def invalid?
|
||||||
|
@invalid
|
||||||
end
|
end
|
||||||
|
|
||||||
def finalize!
|
def finalize!
|
||||||
|
@ -71,7 +99,7 @@ module VagrantPlugins
|
||||||
@type = nil if @type == UNSET_VALUE
|
@type = nil if @type == UNSET_VALUE
|
||||||
@size = nil if @size == UNSET_VALUE
|
@size = nil if @size == UNSET_VALUE
|
||||||
|
|
||||||
@options = nil if @options == UNSET_VALUE
|
@config = nil if @options == UNSET_VALUE
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return [Array] array of strings of error messages from config option validation
|
# @return [Array] array of strings of error messages from config option validation
|
||||||
|
|
|
@ -392,7 +392,7 @@ module VagrantPlugins
|
||||||
@__defined_vms[name].config_procs << [options[:config_version], block] if block
|
@__defined_vms[name].config_procs << [options[:config_version], block] if block
|
||||||
end
|
end
|
||||||
|
|
||||||
def disk(type, &block)
|
def disk(type, **options, &block)
|
||||||
disk = VagrantConfigDisk.new(type)
|
disk = VagrantConfigDisk.new(type)
|
||||||
if block.is_a?(Hash)
|
if block.is_a?(Hash)
|
||||||
disk.set_options(block)
|
disk.set_options(block)
|
||||||
|
@ -400,7 +400,10 @@ module VagrantPlugins
|
||||||
block.call(disk, VagrantConfigDisk)
|
block.call(disk, VagrantConfigDisk)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
disk.add_config(options, block)
|
||||||
|
|
||||||
@__drives << disk
|
@__drives << disk
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue