[pve-devel] [PATCH v2 common 04/14] network: add unique_ips function
Fabian Ebner
f.ebner at proxmox.com
Mon May 10 14:18:16 CEST 2021
Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
New in v2.
src/PVE/Network.pm | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/src/PVE/Network.pm b/src/PVE/Network.pm
index 48268b1..bb574e0 100644
--- a/src/PVE/Network.pm
+++ b/src/PVE/Network.pm
@@ -665,4 +665,24 @@ sub canonical_ip {
return $ip_obj->canon();
}
+# List of unique, canonical IPs in the provided list.
+# Keeps the original order, filtering later duplicates.
+sub unique_ips {
+ my ($ips) = @_;
+
+ my $res = [];
+ my $seen = {};
+
+ for my $ip (@{$ips}) {
+ $ip = canonical_ip($ip);
+
+ next if $seen->{$ip};
+
+ $seen->{$ip} = 1;
+ push @{$res}, $ip;
+ }
+
+ return $res;
+}
+
1;
--
2.20.1
More information about the pve-devel
mailing list