MT#16239 Avoid duplicate IP records (shared_ip/shared_v6ip/advertised_ip)

Configuring the identical shared IP once again shouldn't cause
duplicate IP records, since e.g. nginx receives two "listen"
lines with the same IP and fails hard then.

New behaviour with this change is to avoid duplicates:

| root@spce:~# ngcp-network --verbose --set-interface=eth0 --shared-ip=1.2.3.4
| [...]
| adding IP entry shared_ip: 1.2.3.4
| [...]
| root@spce:~# ngcp-network --verbose --set-interface=eth0 --shared-ip=1.2.3.4
| [...]
| not setting shared_ip to 1.2.3.4 to avoid duplicates
| [...]

Change-Id: Iee3ff1e7a27bc3298128835468e1e888c327d13d
changes/45/5445/3
Michael Prokop 10 years ago
parent 3f1b490797
commit 4e3703660e

@ -267,11 +267,16 @@ sub set_interface {
delete $yaml->[0]->{hosts}->{$host}->{$iface}->{$k};
}
else {
logger("$k: $settings->{$k}");
if($k eq 'shared_ip' || $k eq 'shared_v6ip' || $k eq 'advertised_ip') {
push @{ $yaml->[0]->{hosts}->{$host}->{$iface}->{$k} }, $settings->{$k};
if (my ($matched) = grep { $_ eq $settings->{$k} } @{ $yaml->[0]->{hosts}->{$host}->{$iface}->{$k} }) {
logger("not setting $k to $matched to avoid duplicates");
} else {
logger("adding IP entry $k: $settings->{$k}");
push @{ $yaml->[0]->{hosts}->{$host}->{$iface}->{$k} }, $settings->{$k}
}
}
else {
logger("adding entry $k: $settings->{$k}");
$yaml->[0]->{hosts}->{$host}->{$iface}->{$k} = $settings->{$k};
}
}

Loading…
Cancel
Save