Created
July 11, 2012 14:59
-
-
Save mks-m/3090955 to your computer and use it in GitHub Desktop.
puppet repo graph
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
# Generates infrastructure graph in DOT format | |
# Usage: | |
# $ find . -name '*.pp' | while read file; do cat $file; echo; done | \ | |
# ruby graph.rb > puppet.dot | |
NODE = /^\s*(class|define|node)(\s+)([\w:]+)/ | |
RELATION = /^\s*(require|inherits|include)(\s+)([\w:]+)/ | |
USAGE = /^\s*([\w:]*[\w])(\s*)\{(\s*)/ | |
IGNORE = %w{file package service cron exec Exec line plugin} | |
$nodes = {} | |
while line = gets | |
line.gsub!(/#.*/, '') | |
if line =~ NODE | |
current_node = "\"#{$3}\"" | |
$nodes[current_node] = { | |
"type" => $1, | |
"uses" => [], | |
"include" => [], | |
"require" => [], | |
"inherits" => []} | |
end | |
if line =~ RELATION | |
$nodes[current_node][$1] << "\"#{$3}\"" | |
end | |
if line =~ USAGE | |
$nodes[current_node]["uses"] << "\"#{$1}\"" unless IGNORE.include?($1) | |
end | |
end | |
puts "digraph G {" | |
$nodes.each do |n, a| | |
puts "#{n}#{a['type'] == 'node' ? ' [shape=box]' : ''};" | |
puts "#{n} -> {#{a['uses'].join('; ')}} [style=dotted];" if a['uses'].any? | |
puts "#{n} -> {#{a['include'].join('; ')}};" if a['include'].any? | |
puts "#{n} -> {#{a['require'].join('; ')}};" if a['require'].any? | |
puts "#{n} -> {#{a['inherits'].join('; ')}};" if a['inherits'].any? | |
end | |
puts "}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment