diff options
| author | Luke Kanies <luke@madstop.com> | 2007-09-12 18:32:26 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-09-12 18:32:26 -0500 |
| commit | 43f22a2414048b180d2c0e2a421fa8d905c4d8eb (patch) | |
| tree | 72eb0cc1ade37f032284c77ca51a7d1e22d5b317 /lib | |
| parent | a6fe70054f4fb3efe4d558ffdd244917ca1c6f9c (diff) | |
| download | puppet-43f22a2414048b180d2c0e2a421fa8d905c4d8eb.tar.gz puppet-43f22a2414048b180d2c0e2a421fa8d905c4d8eb.tar.xz puppet-43f22a2414048b180d2c0e2a421fa8d905c4d8eb.zip | |
Adding a to_graph method to TransBuckets, so that the buckets can directly generate a graph, rather than having to first convert to RAL types and then have them convert to a graph. This allows us to make it so components do not need a @children array at all. This was all done because I am having the "already a parent of" problem again, and I have gotten far enough that it is relatively easy to just make this problem go away once and for all.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/dsl.rb | 3 | ||||
| -rw-r--r-- | lib/puppet/pgraph.rb | 28 | ||||
| -rw-r--r-- | lib/puppet/transportable.rb | 50 | ||||
| -rw-r--r-- | lib/puppet/type/component.rb | 4 |
4 files changed, 79 insertions, 6 deletions
diff --git a/lib/puppet/dsl.rb b/lib/puppet/dsl.rb index 793578bca..795358e83 100644 --- a/lib/puppet/dsl.rb +++ b/lib/puppet/dsl.rb @@ -255,8 +255,7 @@ module Puppet def scope unless defined?(@scope) @interp = Puppet::Parser::Interpreter.new :Code => "" - # Load the class, so the node object class is available. - require 'puppet/network/handler/node' + require 'puppet/node' @node = Puppet::Node.new(Facter.value(:hostname)) @node.parameters = Facter.to_hash @interp = Puppet::Parser::Interpreter.new :Code => "" diff --git a/lib/puppet/pgraph.rb b/lib/puppet/pgraph.rb index 07bdff4bb..ddecc731d 100644 --- a/lib/puppet/pgraph.rb +++ b/lib/puppet/pgraph.rb @@ -19,6 +19,20 @@ class Puppet::PGraph < GRATR::Digraph super end + # Add a resource to our graph and to our resource table. + def add_resource(resource) + unless resource.respond_to?(:ref) + raise ArgumentError, "Can only add objects that respond to :ref" + end + + ref = resource.ref + if @resource_table.include?(ref) + raise ArgumentError, "Resource %s is already defined" % ref + else + @resource_table[ref] = resource + end + end + def add_vertex!(*args) @reversal = nil super @@ -26,6 +40,7 @@ class Puppet::PGraph < GRATR::Digraph def clear @vertex_dict.clear + #@resource_table.clear if defined? @edge_number @edge_number.clear end @@ -71,6 +86,12 @@ class Puppet::PGraph < GRATR::Digraph def edge_class() Puppet::Relationship end + + def initialize(*args) + super + # Create a table to keep references to all of our resources. + @resource_table = {} + end # Determine all of the leaf nodes below a given vertex. def leaves(vertex, type = :dfs) @@ -97,6 +118,11 @@ class Puppet::PGraph < GRATR::Digraph end end.flatten end + + # Look a resource up by its reference (e.g., File["/etc/passwd"]). + def resource(ref) + @resource_table[ref] + end # Take container information from another graph and use it # to replace any container vertices with their respective leaves. @@ -209,5 +235,3 @@ class Puppet::PGraph < GRATR::Digraph end end end - -# $Id$ diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb index aa7eb92f7..7a04e1f63 100644 --- a/lib/puppet/transportable.rb +++ b/lib/puppet/transportable.rb @@ -60,6 +60,17 @@ module Puppet instance_variables end + def to_ref + unless defined? @ref + if self.type and self.name + @ref = "%s[%s]" % [self.type, self.name] + else + @ref = nil + end + end + @ref + end + def to_type(parent = nil) retobj = nil if typeklass = Puppet::Type.type(self.type) @@ -188,6 +199,43 @@ module Puppet instance_variables end + # Create a resource graph from our structure. + def to_graph + graph = Puppet::PGraph.new + + delver = proc do |obj| + obj.each do |child| + unless container = graph.resource(obj.to_ref) + container = obj.to_type + graph.add_resource container + end + unless resource = graph.resource(child.to_ref) + resource = child.to_type + graph.add_resource resource + end + graph.add_edge!(container, resource) + if child.is_a?(self.class) + delver.call(child) + end + end + end + + delver.call(self) + + return graph + end + + def to_ref + unless defined? @ref + if self.type and self.name + @ref = "%s[%s]" % [self.type, self.name] + else + @ref = nil + end + end + @ref + end + def to_type(parent = nil) # this container will contain the equivalent of all objects at # this level @@ -287,7 +335,5 @@ module Puppet end end - #------------------------------------------------------------ end -# $Id$ diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb index 5905d85ab..79afa95a7 100644 --- a/lib/puppet/type/component.rb +++ b/lib/puppet/type/component.rb @@ -169,6 +169,10 @@ Puppet::Type.newtype(:component) do end end + def ref + title + end + # Remove an object. The argument determines whether the object's # subscriptions get eliminated, too. def remove(rmdeps = true) |
