diff options
| author | Luke Kanies <luke@madstop.com> | 2008-01-19 13:40:40 -0800 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-01-19 13:40:40 -0800 |
| commit | f98be4a7198326b26f1072c401b3e337f340db40 (patch) | |
| tree | 36a3f5637a175bc7da7acb639857bf2c2ca9f0c3 /lib | |
| parent | 2cbab2c6916d6bd7c5ad01b137b3469eeea8d3e4 (diff) | |
| download | puppet-f98be4a7198326b26f1072c401b3e337f340db40.tar.gz puppet-f98be4a7198326b26f1072c401b3e337f340db40.tar.xz puppet-f98be4a7198326b26f1072c401b3e337f340db40.zip | |
Fixing #976 -- both the full name of qualified classes and
the class parts are now added as tags. I've also
created a Tagging module that we should push throughout
the rest of the system that uses tags.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/parser/resource.rb | 35 | ||||
| -rw-r--r-- | lib/puppet/transaction.rb | 2 | ||||
| -rw-r--r-- | lib/puppet/util/tagging.rb | 34 |
3 files changed, 45 insertions, 26 deletions
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index 3f346166e..7dc42ccec 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) @@ -86,6 +86,7 @@ class Puppet::Parser::Resource add_overrides() add_defaults() add_metaparams() + add_scope_tags() validate() end @@ -130,13 +131,8 @@ 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]+$/ - - if scope.resource - @tags += scope.resource.tags - end + tag(@ref.title) if valid_tag?(@ref.title.to_s) end # Merge an override resource in. This will throw exceptions if @@ -223,23 +219,6 @@ 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 - end - end - - def tags - @tags.dup - end - def to_hash @params.inject({}) do |hash, ary| param = ary[1] @@ -374,6 +353,12 @@ class Puppet::Parser::Resource end end + def add_scope_tags + if scope_resource = scope.resource + tag(*scope_resource.tags) + end + end + # Accept a parameter from an override. def override_parameter(param) # This can happen if the override is defining a new parameter, rather diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index 6a4981298..f304cadc6 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -424,7 +424,7 @@ class Transaction # Should we ignore tags? def ignore_tags? - ! @catalog.host_config? + ! (@catalog.host_config? or Puppet[:name] == "puppet") end # this should only be called by a Puppet::Type::Component resource now diff --git a/lib/puppet/util/tagging.rb b/lib/puppet/util/tagging.rb new file mode 100644 index 000000000..25d74c420 --- /dev/null +++ b/lib/puppet/util/tagging.rb @@ -0,0 +1,34 @@ +# Created on 2008-01-19 +# Copyright Luke Kanies + +# A common module to handle tagging. +module Puppet::Util::Tagging + # Add a tag to our current list. These tags will be added to all + # of the objects contained in this scope. + def tag(*ary) + @tags ||= [] + + qualified = [] + + ary.collect { |tag| tag.to_s.downcase }.each do |tag| + fail(Puppet::ParseError, "Invalid tag %s" % tag.inspect) unless valid_tag?(tag) + qualified << tag if tag.include?("::") + @tags << tag unless @tags.include?(tag) + end + + qualified.collect { |name| name.split("::") }.flatten.each { |tag| @tags << tag unless @tags.include?(tag) } + end + + # Return a copy of the tag list, so someone can't ask for our tags + # and then modify them. + def tags + @tags ||= [] + @tags.dup + end + + private + + def valid_tag?(tag) + tag =~ /^\w[-\w:]*$/ + end +end |
