mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[vsphere|compute] Be more intelligent about auto-picking a unit number for a volume.
This commit is contained in:
parent
020436595a
commit
00042f6af2
1 changed files with 13 additions and 1 deletions
|
@ -49,7 +49,19 @@ module Fog
|
|||
requires :server_id, :size, :datastore
|
||||
|
||||
if unit_number.nil?
|
||||
self.unit_number = server.volumes.size
|
||||
used_unit_numbers = server.volumes.collect { |volume| volume.unit_number }
|
||||
max_unit_number = used_unit_numbers.max
|
||||
|
||||
if max_unit_number > server.volumes.size
|
||||
# If the max ID exceeds the number of volumes, there must be a hole in the range. Find a hole and use it.
|
||||
self.unit_number = max_unit_number.times.to_a.find { |i| used_unit_numbers.exclude?(i) }
|
||||
else
|
||||
self.unit_number = max_unit_number + 1
|
||||
end
|
||||
else
|
||||
if server.volumes.any? { |volume| volume.unit_number == self.unit_number && volume.id != self.id }
|
||||
raise "A volume already exists with that unit_number, so we can't save the new volume"
|
||||
end
|
||||
end
|
||||
|
||||
service.add_vm_volume(self)
|
||||
|
|
Loading…
Add table
Reference in a new issue