-
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.
Merge pull request #43 from redBorder/development
Release 0.5.0
- Loading branch information
Showing
8 changed files
with
112 additions
and
4 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
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
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,16 @@ | ||
module RbProxy | ||
module Helpers | ||
def get_managers_all | ||
managers = [] | ||
managers_keys = Chef::Node.list.keys.sort | ||
managers_keys.each do |m_key| | ||
m = Chef::Node.load(m_key) | ||
roles = m[:roles] || [] | ||
if roles.include?('manager') | ||
managers << m | ||
end | ||
end | ||
managers | ||
end | ||
end | ||
end |
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,67 @@ | ||
module RbProxy | ||
module Helpers | ||
def update_hosts_file | ||
managers = get_managers_all() | ||
manager_ip = [] | ||
managers.each do |m| | ||
manager_ip << m['ipaddress_sync'] | ||
end | ||
|
||
# grouped_virtual_ips returns a hash where: | ||
# - The keys are IP addresses from the data bags, or `nil` if an IP is missing. | ||
# - The values are arrays of services associated with each IP address. | ||
# - If an IP is missing from a data bag, the associated services are grouped under the sync_ip key. | ||
grouped_virtual_ips = Hash.new { |hash, key| hash[key] = [] } | ||
databags = Chef::DataBag.load('rBglobal').keys | ||
databags.each do |bag| | ||
next unless bag.start_with?('ipvirtual-external') | ||
virtual_dg = data_bag_item('rBglobal', bag) | ||
ip = virtual_dg['ip'] | ||
|
||
if ip && !ip.empty? | ||
grouped_virtual_ips[ip] << bag.gsub('ipvirtual-external-', '') | ||
else | ||
grouped_virtual_ips[manager_ip[0]] << bag.gsub('ipvirtual-external-', '') | ||
end | ||
end | ||
|
||
# Read hosts file and store in hash | ||
hosts_hash = Hash.new { |hash, key| hash[key] = [] } | ||
File.readlines('/etc/hosts').each do |line| | ||
next if line.strip.empty? || line.start_with?('#') | ||
values = line.split(/\s+/) | ||
ip = values.shift | ||
services = values | ||
hosts_hash[ip].concat(services).uniq! | ||
end | ||
|
||
# Update hosts_hash based on grouped_virtual_ips | ||
grouped_virtual_ips.each do |new_ip, new_services| | ||
new_services.each do |new_service| | ||
service_key = new_service.split('.').first | ||
|
||
hosts_hash.each do |_ip, services| | ||
services.delete_if { |service| service.split('.').first == service_key } | ||
end | ||
|
||
if new_ip | ||
hosts_hash[new_ip] << "#{new_service}.service" | ||
hosts_hash[new_ip] << "#{new_service}.#{node['redborder']['cdomain']}" | ||
else | ||
hosts_hash[manager_ip[0]] << "#{new_service}.service" | ||
hosts_hash[manager_ip[0]] << "#{new_service}.#{node['redborder']['cdomain']}" | ||
end | ||
end | ||
end | ||
|
||
# Prepare the lines for the hosts file | ||
hosts_entries = [] | ||
hosts_hash.each do |ip, services| | ||
format_entry = format('%-18s%s', ip, services.join(' ')) | ||
hosts_entries << format_entry unless services.empty? | ||
end | ||
|
||
hosts_entries | ||
end | ||
end | ||
end |
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
maintainer_email '[email protected]' | ||
license 'AGPL-3.0' | ||
description 'Installs/Configures redborder proxy' | ||
version '0.4.0' | ||
version '0.5.0' | ||
|
||
depends 'rb-common' | ||
depends 'rb-selinux' | ||
|
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
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
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,3 @@ | ||
<% @hosts_entries.each do |host| %> | ||
<%= host %> | ||
<% end %> |