[%
# vi: ft=tt2

# Return an array of IPv6 addresses from the interface of a given type for
# all nodes which act as a given role.
#
# @param argv.role      The role of the node to process, one of:
#                         proxy, lb, mgmt
# @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.status    node status [ online, offline, inactive ]
#                         default value: ['online', 'inactive']
# @return out           The array of IPs.

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 = [];
FOREACH host IN hosts.keys.sort;
  NEXT UNLESS status.item(hosts.$host.status);
  NEXT UNLESS hosts.$host.role.grep('^' _ argv.role _ '$').size();

  FOREACH iface IN hosts.$host.interfaces;
    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);
    END;
  END;
END;
out = out.sort;

-%]
