diff --git a/plugins/providers/virtualbox/cap/configure_disks.rb b/plugins/providers/virtualbox/cap/configure_disks.rb index 2edb557f8..b5792d19b 100644 --- a/plugins/providers/virtualbox/cap/configure_disks.rb +++ b/plugins/providers/virtualbox/cap/configure_disks.rb @@ -20,16 +20,22 @@ module VagrantPlugins disks_defined = defined_disks.select { |d| d.type == :disk } if disks_defined.any? controller = machine.provider.driver.get_controller('SATA') - if disks_defined.size > controller.maxportcount - raise Vagrant::Errors::VirtualBoxDisksDefinedExceedLimit + if disks_defined.size > controller.limit + raise Vagrant::Errors::VirtualBoxDisksDefinedExceedLimit, + limit: controller.limit, + storage_bus: 'SATA', + type: :disk end end dvds_defined = defined_disks.select { |d| d.type == :dvd } if dvds_defined.any? controller = machine.provider.driver.get_controller('IDE') - if disks_defined.size > controller.maxportcount * 2 - raise Vagrant::Errors::VirtualBoxDisksDefinedExceedLimit + if disks_defined.size > controller.limit + raise Vagrant::Errors::VirtualBoxDisksDefinedExceedLimit, + limit: controller.limit, + storage_bus: 'IDE', + type: :dvd end end @@ -236,8 +242,12 @@ module VagrantPlugins if dsk_info[:port].to_s.empty? # This likely only occurs if additional disks have been added outside of Vagrant configuration - LOGGER.warn("There are no more available ports to attach disks to for the controller '#{controller}'. Clear up some space on the controller '#{controller}' to attach new disks.") - raise Vagrant::Errors::VirtualBoxDisksDefinedExceedLimit + LOGGER.warn("There is no more available space to attach disks to for the controller '#{controller}'. Clear up some space on the controller '#{controller}' to attach new disks.") + disk_type = controller.storage_bus == 'SATA' ? :disk : :dvd + raise Vagrant::Errors::VirtualBoxDisksDefinedExceedLimit, + limit: controller.limit, + storage_bus: controller.storage_bus, + type: disk_type end dsk_info diff --git a/plugins/providers/virtualbox/model/storage_controller.rb b/plugins/providers/virtualbox/model/storage_controller.rb index 600f174eb..abd4b8c7d 100644 --- a/plugins/providers/virtualbox/model/storage_controller.rb +++ b/plugins/providers/virtualbox/model/storage_controller.rb @@ -24,14 +24,19 @@ module VagrantPlugins # @return [String] attr_reader :storage_bus - # The maximum number of avilable ports for the storage controller. For - # SATA controllers, this indicates the number of disks that can be - # attached. For IDE controllers, this indicates that n*2 disks can be - # attached (primary/secondary). + # The maximum number of avilable ports for the storage controller. # # @return [Integer] attr_reader :maxportcount + # The maximum number of individual disks that can be attached to the + # storage controller. For SATA controllers, this equals the maximum + # number of ports. For IDE controllers, this will be twice the max + # number of ports (primary/secondary). + # + # @return [Integer] + attr_reader :limit + # The list of disks/ISOs attached to each storage controller. # # @return [Array] @@ -50,6 +55,11 @@ module VagrantPlugins end @maxportcount = maxportcount.to_i + if @storage_bus == 'IDE' + @limit = @maxportcount * 2 + else + @limit = @maxportcount + end attachments ||= [] @attachments = attachments diff --git a/templates/locales/en.yml b/templates/locales/en.yml index a6a27b877..1218d9a56 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1688,10 +1688,11 @@ en: controller. Vagrant Disks requires that the primary disk be attached to the first port of the SATA controller in order to manage it. virtualbox_disks_defined_exceed_limit: |- - VirtualBox only allows up to 30 disks to be attached to a single guest using the SATA Controller, - including the primray disk. + VirtualBox only allows up to %{limit} disks to be attached to a single + guest using the %{storage_bus} controller, including the primary disk. - Please ensure only up to 30 disks are configured for your guest. + Please ensure only up to %{limit} disks of type '%{type}' are + configured for your guest. virtualbox_guest_property_not_found: |- Could not find a required VirtualBox guest property: %{guest_property} diff --git a/test/unit/plugins/providers/virtualbox/cap/configure_disks_test.rb b/test/unit/plugins/providers/virtualbox/cap/configure_disks_test.rb index 5ae19f423..334893541 100644 --- a/test/unit/plugins/providers/virtualbox/cap/configure_disks_test.rb +++ b/test/unit/plugins/providers/virtualbox/cap/configure_disks_test.rb @@ -25,8 +25,13 @@ describe VagrantPlugins::ProviderVirtualBox::Cap::ConfigureDisks do double(:state) end - let(:sata_controller) { double("controller", name: "SATA Controller", storage_bus: "SATA", maxportcount: 30) } - let(:ide_controller) { double("controller", name: "IDE Controller", storage_bus: "IDE", maxportcount: 2) } + let(:sata_controller) { double("controller", name: "SATA Controller", + storage_bus: "SATA", maxportcount: 30, + limit: 30) } + + let(:ide_controller) { double("controller", name: "IDE Controller", + storage_bus: "IDE", maxportcount: 2, + limit: 4) } let(:attachments) { [{port: "0", device: "0", uuid: "12345"}, {port: "1", device: "0", uuid: "67890"}]} diff --git a/test/unit/plugins/providers/virtualbox/models/storage_controller_test.rb b/test/unit/plugins/providers/virtualbox/models/storage_controller_test.rb index 015fb2c71..d25298449 100644 --- a/test/unit/plugins/providers/virtualbox/models/storage_controller_test.rb +++ b/test/unit/plugins/providers/virtualbox/models/storage_controller_test.rb @@ -13,18 +13,28 @@ describe VagrantPlugins::ProviderVirtualBox::Model::StorageController do describe "#initialize" do context "with SATA controller type" do let(:type) { "IntelAhci" } + let(:maxportcount) { 30 } - it "is recognizes a SATA controller" do + it "recognizes a SATA controller" do expect(subject.storage_bus).to eq('SATA') end + + it "calculates the maximum number of attachments" do + expect(subject.limit).to eq(30) + end end context "with IDE controller type" do let(:type) { "PIIX4" } + let(:maxportcount) { 2 } it "recognizes an IDE controller" do expect(subject.storage_bus).to eq('IDE') end + + it "calculates the maximum number of attachments" do + expect(subject.limit).to eq(4) + end end context "with some other type" do