-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32fe52b
commit 161b5dd
Showing
1 changed file
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
module Rb_manager | ||
module Helpers | ||
def get_virtual_ip_info(managers) | ||
virtual_ips = {} | ||
ip_regex = /^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$/ | ||
has_any_virtual_ip=false | ||
|
||
node["redborder"]["manager"]["virtual_ips"].each do |type, services| | ||
virtual_ips[type.to_s] = {} | ||
services.each do |service| | ||
virtual_dg = Chef::DataBagItem.load('rBglobal', "ipvirtual-#{type}-#{service["service"]}") rescue ipvirtual_dg = {} | ||
hash = {} | ||
hash['ip'] = virtual_dg['ip'] | ||
hash['loadbalance'] = (virtual_dg['loadbalance'].nil? ? true : virtual_dg['loadbalance']) | ||
|
||
hash['service'] = service['service'] | ||
if virtual_dg['ip'] =~ ip_regex and !hash['ip'].nil? | ||
hash['enable'] = true | ||
else | ||
hash['enable'] = false | ||
end | ||
|
||
if hash['enable'] | ||
hash['virtual'] = true | ||
hash['run_anywhere'] = true | ||
has_any_virtual_ip=true if (hash['ip'] and manager_services[service['service']]) | ||
hash["iface"]= node['redborder']['management_interface'] | ||
if manager_services[service['service']] | ||
all_deps_enabled=true | ||
if !service['deps'].nil? | ||
service['deps'].each do |srv_dep| | ||
all_deps_enabled=false if manager_services[srv_dep].nil? or manager_services[srv_dep]==false | ||
end | ||
end | ||
hash['enable'] = all_deps_enabled | ||
else | ||
hash['enable'] = false | ||
end | ||
else | ||
#The virtual ip is not valid or it has not been specified. We need to set at least one | ||
hash['virtual'] = false | ||
hash['run_anywhere'] = false | ||
nodeservice=nil | ||
managers.each do |m| | ||
hash["iface"] = node['redborder']['management_interface'] | ||
run_anywhere_flag=false | ||
|
||
if m.name == node.name | ||
run_anywhere_flag=manager_services[service['service']] | ||
elsif !m['redborder'].nil? and !m['redborder']['manager'].nil? and !m['redborder']['manager']['services'].nil? and !m['redborder']['manager']['services']['current'].nil? | ||
run_anywhere_flag=m['redborder']["manager"]["services"]["current"][service['service']] | ||
end | ||
|
||
if run_anywhere_flag and !m['redborder']['manager'][hash['iface']].nil? | ||
nodeservice=m | ||
break | ||
end | ||
end | ||
|
||
if nodeservice.nil? | ||
managers.each do |m| | ||
hash["iface"] = node['redborder']['management_interface'] | ||
run_anywhere_flag=false | ||
run_anywhere_flag=m['redborder']['manager']['services']['overwrite'][service['service']] if !m['redborder']['manager']['services']['overwrite'].nil? | ||
run_anywhere_flag=m['redborder']['manager']['services'][m['redborder']['manager']['mode']][service['service']] if (run_anywhere_flag!=true and !m['redborder']['manager']['services'][m['redborder']['manager']['mode']].nil?) | ||
if run_anywhere_flag and !m["redborder"]["manager"][hash["iface"]].nil? | ||
nodeservice=m | ||
break | ||
end | ||
end | ||
end | ||
|
||
if !nodeservice.nil? and !nodeservice['redborder']['manager'][hash['iface']].nil? | ||
hash['virtual'] = false | ||
hash['ip'] = nodeservice['redborder']['manager'][hash['iface']]['ip'] | ||
hash['physical_ip'] = hash['ip'] | ||
hash['prefixlen'] = nodeservice['redborder']['manager'][hash['iface']]['prefixlen'] | ||
hash['run_anywhere'] = true | ||
end | ||
end | ||
virtual_ips[type.to_s][service["service"]] = hash | ||
end | ||
end | ||
return virtual_ips, has_any_virtual_ip | ||
|
||
end | ||
|
||
def get_virtual_ips_per_ip_info(virtual_ips) | ||
virtual_ips_per_ip = {} | ||
virtual_ips.each do |type, data| | ||
data.each.each do |service, vi| | ||
if vi['ip'] | ||
virtual_ips_per_ip[vi['ip']] = [] if virtual_ips_per_ip[vi['ip']].nil? | ||
virtual_ips_per_ip[vi['ip']] << vi | ||
end | ||
end | ||
end | ||
virtual_ips_per_ip | ||
end | ||
|
||
end | ||
end |