summaryrefslogtreecommitdiffstats
path: root/lib/puppet/node
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-12 18:40:54 -0500
committerLuke Kanies <luke@madstop.com>2007-09-12 18:40:54 -0500
commit3632926089cb27b93ff075c05ba21e2340a562ac (patch)
tree358905669eec4eef70e1f7997c35f3ecec82c1f5 /lib/puppet/node
parent43f22a2414048b180d2c0e2a421fa8d905c4d8eb (diff)
downloadpuppet-3632926089cb27b93ff075c05ba21e2340a562ac.tar.gz
puppet-3632926089cb27b93ff075c05ba21e2340a562ac.tar.xz
puppet-3632926089cb27b93ff075c05ba21e2340a562ac.zip
Moving the resource container behaviour to the Configuration object, rather than the base PGraph class. I expect I will just do away with PGraph, but for now, I am at least going to keep configuration-related code in that class.
Diffstat (limited to 'lib/puppet/node')
-rw-r--r--lib/puppet/node/configuration.rb27
1 files changed, 26 insertions, 1 deletions
diff --git a/lib/puppet/node/configuration.rb b/lib/puppet/node/configuration.rb
index 4f93fdbe5..be30ddb68 100644
--- a/lib/puppet/node/configuration.rb
+++ b/lib/puppet/node/configuration.rb
@@ -4,7 +4,7 @@ require 'puppet/external/gratr/digraph'
# meant to be passed from server to client, and it contains all
# of the information in the configuration, including the resources
# and the relationships between them.
-class Puppet::Node::Configuration < GRATR::Digraph
+class Puppet::Node::Configuration < Puppet::PGraph
attr_accessor :name, :version
attr_reader :extraction_format
@@ -18,6 +18,25 @@ class Puppet::Node::Configuration < GRATR::Digraph
tag(*classes)
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 clear
+ super
+ @resource_table.clear
+ end
+
def classes
@classes.dup
end
@@ -100,6 +119,12 @@ class Puppet::Node::Configuration < GRATR::Digraph
@extraction_format ||= :transportable
@tags = []
@classes = []
+ @resource_table = {}
+ end
+
+ # Look a resource up by its reference (e.g., File[/etc/passwd]).
+ def resource(ref)
+ @resource_table[ref]
end
# Add a tag.