[pmg-devel] applied: [PATCH pmg-api] config: add ips/nets uniquely to the template variables

Wolfgang Bumiller w.bumiller at proxmox.com
Tue Jun 14 09:56:12 CEST 2022


could have probably gone with a single hash but it's clearer this way
given the function's length

applied

On Tue, May 31, 2022 at 01:52:53PM +0200, Dominik Csapak wrote:
> otherwise a config with many entries such as:
> domain1: ip1
> domain2: ip1
> domain3: ip1
> etc.
> 
> unnecessarily adds 'ip1' multiple times to the 'mynetworks' variable
> 
> to keep the output sorted (so it's stable) move the sort to the 'join'
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
>  src/PMG/Config.pm | 40 +++++++++++++++++++++-------------------
>  1 file changed, 21 insertions(+), 19 deletions(-)
> 
> diff --git a/src/PMG/Config.pm b/src/PMG/Config.pm
> index 31f9c6f..9ba5c76 100755
> --- a/src/PMG/Config.pm
> +++ b/src/PMG/Config.pm
> @@ -1297,63 +1297,65 @@ sub get_template_vars {
>      my $int_ip = PMG::Cluster::remote_node_ip($dnsinfo->{hostname});
>      $vars->{ipconfig}->{int_ip} = $int_ip;
>  
> -    my $transportnets = [];
> +    my $transportnets = {};
> +    my $mynetworks = {
> +	'127.0.0.0/8' => 1,
> +	'[::1]/128', => 1,
> +    };
>  
>      if (my $tmap = PVE::INotify::read_file('transport')) {
> -	foreach my $domain (sort keys %$tmap) {
> +	foreach my $domain (keys %$tmap) {
>  	    my $data = $tmap->{$domain};
>  	    my $host = $data->{host};
>  	    if ($host =~ m/^$IPV4RE$/) {
> -		push @$transportnets, "$host/32";
> +		$transportnets->{"$host/32"} = 1;
> +		$mynetworks->{"$host/32"} = 1;
(...)




More information about the pmg-devel mailing list