Skip to content

Commit ecdcc35

Browse files
committed
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)
1 parent fe6c43b commit ecdcc35

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

quattor/functions/network.pan

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,22 @@ function ip_in_network = {
173173
by structure_interface + 'subnet' which is the subnet number (result of applying the\
174174
mask to the address. `subnet` key is mandatory, 'netmask` defaults to 255.255.255.0.
175175
arg = ip address to test
176+
arg = boolean. When true, keep subnet parameter in return value. Default: false.
176177
}
177178
function get_subnet_params = {
178-
if ( ARGC != 2 ) {
179-
error("get_subnet_params requires 2 arguments");
179+
if ( ARGC < 2 || ARGC > 3 ) {
180+
error("get_subnet_params requires 2 or 3 arguments");
180181
};
181182

182183
subnet_list = ARGV[0];
183184
ipaddr = ARGV[1];
184185

186+
if ( ARGC == 3 ) {
187+
keep_subnet = ARGV[2];
188+
} else {
189+
keep_subnet = false;
190+
};
191+
185192
if ( !is_list(subnet_list) ) {
186193
error("get_subnet_params first argument must be a list");
187194
};
@@ -217,7 +224,9 @@ function get_subnet_params = {
217224
};
218225

219226
if ( ip_in_network(ipaddr, params['subnet'], params['netmask']) ) {
220-
delete(params["subnet"]); # Suppress subnet key
227+
if (! keep_subnet) {
228+
delete(params["subnet"]); # Suppress subnet key
229+
};
221230
return (params);
222231
};
223232
};

0 commit comments

Comments
 (0)