[% # vi: ft=tt2 # Return an array of shared IPs for a given host. # # @param argv.host The host to get all shared IPs for. # @param argv.type The interface type or empty string for all types. # @param argv.format Return addresses in short format (default), expanded # format ('expand'), or as a hash with netmask info # ('hash') # @param argv.status node status [ online, offline, inactive ] # default value: ['online', 'inactive'] # @return out The array of shared 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; NEXT UNLESS hosts.${argv.host}.exists(iface); NEXT UNLESS hosts.${argv.host}.$iface.type.grep('^' _ argv.type _ '$').size(); FOREACH ip IN hosts.${argv.host}.$iface.shared_v6ip; expanded = ngcp.net_ip_expand(ip); IF argv.format == 'expand'; ip = expanded; END; NEXT UNLESS ip; IF argv.format == 'hash'; ip = { ip = ip, expanded = expanded, interface = iface, netmask = hosts.${argv.host}.$iface.v6netmask }; END; out.push(ip); END; END; END; IF argv.format == 'hash'; out = out.sort('ip'); ELSE; out = out.sort; END; -%]