Skip to content

Commit 498af8c

Browse files
committed
The prefix should also be returned from the network_spec
1 parent fe38619 commit 498af8c

File tree

2 files changed

+6
-5
lines changed
  • src/bosh-director

2 files changed

+6
-5
lines changed

src/bosh-director/lib/bosh/director/models/vm.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def ips
2525
else
2626
cidr_ip
2727
end
28-
end
28+
end.sort_by { |ip| Bosh::Director::IpAddrOrCidr.new(ip).to_i }
2929
end
3030

3131
def ips_cidr
@@ -39,7 +39,7 @@ def manual_or_vip_ips
3939
end
4040

4141
def dynamic_ips
42-
network_spec.map { |_, network| network['ip'] }
42+
network_spec.map { |_, network| "#{network['ip']}/#{network['prefix']}" }
4343
end
4444
end
4545
end

src/bosh-director/spec/unit/bosh/director/models/vm_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,14 @@ module Models
4343
describe '#ips' do
4444
let!(:ip_address) { FactoryBot.create(:models_ip_address, vm: vm, address_str: to_ipaddr('1.1.1.1/32').to_s) }
4545
let!(:ip_address2) { FactoryBot.create(:models_ip_address, vm: vm, address_str: to_ipaddr('1.1.1.2/32').to_s) }
46+
let!(:ip_address3) { FactoryBot.create(:models_ip_address, vm: vm, address_str: to_ipaddr('1.1.1.16/28').to_s) }
4647

4748
before do
48-
vm.network_spec = { 'some' => { 'ip' => '1.1.1.3/32' } }
49+
vm.network_spec = { 'some' => { 'ip' => '2001:db8::1', 'prefix' => '64' }, 'some_other' => { 'ip' => '1.1.1.4', 'prefix' => '32' } }
4950
end
5051

51-
it 'returns all ips for the vm' do
52-
expect(vm.ips).to match_array(['1.1.1.1', '1.1.1.2', '1.1.1.3'])
52+
it 'returns ips without prefix for single ips and with prefix for prefix ips order by size of the integer representation' do
53+
expect(vm.ips).to match_array(['1.1.1.1', '1.1.1.2', '1.1.1.16/28', '1.1.1.4', '2001:db8::1/64'])
5354
end
5455
end
5556
end

0 commit comments

Comments
 (0)