Class: PuppetGraph::Grapher
- Inherits:
-
Object
- Object
- PuppetGraph::Grapher
- Defined in:
- lib/puppet-graph/grapher.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#fact_overrides ⇒ Object
Returns the value of attribute fact_overrides.
-
#modulepath ⇒ Object
Returns the value of attribute modulepath.
Instance Method Summary collapse
- #catalogue ⇒ Object
- #default_facts ⇒ Object
- #draw(format, output_file) ⇒ Object
- #draw_dot_graph(output_file) ⇒ Object
- #draw_png_graph(output_file) ⇒ Object
- #node ⇒ Object
- #relationship_graph ⇒ Object
- #stub_facts ⇒ Object
- #with_tmpdir ⇒ Object
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
5 6 7 |
# File 'lib/puppet-graph/grapher.rb', line 5 def code @code end |
#fact_overrides ⇒ Object
Returns the value of attribute fact_overrides.
3 4 5 |
# File 'lib/puppet-graph/grapher.rb', line 3 def fact_overrides @fact_overrides end |
#modulepath ⇒ Object
Returns the value of attribute modulepath.
4 5 6 |
# File 'lib/puppet-graph/grapher.rb', line 4 def modulepath @modulepath end |
Instance Method Details
#catalogue ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/puppet-graph/grapher.rb', line 43 def catalogue with_tmpdir do |dir| Puppet[:modulepath] = modulepath Puppet[:vardir] = dir Puppet[:confdir] = dir Puppet[:logdir] = dir Puppet[:rundir] = dir Puppet[:code] = code stub_facts Puppet::Resource::Catalog.indirection.find(node.name, :use_node => node) end end |
#default_facts ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/puppet-graph/grapher.rb', line 72 def default_facts @default_facts ||= { 'hostname' => node.name.split('p').first, 'fqdn' => node.name, 'domain' => node.name.split('.').last, } end |
#draw(format, output_file) ⇒ Object
7 8 9 |
# File 'lib/puppet-graph/grapher.rb', line 7 def draw(format, output_file) self.send("draw_#{format}_graph", output_file) end |
#draw_dot_graph(output_file) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/puppet-graph/grapher.rb', line 25 def draw_dot_graph(output_file) dot_graph = relationship_graph.to_dot('label' => code) File.open(output_file, 'wb') do |f| f.puts dot_graph end end |
#draw_png_graph(output_file) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/puppet-graph/grapher.rb', line 11 def draw_png_graph(output_file) dot_graph = relationship_graph.to_dot('label' => code) tmp_dot_file = Tempfile.new('puppet-graph') begin tmp_dot_file.write dot_graph tmp_dot_file.flush `dot -o#{output_file} -Tpng #{tmp_dot_file.path}` ensure tmp_dot_file.close tmp_dot_file.unlink end end |
#node ⇒ Object
89 90 91 |
# File 'lib/puppet-graph/grapher.rb', line 89 def node @node ||= Puppet::Node.new('testnode') end |
#relationship_graph ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/puppet-graph/grapher.rb', line 33 def relationship_graph @relationship_graph ||= lambda { graph = catalogue.to_ral.relationship_graph graph.vertices.select { |r| r.to_s == 'Class[Settings]' }.each do |vertex| graph.remove_vertex! vertex end graph }.call end |
#stub_facts ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/puppet-graph/grapher.rb', line 58 def stub_facts if fact_overrides.nil? facts = default_facts else facts = default_facts.merge(fact_overrides) end facts.each do |key, value| Facter.add(key) { setcode { value } } end node.merge(facts) end |
#with_tmpdir ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/puppet-graph/grapher.rb', line 80 def with_tmpdir dir = Dir.mktmpdir begin yield dir ensure FileUtils.remove_entry_secure dir end end |