[%
# vi: ft=tt2

# Return a hash of set_name=>dispatcher_id for a given cluster set type.
#
# @param argv.type      The type of element we are interested in (rtp, lb).
# @param argv.status    node status [ online, offline, inactive ]
#                         default value: ['online', 'inactive']
# @return out           The hash.

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 set IN cluster_sets.keys;
  NEXT IF (set == 'default_set' || set == 'type');

  FOREACH host IN hosts.keys.sort;
    NEXT UNLESS status.item(hosts.$host.status);
    NEXT UNLESS hosts.$host.role.grep('^' _ argv.type _ '$').size();
    FOREACH iface IN hosts.$host.interfaces;
      NEXT UNLESS hosts.$host.$iface.cluster_sets.grep('^' _ set _ '$').size();
      out.$set = cluster_sets.$set.dispatcher_id;
    END;
  END;
END;

-%]
