Skip to content

Commit

Permalink
quattor/functions/network get_subnet_params: allow to return subnet
Browse files Browse the repository at this point in the history
- Third argument added (boolean): default unchanged (subnet not returned to be compatible with
  the interface schema)
  • Loading branch information
jouvin committed Dec 11, 2024
1 parent fe6c43b commit ecdcc35
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions quattor/functions/network.pan
Original file line number Diff line number Diff line change
Expand Up @@ -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");
};
Expand Down Expand Up @@ -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);
};
};
Expand Down

0 comments on commit ecdcc35

Please sign in to comment.