Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ def try_to_allocate_dynamic_ip(reservation, subnet)
addresses_we_cant_allocate.delete_if { |ipaddr| ipaddr.ipv6? }
end

addresses_we_cant_allocate.reject! do |ip|
addresses_we_cant_allocate.any? do |other_ip|
includes = other_ip.include?(ip)
includes && other_ip.prefix < ip.prefix
end
end

ip_address_cidr = find_next_available_ip(addresses_we_cant_allocate, first_range_address, subnet.prefix)

if !(subnet.range == ip_address_cidr || subnet.range.include?(ip_address_cidr))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def self.parse(network_name, subnet_spec, availability_zones, managed = false)

restricted_ips.reject! do |ip|
restricted_ips.any? do |other_ip|
includes = other_ip.include?(ip) rescue false
includes = other_ip.include?(ip)
includes && other_ip.prefix < ip.prefix
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,27 @@ def dynamic_reservation_with_ip(ip)
end
end

context 'when existing ips overlap with restricted ips' do
def save_ip(ip)
Bosh::Director::Models::IpAddress.new(
address_str: ip.to_s,
network_name: 'my-manual-network',
instance: instance_model,
task_id: Bosh::Director::Config.current_job.task_id
).save
end

it 'clears similar ips with smaller prefix' do
network_spec['subnets'].first['reserved'] = ['192.168.1.0 - 192.168.1.12']
network_spec['subnets'].first['range'] = '192.168.1.0/24'
save_ip(cidr_ip('192.168.1.8'))

ip_address = ip_repo.allocate_dynamic_ip(reservation, subnet)
expected_ip_address = cidr_ip('192.168.1.13')
expect(ip_address).to eq(expected_ip_address)
end
end

context 'when there are static and restricted ips' do
it 'does not reserve them' do
network_spec['subnets'].first['reserved'] = ['192.168.1.2']
Expand Down
Loading