diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-03-11 22:18:59 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-03-11 22:18:59 +0000 |
commit | fa9aab6749bcb76004b567e228c5af8f7a4bfee8 (patch) | |
tree | 15aa928fd00bcdec80ccb88642f93139e794d9d5 /lib/puppet | |
parent | 414d364a6f337cc8e542dc107d8e51f625375db4 (diff) | |
download | puppet-fa9aab6749bcb76004b567e228c5af8f7a4bfee8.tar.gz puppet-fa9aab6749bcb76004b567e228c5af8f7a4bfee8.tar.xz puppet-fa9aab6749bcb76004b567e228c5af8f7a4bfee8.zip |
Fixing #82. You can now specify comma-separated tags to get run in puppet or puppetd: puppetd --onetime --tags "enhost, facter" -v. You cannot specify classes explicitly, but tags map well to classes and have the benefit of being more generic.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1005 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/config.rb | 2 | ||||
-rw-r--r-- | lib/puppet/transaction.rb | 19 | ||||
-rw-r--r-- | lib/puppet/type.rb | 33 |
3 files changed, 51 insertions, 3 deletions
diff --git a/lib/puppet/config.rb b/lib/puppet/config.rb index b0aa93839..ff1494ea8 100644 --- a/lib/puppet/config.rb +++ b/lib/puppet/config.rb @@ -263,7 +263,7 @@ class Config when String, Integer, Float: # nothing klass = CElement else - raise Puppet::Error, "Invalid value '%s' for %s" % [value, hash[:name]] + raise Puppet::Error, "Invalid value '%s' for %s" % [value.inspect, hash[:name]] end element = klass.new(hash) element.parent = self diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index 182401cb5..d9bea92ba 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -8,6 +8,13 @@ module Puppet class Transaction attr_accessor :toplevel, :component, :objects + + Puppet.config.setdefaults(:transaction, + :tags => ["", "Tags to use to find objects. If this is set, then + only objects tagged with the specified tags will be applied. Values must + be comma-separated."] + ) + # a bit of a gross hack; a global list of objects that have failed to sync, # so that we can verify during later syncs that our dependencies haven't # failed @@ -35,7 +42,19 @@ class Transaction count = 0 now = Time.now + tags = Puppet[:tags] + if tags == "" + tags = nil + else + tags = tags.split(/\s*,\s*/) + end events = @objects.find_all { |child| + if tags + child.tagged?(tags) + else + true # match everything when there are no tags + end + }.find_all { |child| child.scheduled? }.collect { |child| # these children are all Puppet::Type instances diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 1d2eea54c..eec397670 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -19,7 +19,8 @@ class Type < Puppet::Element # that it is clear whether it operates on all attributes (thus has 'attr' in # the method name, or whether it operates on a specific type of attributes. attr_accessor :children, :parent - attr_accessor :file, :line, :tags + attr_accessor :file, :line + attr_reader :tags attr_writer :implicit def implicit? @@ -1466,8 +1467,36 @@ class Type < Puppet::Element return schedule.match?(self.cached(:checked).to_i) end + # Add a new tag. def tag(tag) - @tags << tag + tag = tag.intern if tag.is_a? String + unless @tags.include? tag + @tags << tag + end + end + + # Define the initial list of tags. + def tags=(list) + list = [list] unless list.is_a? Array + + @tags = list.collect do |t| + case t + when String: t.intern + when Symbol: t + else + self.warning "Ignoring tag %s of type %s" % [tag.inspect, tag.class] + end + end + end + + # Figure out of any of the specified tags apply to this object. This is an + # OR operation. + def tagged?(tags) + tags = [tags] unless tags.is_a? Array + + tags = tags.collect { |t| t.intern } + + return tags.find { |tag| @tags.include? tag } end # Is the specified parameter set? |