From 37b7d7a1ced2ecbaf54e67d654d47be677da863b Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Thu, 7 Aug 2014 09:10:52 +0200 Subject: [PATCH] MT#8503 Add helper to fetch cluster ips. --- lib/get_all_cluster_set_ip_maps | 29 ++++++++++++++++++++++ lib/get_all_cluster_set_shared_ip_maps | 34 ++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 lib/get_all_cluster_set_ip_maps create mode 100644 lib/get_all_cluster_set_shared_ip_maps diff --git a/lib/get_all_cluster_set_ip_maps b/lib/get_all_cluster_set_ip_maps new file mode 100644 index 00000000..af90f3d0 --- /dev/null +++ b/lib/get_all_cluster_set_ip_maps @@ -0,0 +1,29 @@ +[% + # Return an array of hashes, each hash containing dispatcher_id and ips, + # which is an array of ips, for a given cluster set type. + # + # @param argv.type The type of element we are interested in (rtp, lb) + # @return out The array of hashes +-%] +[% + out = []; + FOREACH set IN cluster_sets.keys; + set = cluster_sets.$set; + IF set.${argv.type}.defined; + theset = { dispatcher_id = set.dispatcher_id }; + theset.ips = []; + FOREACH entry IN set.${argv.type}; + iftype = entry.iface; + host = entry.host; + FOREACH iface IN hosts.$host.interfaces; + realiface = hosts.$host.$iface; + NEXT UNLESS realiface.type.grep('^' _ iftype _ '$').size(); + theset.ips.push(realiface.ip); + END; + END; + IF theset.ips.size(); + out.push(theset); + END; + END; + END; +-%] diff --git a/lib/get_all_cluster_set_shared_ip_maps b/lib/get_all_cluster_set_shared_ip_maps new file mode 100644 index 00000000..73f92894 --- /dev/null +++ b/lib/get_all_cluster_set_shared_ip_maps @@ -0,0 +1,34 @@ +[% + # Return an array of hashes, each hash containing dispatcher_id and ips, + # which is an array of shared ips, for a given cluster set type. + # + # @param argv.type The type of element we are interested in (rtp, lb) + # @return out The array of hashes +-%] +[% + blktmp.processed_hosts = {}; + out = []; + FOREACH set IN cluster_sets.keys; + set = cluster_sets.$set; + IF set.${argv.type}.defined; + theset = { dispatcher_id = set.dispatcher_id }; + theset.ips = []; + FOREACH entry IN set.${argv.type}; + iftype = entry.iface; + host = entry.host; + NEXT IF blktmp.processed_hosts.$host.defined; + FOREACH iface IN hosts.$host.interfaces; + realiface = hosts.$host.$iface; + NEXT UNLESS realiface.type.grep('^' _ iftype _ '$').size(); + blktmp.processed_hosts.$peer = 1; + FOREACH ip IN realiface.shared_ip; + theset.ips.push(ip); + END; + END; + END; + IF theset.ips.size(); + out.push(theset); + END; + END; + END; +-%]