Make VirtualBoxDisksDefinedExceedLimit error generic
Create a #limit method in the StorageController class so we can customize the error message when a storage controller is full.
This commit is contained in:
parent
1e6eb0d636
commit
53f7412821
@ -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
|
||||
|
||||
@ -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<Hash>]
|
||||
@ -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
|
||||
|
||||
@ -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}
|
||||
|
||||
@ -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"}]}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user