diff options
author | Luke Kanies <luke@madstop.com> | 2008-03-31 23:56:09 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-03-31 23:56:09 -0500 |
commit | 88dc49cb7b0efe757c92ce28c807b91335acb07a (patch) | |
tree | 13fe4561f1f524f97a8bb2c1ff84c1ef981d0241 /lib/puppet/parser/resource.rb | |
parent | 4165edaeb71ee2883b1bb85ff39a52d5628b259f (diff) | |
parent | a8592f1009040ebf30a98268610915cc33bb3f63 (diff) | |
download | puppet-88dc49cb7b0efe757c92ce28c807b91335acb07a.tar.gz puppet-88dc49cb7b0efe757c92ce28c807b91335acb07a.tar.xz puppet-88dc49cb7b0efe757c92ce28c807b91335acb07a.zip |
Merge branch 'master' into master_no_global_resources
Conflicts:
lib/puppet/node/catalog.rb
lib/puppet/type/pfile.rb
lib/puppet/type/pfilebucket.rb
lib/puppet/util/filetype.rb
spec/unit/node/catalog.rb
spec/unit/other/transbucket.rb
spec/unit/ral/provider/mount/parsed.rb
spec/unit/ral/types/file.rb
spec/unit/ral/types/interface.rb
spec/unit/ral/types/mount.rb
spec/unit/ral/types/package.rb
spec/unit/ral/types/schedule.rb
spec/unit/ral/types/service.rb
test/language/compile.rb
test/language/lexer.rb
test/language/snippets.rb
test/lib/puppettest.rb
test/ral/types/basic.rb
test/ral/types/cron.rb
test/ral/types/exec.rb
test/ral/types/file.rb
test/ral/types/file/target.rb
test/ral/types/filebucket.rb
test/ral/types/fileignoresource.rb
test/ral/types/filesources.rb
test/ral/types/group.rb
test/ral/types/host.rb
test/ral/types/parameter.rb
test/ral/types/sshkey.rb
test/ral/types/tidy.rb
test/ral/types/user.rb
test/ral/types/yumrepo.rb
Diffstat (limited to 'lib/puppet/parser/resource.rb')
-rw-r--r-- | lib/puppet/parser/resource.rb | 89 |
1 files changed, 37 insertions, 52 deletions
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index 3f346166e..4b48ff6cf 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -3,18 +3,18 @@ class Puppet::Parser::Resource require 'puppet/parser/resource/param' require 'puppet/parser/resource/reference' + require 'puppet/util/tagging' include Puppet::Util include Puppet::Util::MethodHelper include Puppet::Util::Errors include Puppet::Util::Logging + include Puppet::Util::Tagging attr_accessor :source, :line, :file, :scope, :rails_id attr_accessor :virtual, :override, :translated attr_reader :exported, :evaluated, :params - attr_writer :tags - # Determine whether the provided parameter name is a relationship parameter. def self.relationship_parameter?(name) unless defined?(@relationship_names) @@ -58,8 +58,7 @@ class Puppet::Parser::Resource def evaluate if klass = @ref.definedtype finish() - scope.compile.delete_resource(self) - return klass.evaluate(:scope => scope, :resource => self) + return klass.evaluate_code(self) elsif builtin? devfail "Cannot evaluate a builtin type" else @@ -83,12 +82,19 @@ class Puppet::Parser::Resource # Do any finishing work on this object, called before evaluation or # before storage/translation. def finish - add_overrides() + return if finished? + @finished = true add_defaults() add_metaparams() + add_scope_tags() validate() end + # Has this resource already been finished? + def finished? + defined?(@finished) and @finished + end + def initialize(options) # Set all of the options we can. options.each do |option, value| @@ -130,12 +136,16 @@ class Puppet::Parser::Resource raise ArgumentError, "Resources do not accept %s" % options.keys.collect { |k| k.to_s }.join(", ") end - @tags = [] tag(@ref.type) - tag(@ref.title) if @ref.title.to_s =~ /^[-\w]+$/ + tag(@ref.title) if valid_tag?(@ref.title.to_s) + end - if scope.resource - @tags += scope.resource.tags + # Is this resource modeling an isomorphic resource type? + def isomorphic? + if builtin? + return @ref.builtintype.isomorphic? + else + return true end end @@ -223,21 +233,18 @@ class Puppet::Parser::Resource @ref.to_s end - # Add a tag to our current list. These tags will be added to all - # of the objects contained in this scope. - def tag(*ary) - ary.collect { |tag| tag.to_s.downcase }.collect { |tag| tag.split("::") }.flatten.each do |tag| - unless tag =~ /^\w[-\w]*$/ - fail Puppet::ParseError, "Invalid tag %s" % tag.inspect - end - unless @tags.include?(tag) - @tags << tag - end + # Define a parameter in our resource. + def set_parameter(param, value = nil) + if value + param = Puppet::Parser::Resource::Param.new( + :name => param, :value => value, :source => self.source + ) + elsif ! param.is_a?(Puppet::Parser::Resource::Param) + raise ArgumentError, "Must pass a parameter or all necessary values" end - end - def tags - @tags.dup + # And store it in our parameter hash. + @params[param.name] = param end def to_hash @@ -260,6 +267,8 @@ class Puppet::Parser::Resource # Handle file specially db_resource.file = self.file + db_resource.save + @params.each { |name, param| param.to_rails(db_resource) } @@ -336,7 +345,7 @@ class Puppet::Parser::Resource unless @params.include?(name) self.debug "Adding default for %s" % name - @params[name] = param + @params[name] = param.dup end end end @@ -361,16 +370,9 @@ class Puppet::Parser::Resource end end - # Add any overrides for this object. - def add_overrides - if overrides = scope.compile.resource_overrides(self) - overrides.each do |over| - self.merge(over) - end - - # Remove the overrides, so that the configuration knows there - # are none left. - overrides.clear + def add_scope_tags + if scope_resource = scope.resource + tag(*scope_resource.tags) end end @@ -382,11 +384,8 @@ class Puppet::Parser::Resource # The parameter is already set. Fail if they're not allowed to override it. unless param.source.child_of?(current.source) - if Puppet[:trace] - puts caller - end - msg = "Parameter '%s' is already set on %s" % - [param.name, self.to_s] + puts caller if Puppet[:trace] + msg = "Parameter '%s' is already set on %s" % [param.name, self.to_s] if current.source.to_s != "" msg += " by %s" % current.source end @@ -438,20 +437,6 @@ class Puppet::Parser::Resource end end - # Define a parameter in our resource. - def set_parameter(param, value = nil) - if value - param = Puppet::Parser::Resource::Param.new( - :name => param, :value => value, :source => self.source - ) - elsif ! param.is_a?(Puppet::Parser::Resource::Param) - raise ArgumentError, "Must pass a parameter or all necessary values" - end - - # And store it in our parameter hash. - @params[param.name] = param - end - # Make sure the resource's parameters are all valid for the type. def validate @params.each do |name, param| |