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
|
@id = SecureRandom.uuid
|
||||||
end
|
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)
|
def add_provider_config(**options, &block)
|
||||||
current = {}
|
current = {}
|
||||||
options.each do |k,v|
|
options.each do |k,v|
|
||||||
opts = k.to_s.split("__")
|
opts = k.to_s.split("__")
|
||||||
|
|
||||||
if opts.size == 2
|
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
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
#block.call(current) if block
|
|
||||||
current = @provider_config.merge(current) if !@provider_config.empty?
|
current = @provider_config.merge(current) if !@provider_config.empty?
|
||||||
@provider_config = current
|
@provider_config = current
|
||||||
end
|
end
|
||||||
|
|
|
@ -409,23 +409,27 @@ 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
|
||||||
|
|
||||||
|
# Stores disk config options from Vagrantfile
|
||||||
|
#
|
||||||
|
# @param [Symbol] type
|
||||||
|
# @param [Hash] options
|
||||||
|
# @param [Block] block
|
||||||
def disk(type, **options, &block)
|
def disk(type, **options, &block)
|
||||||
disk_config = VagrantConfigDisk.new(type)
|
disk_config = VagrantConfigDisk.new(type)
|
||||||
|
|
||||||
# Remove provider__option options before set_options, otherwise will
|
# Remove provider__option options before set_options, otherwise will
|
||||||
# show up as missing setting
|
# show up as missing setting
|
||||||
#
|
# Extract provider hash options as well
|
||||||
# We can probably combine this into a single method call...?
|
provider_options = {}
|
||||||
provider_options = options.select { |k,v| k.to_s.include?("__") }
|
options.delete_if do |p,o|
|
||||||
options.delete_if { |k,v| k.to_s.include?("__") }
|
if o.is_a?(Hash) || p.to_s.include?("__")
|
||||||
|
provider_options[p] = o
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
disk_config.set_options(options)
|
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
|
# Add provider config
|
||||||
disk_config.add_provider_config(provider_options, &block)
|
disk_config.add_provider_config(provider_options, &block)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue