From ecdcc35ded9c263bb6b2e4618685051c14d2de2d Mon Sep 17 00:00:00 2001 From: Michel Jouvin Date: Sun, 8 Dec 2024 15:23:16 +0100 Subject: [PATCH] quattor/functions/network get_subnet_params: allow to return subnet - Third argument added (boolean): default unchanged (subnet not returned to be compatible with the interface schema) --- quattor/functions/network.pan | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/quattor/functions/network.pan b/quattor/functions/network.pan index dd36595a4..9d6eb8c23 100644 --- a/quattor/functions/network.pan +++ b/quattor/functions/network.pan @@ -173,15 +173,22 @@ function ip_in_network = { by structure_interface + 'subnet' which is the subnet number (result of applying the\ mask to the address. `subnet` key is mandatory, 'netmask` defaults to 255.255.255.0. arg = ip address to test + arg = boolean. When true, keep subnet parameter in return value. Default: false. } function get_subnet_params = { - if ( ARGC != 2 ) { - error("get_subnet_params requires 2 arguments"); + if ( ARGC < 2 || ARGC > 3 ) { + error("get_subnet_params requires 2 or 3 arguments"); }; subnet_list = ARGV[0]; ipaddr = ARGV[1]; + if ( ARGC == 3 ) { + keep_subnet = ARGV[2]; + } else { + keep_subnet = false; + }; + if ( !is_list(subnet_list) ) { error("get_subnet_params first argument must be a list"); }; @@ -217,7 +224,9 @@ function get_subnet_params = { }; if ( ip_in_network(ipaddr, params['subnet'], params['netmask']) ) { - delete(params["subnet"]); # Suppress subnet key + if (! keep_subnet) { + delete(params["subnet"]); # Suppress subnet key + }; return (params); }; };