Support both kinds of provider config options for disk config
This commit is contained in:
parent
83fea21ff1
commit
a51e9b1fa1
|
@ -66,18 +66,30 @@ module VagrantPlugins
|
|||
@id = SecureRandom.uuid
|
||||
end
|
||||
|
||||
# Helper method for storing provider specific config options
|
||||
#
|
||||
# Expected format is:
|
||||
#
|
||||
# - `provider__diskoption: value`
|
||||
# - `{provider: {diskoption: value, otherdiskoption: value, ...}`
|
||||
#
|
||||
# Duplicates will be overriden
|
||||
#
|
||||
# @param [Hash] options
|
||||
def add_provider_config(**options, &block)
|
||||
current = {}
|
||||
options.each do |k,v|
|
||||
opts = k.to_s.split("__")
|
||||
|
||||
if opts.size == 2
|
||||
current[opts[0]] = opts[1]
|
||||
current[opts[0].to_sym] = {opts[1].to_sym => v}
|
||||
elsif v.is_a?(Hash)
|
||||
current[k] = v
|
||||
else
|
||||
@logger.warn("Disk option '#{k}' found that does not match expected schema")
|
||||
@logger.warn("Disk option '#{k}' found that does not match expected provider disk config schema.")
|
||||
end
|
||||
end
|
||||
|
||||
#block.call(current) if block
|
||||
current = @provider_config.merge(current) if !@provider_config.empty?
|
||||
@provider_config = current
|
||||
end
|
||||
|
|
|
@ -409,23 +409,27 @@ module VagrantPlugins
|
|||
@__defined_vms[name].config_procs << [options[:config_version], block] if block
|
||||
end
|
||||
|
||||
# Stores disk config options from Vagrantfile
|
||||
#
|
||||
# @param [Symbol] type
|
||||
# @param [Hash] options
|
||||
# @param [Block] block
|
||||
def disk(type, **options, &block)
|
||||
disk_config = VagrantConfigDisk.new(type)
|
||||
|
||||
# Remove provider__option options before set_options, otherwise will
|
||||
# show up as missing setting
|
||||
#
|
||||
# We can probably combine this into a single method call...?
|
||||
provider_options = options.select { |k,v| k.to_s.include?("__") }
|
||||
options.delete_if { |k,v| k.to_s.include?("__") }
|
||||
# Extract provider hash options as well
|
||||
provider_options = {}
|
||||
options.delete_if do |p,o|
|
||||
if o.is_a?(Hash) || p.to_s.include?("__")
|
||||
provider_options[p] = o
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
disk_config.set_options(options)
|
||||
|
||||
# Can't use blocks if we use provider__option
|
||||
#if block_given?
|
||||
# block.call(disk, VagrantConfigDisk)
|
||||
#end
|
||||
|
||||
# Add provider config
|
||||
disk_config.add_provider_config(provider_options, &block)
|
||||
|
||||
|
|
Loading…
Reference in New Issue