Skip to content

Commit

Permalink
(maint) define an intuitive output order
Browse files Browse the repository at this point in the history
  • Loading branch information
tkishel committed Oct 17, 2019
1 parent d4cd672 commit 4eb14cc
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions lib/puppet_x/puppetlabs/tune.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def output_infrastructure
def output_current_settings
current_total_puppetserver_jrubies = collect_current_settings

@current_collected_nodes.each do |certname, node|
@current_collected_nodes.sort_by { |_k, node| [node['order'], node['certname']] }.each do |certname, node|
next if @options[:node] && certname != @options[:node]
output_current_settings_for_node(certname, node)
end
Expand All @@ -151,7 +151,7 @@ def output_optimized_settings
optimized_total_puppetserver_jrubies = collect_optimized_settings

collect_optimized_settings_common_to_all_nodes
@collected_nodes.each do |certname, node|
@collected_nodes.sort_by { |_k, node| [node['order'], node['certname']] }.each do |certname, node|
next if @options[:node] && certname != @options[:node]
output_optimized_settings_for_node(certname, node)
end
Expand All @@ -169,7 +169,7 @@ def output_compare_current_and_optimized_settings
collect_current_settings
collect_optimized_settings

@current_collected_nodes.each do |certname, current_node|
@current_collected_nodes.sort_by { |_k, node| [node['order'], node['certname']] }.each do |certname, current_node|
next if @options[:node] && certname != @options[:node]
if current_node['settings']['params'].empty?
output _('No currently defined settings to compare for %{role} %{certname}') % { role: current_node['role'], certname: certname }
Expand Down Expand Up @@ -386,8 +386,10 @@ def configuration_for_node(certname)

def collect_current_node(certname, role, settings)
properties = {
'role' => role,
'settings' => settings,
'certname' => certname,
'order' => output_order(role),
'role' => role,
'settings' => settings,
}
@current_collected_nodes[certname] = properties
end
Expand All @@ -396,13 +398,34 @@ def collect_current_node(certname, role, settings)

def collect_optimized_node(certname, role, node)
properties = {
'certname' => certname,
'order' => output_order(role),
'resources' => node['resources'],
'role' => role,
'settings' => node['settings'],
}
@collected_nodes[certname] = properties
end

# Establish an intuitive output order of hosts.

def output_order(role)
case role
when 'Primary Master'
1
when 'Replica Master'
2
when 'Console Host'
3
when 'PuppetDB Host'
4
when 'External Database Host'
5
else
9
end
end

# Extract optimized settings common to all PE Infrastructure nodes.

def collect_optimized_settings_common_to_all_nodes
Expand Down Expand Up @@ -572,7 +595,7 @@ def output_settings_to_hiera
output_error_and_exit _("Unable to create output directory: %{directory}") % { directory: hiera_directory } unless File.directory?(hiera_directory)
Dir.mkdir(hiera_subdirectory) unless File.directory?(hiera_subdirectory)
output_error_and_exit _("Unable to create output subdirectory: %{directory}") % { directory: hiera_subdirectory } unless File.directory?(hiera_subdirectory)
@collected_nodes.each do |certname, properties|
@collected_nodes.sort_by { |_k, node| [node['order'], node['certname']] }.each do |certname, properties|
next if @options[:node] && certname != @options[:node]
next if properties['settings']['params'].empty?
output_file = "#{@options[:hiera]}/nodes/#{certname}.yaml"
Expand All @@ -589,7 +612,7 @@ def output_settings_to_hiera

def output_settings_to_pe_conf
return unless @options[:pe_conf]
@collected_nodes.each do |_certname, properties|
@collected_nodes.sort_by { |_k, node| [node['order'], node['certname']] }.each do |_certname, properties|
next if @options[:node] && certname != @options[:node]
next if properties['settings']['params'].empty?
if @pe_conf::write(properties['settings']['params'])
Expand Down

0 comments on commit 4eb14cc

Please sign in to comment.