~ubuntu-branches/ubuntu/trusty/puppet/trusty

« back to all changes in this revision

Viewing changes to lib/puppet/resource/catalog.rb

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2011-10-22 14:08:22 UTC
  • mfrom: (1.1.25) (3.1.32 sid)
  • Revision ID: package-import@ubuntu.com-20111022140822-odxde5lohc45yhuz
Tags: 2.7.6-1
* New upstream release (CVE-2011-3872)
* Remove cherry-picked "groupadd_aix_warning" patch
* Install all new manpages

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
require 'puppet/simple_graph'
4
4
require 'puppet/transaction'
5
5
 
6
 
require 'puppet/util/cacher'
7
6
require 'puppet/util/pson'
8
7
 
9
8
require 'puppet/util/tagging'
20
19
 
21
20
  include Puppet::Util::Tagging
22
21
  extend Puppet::Util::Pson
23
 
  include Puppet::Util::Cacher::Expirer
24
22
 
25
23
  # The host name this is a catalog for.
26
24
  attr_accessor :name
94
92
    resource.ref =~ /^(.+)\[/
95
93
    class_name = $1 || resource.class.name
96
94
 
97
 
    newref = [class_name, key]
 
95
    newref = [class_name, key].flatten
98
96
 
99
97
    if key.is_a? String
100
98
      ref_string = "#{class_name}[#{key}]"
107
105
    # isn't sufficient.
108
106
    if existing = @resource_table[newref]
109
107
      return if existing == resource
110
 
      raise(ArgumentError, "Cannot alias #{resource.ref} to #{key.inspect}; resource #{newref.inspect} already exists")
 
108
      resource_definition = " at #{resource.file}:#{resource.line}" if resource.file and resource.line
 
109
      existing_definition = " at #{existing.file}:#{existing.line}" if existing.file and existing.line
 
110
      msg = "Cannot alias #{resource.ref} to #{key.inspect}#{resource_definition}; resource #{newref.inspect} already defined#{existing_definition}"
 
111
      raise ArgumentError, msg
111
112
    end
112
113
    @resource_table[newref] = resource
113
114
    @aliases[resource.ref] ||= []
123
124
  def apply(options = {})
124
125
    @applying = true
125
126
 
126
 
    # Expire all of the resource data -- this ensures that all
127
 
    # data we're operating against is entirely current.
128
 
    expire
129
 
 
130
127
    Puppet::Util::Storage.load if host_config?
131
 
    transaction = Puppet::Transaction.new(self)
132
 
 
133
 
    transaction.report = options[:report] if options[:report]
 
128
 
 
129
    transaction = Puppet::Transaction.new(self, options[:report])
 
130
    register_report = options[:report].nil?
 
131
 
134
132
    transaction.tags = options[:tags] if options[:tags]
135
133
    transaction.ignoreschedules = true if options[:ignoreschedules]
136
134
    transaction.for_network_device = options[:network_device]
138
136
    transaction.add_times :config_retrieval => self.retrieval_duration || 0
139
137
 
140
138
    begin
141
 
      transaction.evaluate
 
139
      Puppet::Util::Log.newdestination(transaction.report) if register_report
 
140
      begin
 
141
        transaction.evaluate
 
142
      ensure
 
143
        Puppet::Util::Log.close(transaction.report) if register_report
 
144
      end
142
145
    rescue Puppet::Error => detail
143
146
      puts detail.backtrace if Puppet[:trace]
144
147
      Puppet.err "Could not apply complete catalog: #{detail}"
156
159
    return transaction
157
160
  ensure
158
161
    @applying = false
159
 
    cleanup
160
162
  end
161
163
 
162
164
  # Are we in the middle of applying the catalog?
191
193
    resource
192
194
  end
193
195
 
194
 
  def dependent_data_expired?(ts)
195
 
    if applying?
196
 
      return super
197
 
    else
198
 
      return true
199
 
    end
200
 
  end
201
 
 
202
196
  # Turn our catalog graph into an old-style tree of TransObjects and TransBuckets.
203
197
  # LAK:NOTE(20081211): This is a  pre-0.25 backward compatibility method.
204
198
  # It can be removed as soon as xmlrpc is killed.
430
424
      res = Puppet::Resource.new(nil, type)
431
425
    end
432
426
    title_key      = [res.type, res.title.to_s]
433
 
    uniqueness_key = [res.type, res.uniqueness_key]
 
427
    uniqueness_key = [res.type, res.uniqueness_key].flatten
434
428
    @resource_table[title_key] || @resource_table[uniqueness_key]
435
429
  end
436
430
 
541
535
 
542
536
  # Store the classes in the classfile.
543
537
  def write_class_file
544
 
      ::File.open(Puppet[:classfile], "w") do |f|
545
 
        f.puts classes.join("\n")
546
 
      end
547
 
  rescue => detail
548
 
      Puppet.err "Could not create class file #{Puppet[:classfile]}: #{detail}"
 
538
    ::File.open(Puppet[:classfile], "w") do |f|
 
539
      f.puts classes.join("\n")
 
540
    end
 
541
  rescue => detail
 
542
    Puppet.err "Could not create class file #{Puppet[:classfile]}: #{detail}"
 
543
  end
 
544
 
 
545
  # Store the list of resources we manage
 
546
  def write_resource_file
 
547
    ::File.open(Puppet[:resourcefile], "w") do |f|
 
548
      to_print = resources.map do |resource|
 
549
        next unless resource.managed?
 
550
        "#{resource.type}[#{resource[resource.name_var]}]"
 
551
      end.compact
 
552
      f.puts to_print.join("\n")
 
553
    end
 
554
  rescue => detail
 
555
    Puppet.err "Could not create resource file #{Puppet[:resourcefile]}: #{detail}"
549
556
  end
550
557
 
551
558
  # Produce the graph files if requested.
558
565
 
559
566
  private
560
567
 
561
 
  def cleanup
562
 
    # Expire any cached data the resources are keeping.
563
 
    expire
564
 
  end
565
 
 
566
568
  # Verify that the given resource isn't defined elsewhere.
567
569
  def fail_on_duplicate_type_and_title(resource)
568
570
    # Short-curcuit the common case,