Add disk class function for provider layers

This commit is contained in:
Brian Cain 2019-10-18 09:39:31 -07:00
parent 98a2d0f723
commit 34673fe5f9
No known key found for this signature in database
GPG Key ID: 9FC4639B2E4510A0
2 changed files with 36 additions and 5 deletions

View File

@ -49,19 +49,47 @@ module VagrantPlugins
# - 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
#
# @return [Hash]
attr_accessor :options
# @return [Object]
attr_accessor :config
def initialize(type)
@logger = Log4r::Logger.new("vagrant::config::vm::trigger::config")
@name = UNSET_VALUE
@type = UNSET_VALUE
@provider_type = UNSET_VALUE
@size = UNSET_VALUE
@options = UNSET_VALUE
@config = nil
@invalid = false
# Internal options
@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
def finalize!
@ -71,7 +99,7 @@ module VagrantPlugins
@type = nil if @type == UNSET_VALUE
@size = nil if @size == UNSET_VALUE
@options = nil if @options == UNSET_VALUE
@config = nil if @options == UNSET_VALUE
end
# @return [Array] array of strings of error messages from config option validation

View File

@ -392,7 +392,7 @@ module VagrantPlugins
@__defined_vms[name].config_procs << [options[:config_version], block] if block
end
def disk(type, &block)
def disk(type, **options, &block)
disk = VagrantConfigDisk.new(type)
if block.is_a?(Hash)
disk.set_options(block)
@ -400,7 +400,10 @@ module VagrantPlugins
block.call(disk, VagrantConfigDisk)
end
disk.add_config(options, block)
@__drives << disk
end
#-------------------------------------------------------------------