Add missing files
This commit is contained in:
45
site-cookbooks/kosmos_postgresql/libraries/helpers.rb
Normal file
45
site-cookbooks/kosmos_postgresql/libraries/helpers.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
class Chef
|
||||
class Recipe
|
||||
def postgresql_primary
|
||||
postgresql_primary = search(:node, "role:postgresql_primary AND chef_environment:#{node.chef_environment}").first
|
||||
|
||||
unless postgresql_primary.nil?
|
||||
primary_ip = ip_for(postgresql_primary)
|
||||
|
||||
{ hostname: postgresql_primary[:hostname], ipaddress: primary_ip }
|
||||
end
|
||||
end
|
||||
|
||||
def postgresql_replicas
|
||||
postgresql_replicas = []
|
||||
|
||||
search(:node, "role:postgresql_replica AND chef_environment:#{node.chef_environment}").each do |replica|
|
||||
replica_ip = ip_for(replica)
|
||||
|
||||
postgresql_replicas << { hostname: replica[:hostname], ipaddress: replica_ip }
|
||||
end
|
||||
|
||||
postgresql_replicas
|
||||
end
|
||||
|
||||
def ip_for(server_node)
|
||||
if node.chef_environment == "development"
|
||||
server_node['network']['interfaces']['eth1']['routes'].first['src']
|
||||
else
|
||||
# If the server has a private Zerotier IP, use it
|
||||
if server_node['knife_zero'] && server_node['knife_zero']['host'] && \
|
||||
server_node['knife_zero']['host'].start_with?("10.1.1.")
|
||||
server_node['knife_zero']['host']
|
||||
else
|
||||
server_node['ipaddress']
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def postgresql_service_name
|
||||
postgresql_version = "12"
|
||||
|
||||
"postgresql@#{postgresql_version}-main"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user