mirror of https://github.com/sipwise/ngcpcfg.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.5 KiB
60 lines
1.5 KiB
[%
|
|
# vi: ft=tt2
|
|
|
|
# Return an array of IPs for a given host. The order is iface1_sharedip_1,
|
|
# iface1_sharedip_n, iface1_ip, iface2_sharedip_1, ...
|
|
#
|
|
# @param argv.host The host to get all IPs for.
|
|
# @param argv.type The interface type or empty string for all types.
|
|
# @param argv.format Optional reformatting of IPv6 addresses.
|
|
# @param argv.status node status [ online, offline, inactive ]
|
|
# default value: ['online', 'inactive']
|
|
# @return out The array of IPs.
|
|
|
|
IF !hosts.${argv.host}.defined;
|
|
argv.host = 'self';
|
|
END;
|
|
|
|
IF !argv.type.length;
|
|
argv.type = '.*';
|
|
END;
|
|
|
|
IF !argv.status.size;
|
|
argv.status = ['online', 'inactive'];
|
|
END;
|
|
|
|
status = {
|
|
online = 0
|
|
offline = 0
|
|
inactive = 0
|
|
};
|
|
FOREACH val IN argv.status;
|
|
status.$val = 1;
|
|
END;
|
|
|
|
out = [];
|
|
IF status.item(hosts.${argv.host}.status);
|
|
FOREACH iface IN hosts.${argv.host}.interfaces;
|
|
FOREACH realiface IN hosts.${argv.host}.keys;
|
|
NEXT IF realiface != iface;
|
|
NEXT UNLESS hosts.${argv.host}.$realiface.type.grep('^' _ argv.type _ '$').size();
|
|
|
|
FOREACH ip IN hosts.${argv.host}.$realiface.v6ip;
|
|
IF argv.format == 'expand';
|
|
WHILE ip.match('::') && ip.match(':', 1).size < 8;
|
|
ip = ip.replace('::', '::0:');
|
|
END;
|
|
ip = ip.replace('::', ':');
|
|
ip = ip.replace('^:', '0:');
|
|
ip = ip.replace(':$', ':0');
|
|
END;
|
|
NEXT UNLESS ip;
|
|
out.push(ip);
|
|
END;
|
|
END;
|
|
END;
|
|
END;
|
|
out = out.sort;
|
|
|
|
-%]
|