Created
September 10, 2011 03:55
-
-
Save spheromak/1207896 to your computer and use it in GitHub Desktop.
ldirectord pub-sub (needs to be abstracted)
This file contains hidden or 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
| package "heartbeat-ldirectord" do | |
| action :install | |
| end | |
| lb = node[:heartbeat][:cluster] | |
| # find all nodes that think they belong to a service | |
| # | |
| subscribes=Hash.new | |
| search(:node, "milt_services:[* TO *]" ).each do |n| | |
| n["milt"]["services"].to_hash.each do |svc, val| | |
| if subscribes.has_key?(svc) | |
| subscribes[svc].merge!( { n["fqdn"] => val } ) | |
| else | |
| subscribes[svc]= { n["fqdn"] => val } | |
| end | |
| end | |
| end | |
| Chef::Log.info "SUBSCRIPTIONS: #{subscribes.inspect} " | |
| vip_defaults = node[:ldirectord][:defaults].to_hash | |
| vips=Array.new | |
| # pull each services vip data bag | |
| # -> load lb settings for vip | |
| data_bag('services').each do |s| | |
| data_bag_item('services', s)["vips"].each do |dbag| | |
| dbag["service"] = s | |
| Chef::Log.info "Settting up service #{s}" | |
| vips << dbag if dbag["ha"]["cluster"] == lb | |
| end | |
| end | |
| # -> add host to vips its subscribed too | |
| subscribes.keys.each do |svc| | |
| # load the hosts from the nodes to the vips its subscribed to | |
| vips.each_index do |i| | |
| next unless svc == vips[i]["service"] | |
| vips[i]["lb"]["config"] = vip_defaults.merge(vips[i]["lb"]["config"].to_hash) | |
| if vips[i]["lb"].has_key?("real_servers") | |
| vips[i]["lb"]["real_servers"].merge!(subscribes[svc]) | |
| else | |
| vips[i]["lb"]["real_servers"] = subscribes[svc] | |
| end | |
| end | |
| end | |
| # find all node data that optionally subscribes to a vip | |
| # -> add it to vips hash | |
| search(:node, "milt_vips_#{lb}:[* TO *]" ).each do |n| | |
| n[:milt][:vips][lb].keys.each do |node_vip| | |
| vips.each_index do |i| | |
| if vips[i]["name"] == node_vip | |
| if vips[i]["lb"].has_key?("real_servers") | |
| vips[i]["lb"]["real_servers"].to_hash.merge!(n["milt"]["vips"][lb][node_vip].to_hash) | |
| else | |
| vips[i]["lb"]["real_servers"] = n["milt"]["vips"][lb][node_vip].to_hash | |
| end | |
| end | |
| end | |
| end | |
| end | |
| #vips.each do |vip| | |
| # Chef::Log.info "VIPDBG: #{vip["name"] } : #{vip["lb"]["config"]["service"] } " | |
| # vip["lb"]["config"].each do |k, v| | |
| # Chef::Log.info "VIPDBG: #{k} = #{v}" | |
| # end | |
| # if vip["lb"].has_key?("real_servers") | |
| # vip["lb"]["real_servers"].each do |k, v| | |
| # Chef::Log.info "VIPDBG: Real = #{k}:#{vip["lb"]["config"]["service"]}\tgate\t#{v}" | |
| # end | |
| # end | |
| #end | |
| # unroll vips | |
| template node[:ldirectord][:config] do | |
| source "lvs.cf.erb" | |
| mode 0640 | |
| backup false | |
| variables(:vips => vips) | |
| end |
This file contains hidden or 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
| # ~~~ ldirectord configuration ~~~ | |
| # | |
| # <%= node[:ldirectord][:config] %> | |
| # config autogenerated via chef | |
| # local edits will be destroyed | |
| # | |
| # ~~~ ldirectord configuration ~~~ | |
| quiescent = <%= node[:ldirectord][:quiescent] %> | |
| autoreload = <%= node[:ldirectord][:autoreload] %> | |
| checktimeout = <%= node[:ldirectord][:checktimeout] %> | |
| checkinterval = <%= node[:ldirectord][:checkinterval] %> | |
| <% @vips.each do |vip| -%> | |
| <% next unless vip.has_key?("lb") %> | |
| virtual = <%= vip["name"] -%>:<%= vip["lb"]["config"]["service"] %> | |
| <% vip["lb"]["config"].each do |k, v| -%> | |
| <%= "#{k}\t= #{v}" %> | |
| <% end %> | |
| <% if vip["lb"]["maintenance"] %> | |
| # maintenance mode enabled for this vip | |
| <% next %> | |
| <% end %> | |
| <% if vip["lb"].has_key?("real_servers") -%> | |
| <% vip["lb"]["real_servers"].each do |k, v| -%> | |
| real = <%= "#{k}:#{vip["lb"]["config"]["service"]}\tgate\t#{v}" %> | |
| <% end -%> | |
| <% end %> | |
| <% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment