TT#50701 lib/get_all_v6ips[_for_host]: support format parameter to expand IPv6 addr

Change-Id: Ic1bc5d019e6f1cfe1cdb66f6dcb4df3588ecd8b2
changes/85/26585/1
Andrew Pogrebennyk 7 years ago
parent 8337f626b4
commit 8cbc023ac1

@ -9,6 +9,7 @@
# @param argv.type The interface type of a node to extract the IP
# from, one of:
# web_int, web_ext, sip_int, sip_ext, ...
# @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.
@ -35,9 +36,19 @@ FOREACH host IN hosts.keys.sort;
FOREACH realiface IN hosts.$host.keys;
NEXT IF realiface != iface;
NEXT UNLESS hosts.$host.$realiface.type.grep('^' _ argv.type _ '$').size();
NEXT UNLESS hosts.$host.$realiface.v6ip;
out.push(hosts.$host.$realiface.v6ip);
FOREACH ip IN hosts.$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;

@ -6,6 +6,7 @@
#
# @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.
@ -37,9 +38,19 @@ IF status.item(hosts.${argv.host}.status);
FOREACH realiface IN hosts.${argv.host}.keys;
NEXT IF realiface != iface;
NEXT UNLESS hosts.${argv.host}.$realiface.type.grep('^' _ argv.type _ '$').size();
NEXT UNLESS hosts.${argv.host}.$realiface.v6ip.defined;
out.push(hosts.${argv.host}.$realiface.v6ip);
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;

Loading…
Cancel
Save