From bf6697cd2473d16577d8f5cf527cf843dabc0bfb Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Mon, 15 Dec 2014 21:30:56 +0100 Subject: [PATCH] MT#10635 add get_all_cluster_set[_shared]ip_for_host remove argv.host from get_all_cluster_set[_shared]ip Split the logic between for_host or all Change-Id: Ice280f5b261b93f8abf92fb2bc357dacbcaa39f4 (cherry picked from commit ff80f075aa215bd118f16c4115f8d9cd463922a4) --- lib/get_all_cluster_set_ip_maps | 15 +----- lib/get_all_cluster_set_ip_maps_for_host | 44 ++++++++++++++++ lib/get_all_cluster_set_shared_ip_maps | 15 +----- ...et_all_cluster_set_shared_ip_maps_for_host | 50 +++++++++++++++++++ 4 files changed, 96 insertions(+), 28 deletions(-) create mode 100644 lib/get_all_cluster_set_ip_maps_for_host create mode 100644 lib/get_all_cluster_set_shared_ip_maps_for_host diff --git a/lib/get_all_cluster_set_ip_maps b/lib/get_all_cluster_set_ip_maps index 04b052aa..70d9401b 100644 --- a/lib/get_all_cluster_set_ip_maps +++ b/lib/get_all_cluster_set_ip_maps @@ -2,32 +2,19 @@ # 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.host If the cluster_set type is 'central; we need to filter by pair # @param argv.role The role of element we are interested in (rtp, lb) # @param argv.type The type of the interfaces (rtp_int, sip_int...) # @return out The array of hashes -%] -[% - IF !hosts.${argv.host}.defined; - argv.host = 'self'; - END; --%] [% out = []; - IF cluster_sets.type == 'central'; - set_hosts = [ argv.host, hosts.${argv.host}.peer ]; - ELSE; - set_hosts = hosts.keys; - END; - - FOREACH set IN cluster_sets.keys; NEXT IF (set == 'default_set' || set == 'type'); theset = { dispatcher_id = cluster_sets.$set.dispatcher_id }; theset.ips = []; - FOREACH host IN set_hosts; + FOREACH host IN hosts.keys; NEXT UNLESS hosts.$host.role.grep('^' _ argv.role _ '$').size(); FOREACH iface IN hosts.$host.interfaces; NEXT UNLESS hosts.$host.$iface.cluster_sets.grep('^' _ set _ '$').size(); diff --git a/lib/get_all_cluster_set_ip_maps_for_host b/lib/get_all_cluster_set_ip_maps_for_host new file mode 100644 index 00000000..04b052aa --- /dev/null +++ b/lib/get_all_cluster_set_ip_maps_for_host @@ -0,0 +1,44 @@ +[% + # 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.host If the cluster_set type is 'central; we need to filter by pair + # @param argv.role The role of element we are interested in (rtp, lb) + # @param argv.type The type of the interfaces (rtp_int, sip_int...) + # @return out The array of hashes +-%] +[% + IF !hosts.${argv.host}.defined; + argv.host = 'self'; + END; +-%] +[% + out = []; + + IF cluster_sets.type == 'central'; + set_hosts = [ argv.host, hosts.${argv.host}.peer ]; + ELSE; + set_hosts = hosts.keys; + END; + + + FOREACH set IN cluster_sets.keys; + NEXT IF (set == 'default_set' || set == 'type'); + theset = { dispatcher_id = cluster_sets.$set.dispatcher_id }; + theset.ips = []; + + FOREACH host IN set_hosts; + NEXT UNLESS hosts.$host.role.grep('^' _ argv.role _ '$').size(); + FOREACH iface IN hosts.$host.interfaces; + NEXT UNLESS hosts.$host.$iface.cluster_sets.grep('^' _ set _ '$').size(); + NEXT UNLESS hosts.$host.$iface.type.grep('^' _ argv.type _ '$').size(); + theset.ips.push(hosts.$host.$iface.ip) UNLESS theset.ips.defined(hosts.$host.$iface.ip); + END; + END; + + IF theset.ips.size(); + out.push(theset); + END; + + END; +-%] diff --git a/lib/get_all_cluster_set_shared_ip_maps b/lib/get_all_cluster_set_shared_ip_maps index 048ad444..6911311f 100644 --- a/lib/get_all_cluster_set_shared_ip_maps +++ b/lib/get_all_cluster_set_shared_ip_maps @@ -2,33 +2,20 @@ # 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.host If the cluster_set type is 'central; we need to filter by pair # @param argv.role The role of element we are interested in (rtp, lb) # @param argv.type The type of the interfaces (rtp_int, sip_int...) # @return out The array of hashes -%] -[% - IF !hosts.${argv.host}.defined; - argv.host = 'self'; - END; --%] [% out = []; - IF cluster_sets.type == 'central'; - set_hosts = [ argv.host, hosts.${argv.host}.peer ]; - ELSE; - set_hosts = hosts.keys; - END; - - FOREACH set IN cluster_sets.keys; NEXT IF (set == "default_set" || set == "type"); blktmp.processed_hosts = {}; theset = { dispatcher_id = cluster_sets.$set.dispatcher_id }; theset.ips = []; - FOREACH host IN set_hosts; + FOREACH host IN hosts.keys; NEXT IF blktmp.processed_hosts.$host.defined; NEXT UNLESS hosts.$host.role.grep('^' _ argv.role _ '$').size(); peer = hosts.$host.peer; diff --git a/lib/get_all_cluster_set_shared_ip_maps_for_host b/lib/get_all_cluster_set_shared_ip_maps_for_host new file mode 100644 index 00000000..e9eb0d7a --- /dev/null +++ b/lib/get_all_cluster_set_shared_ip_maps_for_host @@ -0,0 +1,50 @@ +[% + # 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.host If the cluster_set type is 'central; we need to filter by pair. + # @param argv.role The role of element we are interested in (rtp, lb) + # @param argv.type The type of the interfaces (rtp_int, sip_int...) + # @return out The array of hashes +-%] +[% + IF !hosts.${argv.host}.defined; + argv.host = 'self'; + END; +-%] +[% + out = []; + + IF cluster_sets.type == 'central'; + set_hosts = [ argv.host, hosts.${argv.host}.peer ]; + ELSE; + set_hosts = hosts.keys; + END; + + + FOREACH set IN cluster_sets.keys; + NEXT IF (set == "default_set" || set == "type"); + blktmp.processed_hosts = {}; + theset = { dispatcher_id = cluster_sets.$set.dispatcher_id }; + theset.ips = []; + + FOREACH host IN set_hosts; + NEXT IF blktmp.processed_hosts.$host.defined; + NEXT UNLESS hosts.$host.role.grep('^' _ argv.role _ '$').size(); + peer = hosts.$host.peer; + FOREACH iface IN hosts.$host.interfaces; + NEXT UNLESS hosts.$host.$iface.cluster_sets.grep('^' _ set _ '$').size(); + NEXT UNLESS hosts.$host.$iface.type.grep('^' _ argv.type _ '$').size(); + blktmp.processed_hosts.$peer = 1; + FOREACH ip IN hosts.$host.$iface.shared_ip; + theset.ips.push(ip) UNLESS theset.ips.defined(ip); + END; + END; + END; + + IF theset.ips.size(); + out.push(theset); + END; + + END; +-%]