Class: HybridPlatformsConductor::HpcPlugins::Report::Mediawiki

Inherits:
Report
  • Object
show all
Defined in:
lib/hybrid_platforms_conductor/hpc_plugins/report/mediawiki.rb

Overview

Export in the Mediawiki format

Constant Summary collapse

TRANSLATIONS =
{
  en: {
    alias: 'Alias',
    comment: 'Comment',
    daily_backup: 'Daily backup',
    direct_deploy: 'Direct deployment',
    encrypted_storage: 'Encrypted storage',
    failover_ips: 'Failover IPs',
    false: 'No',
    fqdn: 'FQDN',
    geom_mirror: 'GEOM mirror',
    gui: 'GUI',
    handled_by_chef: 'Handled by Chef',
    hosted_on: 'Hosted on',
    hostname: 'Hostname',
    image: 'Image',
    kernel: 'Kernel',
    location: 'Location',
    missing_chef_recipes: 'Missing Chef recipes',
    missing_industrialization: 'Missing industrialization',
    non_encrypted_storage: 'Non-encrypted storage',
    openvz_specs: 'OpenVZ specifications',
    os: 'OS',
    xae_ip: 'XAE IP',
    xae_location: 'XAE location',
    xae_physical_ref: 'XAE physical reference',
    xae_reference: 'XAE reference',
    private_ips: 'Private IPs',
    product: 'Product',
    public_ips: 'Public IPs',
    raid: 'RAID setup',
    ripe_ips: 'RIPE IPs',
    server_type: 'Server type',
    'sub-product': 'Sub-Product',
    true: 'Yes',
    unattended_upgrades: 'Unattended upgrades',
    veid: 'VEID',
    vlan: 'VLAN',
    vrack: 'VRack'
  }
}

Constants included from LoggerHelpers

LoggerHelpers::LEVELS_MODIFIERS, LoggerHelpers::LEVELS_TO_STDERR

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Report

#initialize

Methods inherited from Plugin

extend_config_dsl_with, #initialize, valid?

Methods included from LoggerHelpers

#err, #init_loggers, #log_component=, #log_debug?, #log_level=, #out, #section, #set_loggers_format, #stderr_device, #stderr_device=, #stderr_displayed?, #stdout_device, #stdout_device=, #stdout_displayed?, #stdouts_to_s, #with_progress_bar

Constructor Details

This class inherits a constructor from HybridPlatformsConductor::Report

Class Method Details

.supported_localesObject

Give the list of supported locales by this report generator

API
  • This method is mandatory.

Result
  • Array<Symbol>: List of supported locales



60
61
62
# File 'lib/hybrid_platforms_conductor/hpc_plugins/report/mediawiki.rb', line 60

def self.supported_locales
  TRANSLATIONS.keys
end

Instance Method Details

#report_for(nodes, locale_code) ⇒ Object

Create a report for a list of nodes, in a given locale

API
  • This method is mandatory.

Parameters
  • nodes (Array<String>): List of nodes

  • locale_code (Symbol): The locale code



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/hybrid_platforms_conductor/hpc_plugins/report/mediawiki.rb', line 70

def report_for(nodes, locale_code)
  output = ''
  locale = TRANSLATIONS[locale_code]

  output << "    Back to the [[Hadoop]] / [[Impala]] / [[XAE_Network_Topology]] portal pages\n\n    This page has been generated using <code>./bin/report --format mediawiki</code> on \#{Time.now.utc.strftime('%F %T')} UTC.\n\n  EOS\n\n  # Get all confs\n  # Use the translations' keys to know all properties we want to display\n  all_properties = (%i[physical_node cluster private_ips description] + locale.keys).uniq\n  @nodes_handler.prefetch_metadata_of nodes, locale.keys\n  nodes.\n    map do |node|\n      { node: node }.merge(Hash[all_properties.map { |property| [property, @nodes_handler.metadata_of(node, property)] }])\n    end.\n    # Group them by physical / VMs\n    group_by do |node_info|\n      # Consume the info to not display it again later\n      physical_node = node_info.delete(:physical_node)\n      !physical_node.nil? && physical_node\n    end.\n    each do |physical, nodes_for_physical|\n      output << \"= \#{physical ? 'Physical' : 'Virtual'} nodes =\\n\\n\"\n      # Group them by location\n      nodes_for_physical.\n        group_by do |node_info|\n          # Consume the info to not display it again later\n          cluster = node_info.delete(:cluster)\n          cluster.nil? ? '' : cluster\n        end.\n        sort.\n        each do |cluster, nodes_for_cluster|\n          output << \"== \#{cluster.empty? ? 'Independent nodes' : \"Belonging to cluster \#{cluster}\"} ==\\n\\n\"\n          # Group them by IP range (24 bits)\n          nodes_for_cluster.\n            group_by { |node_info| node_info[:private_ips].nil? || node_info[:private_ips].empty? ? [] : node_info[:private_ips].first.split('.')[0..2].map(&:to_i) }.\n            sort.\n            each do |ip_range, nodes_for_ip_range|\n              output << \"=== \#{ip_range.empty? ? 'No IP' : \"\#{ip_range.join('.')}/24\"} ===\\n\\n\"\n              nodes_for_ip_range.\n                sort_by { |node_info| node_info[:node] }.\n                each do |node_info|\n                  output << \"* '''\#{node_info.delete(:node)}'''\#{node_info[:private_ips].nil? || node_info[:private_ips].empty? ? '' : \" - \#{node_info[:private_ips].first}\"} - \#{node_info.delete(:description)}\\n\"\n                  node_info.delete(:private_ips) if !node_info[:private_ips].nil? && node_info[:private_ips].size == 1\n                  node_info.sort.each do |property, value|\n                    unless value.nil?\n                      raise \"Missing translation of key: \#{property}. Please edit TRANSLATIONS[:\#{locale_code}].\" unless locale.key?(property)\n                      formatted_value =\n                        if value.is_a?(Array)\n                          \"\\n\#{value.map { |item| \"::* \#{item}\" }.join(\"\\n\")}\"\n                        elsif value.is_a?(Hash)\n                          \"\\n\#{value.map { |item, value| \"::* \#{item}: \#{value}\" }.join(\"\\n\")}\"\n                        elsif value.is_a?(TrueClass)\n                          locale[:true]\n                        elsif value.is_a?(FalseClass)\n                          locale[:false]\n                        else\n                          value.to_str\n                        end\n                      output << \": \#{locale[property]}: \#{formatted_value}\\n\"\n                    end\n                  end\n                  output << \"\\n\\n\"\n                end\n            end\n        end\n    end\n\n  output << <<~EOS\n    Back to the [[Hadoop]] / [[Impala]] / [[XAE_Network_Topology]] portal pages\n\n    [[Category:My Project]]\n    [[Category:Hadoop]]\n    [[Category:NoSQL]]\n    [[Category:Hosting]]\n    [[Category:XAE]]\n    [[Category:Server]]\n    [[Category:Configuration]]\n    [[Category:Chef]]\n  EOS\n\n  out output\nend\n"