You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ngcpcfg/lib/get_all_ips_for_host

46 lines
1007 B

[%
# vi: ft=tt2
# Return an array of IPs for a given host.
#
# @param argv.host The host to get all IPs for.
# @param argv.type The interface type or empty string for all types.
# @param argv.status node status [ online, offline, inactive ]
# default value: ['online', 'inactive']
# @return out The array of 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();
NEXT UNLESS hosts.${argv.host}.$iface.ip;
out.push(hosts.${argv.host}.$iface.ip);
END;
END;
out = out.sort;
-%]