Revision b1dad4cd
Added by Tomer Brisker over 7 years ago
app/assets/javascripts/application.js | ||
---|---|---|
$(item).closest('.accordion-group').remove();
|
||
}
|
||
|
||
function show_rdoc(item){
|
||
var url = $(item).attr('data-url');
|
||
window.open(url);
|
||
}
|
||
|
||
// shows provisioning templates in a new window
|
||
$(function() {
|
||
$('[data-provisioning-template=true]').click(function(){
|
app/helpers/puppetclasses_helper.rb | ||
---|---|---|
module PuppetclassesHelper
|
||
include PuppetclassesAndEnvironmentsHelper
|
||
include LookupKeysHelper
|
||
def rdoc_classes_path(environment, name)
|
||
klass = name.gsub('::', '/')
|
||
"puppet/rdoc/#{environment}/classes/#{klass}.html"
|
||
end
|
||
|
||
def overridden?(puppetclass)
|
||
puppetclass.class_params.present? && puppetclass.class_params.map(&:override).all?
|
app/models/puppetclass.rb | ||
---|---|---|
.count
|
||
end
|
||
|
||
# Populates the rdoc tree with information about all the classes in your modules.
|
||
# Firstly, we prepare the modules tree
|
||
# Secondly we run puppetdoc over the modulespath and manifestdir for all environments
|
||
# The results are written into document_root/puppet/rdoc/<env>/<class>"
|
||
def self.rdoc(root)
|
||
debug, verbose = false, false
|
||
relocated = root != "/" # This is true if the prepare phase copied the modules tree
|
||
|
||
# Retrieve an optional http server's DocumentRoot from the settings.yaml file, and prepare it for writing
|
||
doc_root = Pathname.new(Setting[:document_root])
|
||
doc_root.mkpath
|
||
unless doc_root.directory? && doc_root.writable?
|
||
puts "Unable to write html to #{doc_root}"
|
||
return false
|
||
end
|
||
validator = '<div id="validator-badges">'
|
||
# For each environment we write a puppetdoc tree
|
||
for env, path in Environment.puppetEnvs
|
||
# We may need to rewrite the modulepaths because they have been changed by the prepare step
|
||
modulepaths = relocated ? path.split(":").map{|p| root + p}.join(":") : path
|
||
|
||
# Identify and prepare the output directory
|
||
out = doc_root + env
|
||
out.rmtree if out.directory?
|
||
|
||
replacement = "<div id=\\\"validator-badges\\\"><small><a href=\\\"/puppet/rdoc/#{env}/\\\">[Browser]</a></small>"
|
||
|
||
# Create the documentation
|
||
|
||
puts "*********Proccessing environment #{env} *************"
|
||
cmd = "puppetdoc --output #{out} --modulepath #{modulepaths} -m rdoc"
|
||
puts cmd if Foreman.in_rake?
|
||
sh cmd do |ok, res|
|
||
if ok
|
||
# Add a link to the class browser
|
||
files = `find #{out} -exec grep -l 'validator-badges' {} \\; 2>/dev/null`.gsub(/\n/, " ")
|
||
if files.empty?
|
||
warn "No files to update with the browser link in #{out}. This is probably due to a previous error."
|
||
else
|
||
cmd = "ruby -p -i -e '$_.gsub!(/#{validator}/,\"#{replacement}\")' #{files}"
|
||
puts cmd if debug
|
||
sh cmd
|
||
end
|
||
# Relocate the paths for files and references if the manifests were relocated and sanitized
|
||
if relocated && (files = `find #{out} -exec grep -l '#{root}' {} \\;`.gsub(/\n/, " ")) != ""
|
||
puts "Rewriting..." if verbose
|
||
cmd = "ruby -p -i -e 'rex=%r{#{root}};$_.gsub!(rex,\"\")' #{files}"
|
||
puts cmd if debug
|
||
sh cmd
|
||
# Now relocate the files/* files to match the rewritten url
|
||
mv Dir.glob("#{out}/files/#{root}/*"), "#{out}/files", :verbose => verbose
|
||
end
|
||
else
|
||
logger.warn "Failed to process puppetdocs for #{out} while executing #{cmd}"
|
||
puts "Failed to process puppetdocs for #{out} while executing #{cmd}"
|
||
end
|
||
end
|
||
puts
|
||
end
|
||
end
|
||
|
||
# Optionally creates a copy of the current puppet modules and sanitizes it.
|
||
# If your 'live' manifests and modules can be parsed by puppetdoc
|
||
# then you do not need to do this step. (Unfortunately some sites have circular
|
||
# symlinks which have to be removed.)
|
||
# If the executable Rails,root/script/rdoc_prepare_script exists then it is run
|
||
# and passed a list of all directory paths in all environments.
|
||
# It should return the directory into which it has copied the cleaned modules"
|
||
def self.prepare_rdoc(root)
|
||
debug, verbose = false, false
|
||
|
||
prepare_script = Pathname.new(Rails.root) + "script/rdoc_prepare_script.rb"
|
||
if prepare_script.executable?
|
||
dirs = Environment.puppetEnvs.values.join(":").split(":").uniq.sort.join(" ")
|
||
puts "Running #{prepare_script} #{dirs}" if debug
|
||
location = `#{prepare_script} #{dirs}`
|
||
if $CHILD_STATUS == 0
|
||
root = location.chomp
|
||
puts "Relocated modules to #{root}" if verbose
|
||
end
|
||
else
|
||
puts "No executable #{prepare_script} found so using the uncopied module sources" if verbose
|
||
end
|
||
root
|
||
end
|
||
|
||
def self.search_by_host(key, operator, value)
|
||
conditions = sanitize_sql_for_conditions(["hosts.name #{operator} ?", value_to_sql(operator, value)])
|
||
direct = Puppetclass.joins(:hosts).where(conditions).pluck('puppetclasses.id').uniq
|
app/models/setting/puppet.rb | ||
---|---|---|
self.set('outofsync_interval', N_("Duration in minutes after the Puppet interval for servers to be classed as out of sync."), 5, N_('Out of sync interval')),
|
||
self.set('default_puppet_environment', N_("Foreman will default to this puppet environment if it cannot auto detect one"), "production", N_('Default Puppet environment'), nil, { :collection => Proc.new {Hash[Environment.all.map{|env| [env[:name], env[:name]]}]} }),
|
||
self.set('modulepath',N_("Foreman will set this as the default Puppet module path if it cannot auto detect one"), "/etc/puppet/modules", N_('Module path')),
|
||
self.set('document_root', N_("Document root where puppetdoc files should be created"), "#{Rails.root}/public/puppet/rdoc", N_('Document root')),
|
||
self.set('puppetrun', N_("Enable puppetrun support"), false, N_('Puppetrun')),
|
||
self.set('puppet_server', N_("Default Puppet server hostname"), "puppet", N_('Puppet server')),
|
||
self.set('Default_variables_Lookup_Path', N_("Foreman will evaluate host smart variables in this order by default"), ["fqdn", "hostgroup", "os", "domain"], N_('Default variables lookup path')),
|
app/views/puppetclasses/index.html.erb | ||
---|---|---|
<thead>
|
||
<tr>
|
||
<th class="col-md-3"><%= sort :name, :as => s_("Puppetclass|Name") %></th>
|
||
<th class="col-md-3"><%= sort :environment, :as => _("Environments and documentation") %></th>
|
||
<th class="col-md-3"><%= sort :environment, :as => _("Environments") %></th>
|
||
<th class="col-md-2"><%= _('Host groups') %></th>
|
||
<th><%= _('Hosts') %></th>
|
||
<th class="col-md-1"><%= _('Hosts') %></th>
|
||
<th class="col-md-1"><%= _('Parameters') %></th>
|
||
<th class="col-md-1"><%= _('Variables') %></th>
|
||
<th class="col-md-1"><%= _("Actions") %></th>
|
||
... | ... | |
<% for puppetclass in @puppetclasses %>
|
||
<tr>
|
||
<td class="ellipsis"><%=link_to_if_authorized puppetclass.name, hash_for_edit_puppetclass_path(:id => puppetclass).merge(:auth_object => puppetclass, :authorizer => authorizer) %></td>
|
||
<td class="">
|
||
<% puppetclass.environments.uniq.each do |environment| %>
|
||
<%= link_to_function environment, 'show_rdoc(this)', :'data-url' => rdoc_classes_path(environment, puppetclass.name) %>
|
||
<% end %>
|
||
<td class="ellipsis">
|
||
<%= puppetclass.environments.uniq.to_sentence %>
|
||
</td>
|
||
<td class=""><%= puppetclass.all_hostgroups(false).map {|hg| link_to_if_authorized trunc_with_tooltip(hg, 24), hash_for_edit_hostgroup_path(:id=>hg).merge(:auth_object => hg, :authorizer => @hostgroups_authorizer)}.to_sentence.html_safe %></td>
|
||
<td><%= link_to puppetclass.hosts_count, hosts_path(:search => "class = #{puppetclass.name}")%></td>
|
extras/rdoc/rdoc_prepare_script.rb | ||
---|---|---|
#!/usr/bin/ruby
|
||
verbose = false
|
||
require 'fileutils'
|
||
# Takes a list of directories and copies them, ignoring version control directories, to a new location
|
||
# It then sanitizes them by removing any circular symlinks
|
||
# It must return the new root directory for the tree
|
||
modules_root = "/tmp/puppet"
|
||
FileUtils.mkpath modules_root unless File.exist? modules_root
|
||
FileUtils.rm_rf Dir.glob("#{modules_root}/*")
|
||
FileUtils.chdir "/"
|
||
dirs = ARGV[0..100]
|
||
|
||
# We need to copy in the checked out puppet modules tree. Skipping all the .svn entries.
|
||
modules = "/etc/puppet/modules"
|
||
exit(-1) unless system "tar --create --file - --exclude-vcs #{modules[1..-1]} | tar --extract --file - --read-full-records --directory #{modules_root}"
|
||
|
||
# This copies in the /etc/puppent/env directory symlink trees
|
||
exit(-1) unless system "tar --create --file - --exclude-vcs #{dirs.map{|d| d[1..-1]}.join(' ')} | tar --extract --file - --read-full-records --directory #{modules_root}"
|
||
for dir in dirs
|
||
here = modules_root + dir
|
||
# Scan each modulepath for symlinks and remove them if they point at ".".
|
||
# If they are absolute, recreate them pointing at the copied tree location
|
||
Dir.foreach(here) do |entry|
|
||
linkfile = here + "/" + entry
|
||
next unless File.ftype(linkfile) == "link"
|
||
target = File.readlink(linkfile)
|
||
File.unlink(linkfile) if target == "."
|
||
if target=~/^\//
|
||
File.unlink(linkfile)
|
||
File.symlink modules_root + target, linkfile
|
||
end
|
||
end
|
||
end
|
||
# Look through the resulting tree and remove broken and cyclic links
|
||
links = `find #{modules_root} -type l`
|
||
for link in links
|
||
link.chomp!
|
||
# Remove links pointing to missing files
|
||
unless File.exist?(File.readlink(link))
|
||
File.unlink(link)
|
||
next
|
||
end
|
||
# Remove links pointing to "."
|
||
if File.readlink(link) =~ /\.|\,\//
|
||
File.unlink(link)
|
||
puts "Removing #{link}" if verbose
|
||
else
|
||
puts "link #{link} points to #{File.readlink(link)}" if verbose
|
||
end
|
||
end
|
||
puts modules_root
|
lib/tasks/puppet.rake | ||
---|---|---|
require 'yaml'
|
||
|
||
namespace :puppet do
|
||
root = "/"
|
||
# Author: Paul Kelly (paul.ian.kelly@gogglemail.com)
|
||
# Description: The tasks defined in this namespace populate a directory structure with rdocs for the
|
||
# clases defined in puppet.
|
||
namespace :rdoc do
|
||
desc "
|
||
Populates the rdoc tree with information about all the classes in your modules."
|
||
task :generate => [:environment, :prepare] do
|
||
Puppetclass.rdoc root
|
||
end
|
||
desc "
|
||
Optionally creates a copy of the current puppet modules and sanitizes it.
|
||
It should return the directory into which it has copied the cleaned modules"
|
||
task :prepare => :environment do
|
||
root = Puppetclass.prepare_rdoc root
|
||
end
|
||
end
|
||
namespace :migrate do
|
||
desc "Populates the host fields in Foreman based on your StoredConfig DB"
|
||
task :populate_hosts => :environment do
|
test/fixtures/settings.yml | ||
---|---|---|
category: Setting::Puppet
|
||
default: /etc/puppet/modules
|
||
description: "The Setting::Puppet default module path in case that Foreman can't auto detect it"
|
||
attributes11:
|
||
name: document_root
|
||
category: Setting::Puppet
|
||
default: /home/olevy/git/foreman/public/puppet/rdoc
|
||
description: Document root where puppetdoc files should be created
|
||
attributes12:
|
||
name: puppet_server
|
||
category: Setting::Puppet
|
Also available in: Unified diff
Fixes #1556, #11615 - Remove puppet rdoc support
Puppet rdoc support has been broken for a long time. Removing it from
Foreman.