[%
# vi: ft=tt2

# Return an array of Carrier nodes shared names with a given role
#
# @param argv.role      The role of the node to process, one of:
#                         proxy, lb, mgmt
# @param argv.status    node status [ online, offline, inactive ]
#                         default value: ['online', 'inactive']
# @return out           The array of shared names, e.g.:
#                         [ 'prx01', 'prx02', 'prx05' ]

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;

blktmp.processed_hosts = {};
out = [];
FOREACH host IN hosts.keys.sort;
  NEXT UNLESS status.item(hosts.$host.status);
  NEXT IF blktmp.processed_hosts.$host.defined;
  NEXT UNLESS ngcp.has_role(host, argv.role);
  peer = hosts.$host.peer;
  blktmp.processed_hosts.$peer = 1;
  out.push(ngcp.get_pairname(host));
END;
out = out.sort;

-%]
