From 21954c29afbda321fdc049a4562abfc03e9ada28 Mon Sep 17 00:00:00 2001 From: Jeff Bonhag Date: Wed, 1 Jul 2020 12:12:39 -0400 Subject: [PATCH] Hook into ValidateDiskExt capability --- plugins/providers/virtualbox/cap/configure_disks.rb | 2 +- .../virtualbox/model/storage_controller_array.rb | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/plugins/providers/virtualbox/cap/configure_disks.rb b/plugins/providers/virtualbox/cap/configure_disks.rb index aac4a3824..b3a739dbf 100644 --- a/plugins/providers/virtualbox/cap/configure_disks.rb +++ b/plugins/providers/virtualbox/cap/configure_disks.rb @@ -294,7 +294,7 @@ module VagrantPlugins dsk_info[:port] = port.to_s # Check for a free device - if port_attachments.detect { |a| a[:device] == "0" } + if port_attachments.any? { |a| a[:device] == "0" } dsk_info[:device] = "1" else dsk_info[:device] = "0" diff --git a/plugins/providers/virtualbox/model/storage_controller_array.rb b/plugins/providers/virtualbox/model/storage_controller_array.rb index 63a8eabd1..0e50aa277 100644 --- a/plugins/providers/virtualbox/model/storage_controller_array.rb +++ b/plugins/providers/virtualbox/model/storage_controller_array.rb @@ -1,12 +1,11 @@ +require_relative "../cap/validate_disk_ext" + module VagrantPlugins module ProviderVirtualBox module Model # A collection of storage controllers. Includes finder methods to look # up a storage controller by given attributes. class StorageControllerArray < Array - # TODO: hook into ValidateDiskExt capability - DEFAULT_DISK_EXT = [".vdi", ".vmdk", ".vhd"].map(&:freeze).freeze - # Returns a storage controller with the given name. Raises an # exception if a matching controller can't be found. # @@ -86,8 +85,12 @@ module VagrantPlugins # @param [Hash] attachment - Attachment information # @return [Boolean] def hdd?(attachment) - ext = File.extname(attachment[:location].to_s).downcase - DEFAULT_DISK_EXT.include?(ext) + if !attachment + false + else + ext = File.extname(attachment[:location].to_s).downcase.split('.').last + VagrantPlugins::ProviderVirtualBox::Cap::ValidateDiskExt.validate_disk_ext(nil, ext) + end end end end