diff options
Diffstat (limited to 'lib/puppet/transaction')
-rw-r--r-- | lib/puppet/transaction/change.rb | 160 | ||||
-rw-r--r-- | lib/puppet/transaction/event.rb | 82 | ||||
-rw-r--r-- | lib/puppet/transaction/event_manager.rb | 160 | ||||
-rw-r--r-- | lib/puppet/transaction/report.rb | 230 | ||||
-rw-r--r-- | lib/puppet/transaction/resource_harness.rb | 240 |
5 files changed, 436 insertions, 436 deletions
diff --git a/lib/puppet/transaction/change.rb b/lib/puppet/transaction/change.rb index c8acec88b..ecc3b5a5f 100644 --- a/lib/puppet/transaction/change.rb +++ b/lib/puppet/transaction/change.rb @@ -4,84 +4,84 @@ require 'puppet/transaction/event' # Handle all of the work around performing an actual change, # including calling 'sync' on the properties and producing events. class Puppet::Transaction::Change - attr_accessor :is, :should, :property, :proxy, :auditing - - def auditing? - auditing - end - - # Create our event object. - def event - result = property.event - result.previous_value = is - result.desired_value = should - result - end - - def initialize(property, currentvalue) - @property = property - @is = currentvalue - - @should = property.should - - @changed = false - end - - def apply - return audit_event if auditing? - return noop_event if noop? - - property.sync - - result = event - result.message = property.change_to_s(is, should) - result.status = "success" - result.send_log - result - rescue => detail - puts detail.backtrace if Puppet[:trace] - result = event - result.status = "failure" - - result.message = "change from #{property.is_to_s(is)} to #{property.should_to_s(should)} failed: #{detail}" - result.send_log - result - end - - # Is our property noop? This is used for generating special events. - def noop? - @property.noop - end - - # The resource that generated this change. This is used for handling events, - # and the proxy resource is used for generated resources, since we can't - # send an event to a resource we don't have a direct relationship with. If we - # have a proxy resource, then the events will be considered to be from - # that resource, rather than us, so the graph resolution will still work. - def resource - self.proxy || @property.resource - end - - def to_s - "change #{@property.change_to_s(@is, @should)}" - end - - private - - def audit_event - # This needs to store the appropriate value, and then produce a new event - result = event - result.message = "audit change: previously recorded value #{property.should_to_s(should)} has been changed to #{property.is_to_s(is)}" - result.status = "audit" - result.send_log - result - end - - def noop_event - result = event - result.message = "is #{property.is_to_s(is)}, should be #{property.should_to_s(should)} (noop)" - result.status = "noop" - result.send_log - result - end + attr_accessor :is, :should, :property, :proxy, :auditing + + def auditing? + auditing + end + + # Create our event object. + def event + result = property.event + result.previous_value = is + result.desired_value = should + result + end + + def initialize(property, currentvalue) + @property = property + @is = currentvalue + + @should = property.should + + @changed = false + end + + def apply + return audit_event if auditing? + return noop_event if noop? + + property.sync + + result = event + result.message = property.change_to_s(is, should) + result.status = "success" + result.send_log + result + rescue => detail + puts detail.backtrace if Puppet[:trace] + result = event + result.status = "failure" + + result.message = "change from #{property.is_to_s(is)} to #{property.should_to_s(should)} failed: #{detail}" + result.send_log + result + end + + # Is our property noop? This is used for generating special events. + def noop? + @property.noop + end + + # The resource that generated this change. This is used for handling events, + # and the proxy resource is used for generated resources, since we can't + # send an event to a resource we don't have a direct relationship with. If we + # have a proxy resource, then the events will be considered to be from + # that resource, rather than us, so the graph resolution will still work. + def resource + self.proxy || @property.resource + end + + def to_s + "change #{@property.change_to_s(@is, @should)}" + end + + private + + def audit_event + # This needs to store the appropriate value, and then produce a new event + result = event + result.message = "audit change: previously recorded value #{property.should_to_s(should)} has been changed to #{property.is_to_s(is)}" + result.status = "audit" + result.send_log + result + end + + def noop_event + result = event + result.message = "is #{property.is_to_s(is)}, should be #{property.should_to_s(should)} (noop)" + result.status = "noop" + result.send_log + result + end end diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb index cb6c24edb..e5e5793da 100644 --- a/lib/puppet/transaction/event.rb +++ b/lib/puppet/transaction/event.rb @@ -4,58 +4,58 @@ require 'puppet/util/logging' # A simple struct for storing what happens on the system. class Puppet::Transaction::Event - include Puppet::Util::Tagging - include Puppet::Util::Logging + include Puppet::Util::Tagging + include Puppet::Util::Logging - ATTRIBUTES = [:name, :resource, :property, :previous_value, :desired_value, :status, :message, :node, :version, :file, :line, :source_description] - attr_accessor *ATTRIBUTES - attr_writer :tags - attr_accessor :time - attr_reader :default_log_level + ATTRIBUTES = [:name, :resource, :property, :previous_value, :desired_value, :status, :message, :node, :version, :file, :line, :source_description] + attr_accessor *ATTRIBUTES + attr_writer :tags + attr_accessor :time + attr_reader :default_log_level - EVENT_STATUSES = %w{noop success failure audit} + EVENT_STATUSES = %w{noop success failure audit} - def initialize(*args) - options = args.last.is_a?(Hash) ? args.pop : ATTRIBUTES.inject({}) { |hash, attr| hash[attr] = args.pop; hash } - options.each { |attr, value| send(attr.to_s + "=", value) unless value.nil? } + def initialize(*args) + options = args.last.is_a?(Hash) ? args.pop : ATTRIBUTES.inject({}) { |hash, attr| hash[attr] = args.pop; hash } + options.each { |attr, value| send(attr.to_s + "=", value) unless value.nil? } - @time = Time.now - end + @time = Time.now + end - def property=(prop) - @property = prop.to_s - end + def property=(prop) + @property = prop.to_s + end - def resource=(res) - if res.respond_to?(:[]) and level = res[:loglevel] - @default_log_level = level - end - @resource = res.to_s + def resource=(res) + if res.respond_to?(:[]) and level = res[:loglevel] + @default_log_level = level end + @resource = res.to_s + end - def send_log - super(log_level, message) - end + def send_log + super(log_level, message) + end - def status=(value) - raise ArgumentError, "Event status can only be #{EVENT_STATUSES.join(', ')}" unless EVENT_STATUSES.include?(value) - @status = value - end + def status=(value) + raise ArgumentError, "Event status can only be #{EVENT_STATUSES.join(', ')}" unless EVENT_STATUSES.include?(value) + @status = value + end - def to_s - message - end + def to_s + message + end - private + private - # If it's a failure, use 'err', else use either the resource's log level (if available) - # or 'notice'. - def log_level - status == "failure" ? :err : (@default_log_level || :notice) - end + # If it's a failure, use 'err', else use either the resource's log level (if available) + # or 'notice'. + def log_level + status == "failure" ? :err : (@default_log_level || :notice) + end - # Used by the Logging module - def log_source - source_description || property || resource - end + # Used by the Logging module + def log_source + source_description || property || resource + end end diff --git a/lib/puppet/transaction/event_manager.rb b/lib/puppet/transaction/event_manager.rb index 34a434248..3ebb0a9d3 100644 --- a/lib/puppet/transaction/event_manager.rb +++ b/lib/puppet/transaction/event_manager.rb @@ -1,99 +1,99 @@ require 'puppet/transaction' class Puppet::Transaction::EventManager - attr_reader :transaction, :events - - def initialize(transaction) - @transaction = transaction - @event_queues = {} - @events = [] - end - - def relationship_graph - transaction.relationship_graph + attr_reader :transaction, :events + + def initialize(transaction) + @transaction = transaction + @event_queues = {} + @events = [] + end + + def relationship_graph + transaction.relationship_graph + end + + # Respond to any queued events for this resource. + def process_events(resource) + restarted = false + queued_events(resource) do |callback, events| + r = process_callback(resource, callback, events) + restarted ||= r end - # Respond to any queued events for this resource. - def process_events(resource) - restarted = false - queued_events(resource) do |callback, events| - r = process_callback(resource, callback, events) - restarted ||= r - end - - if restarted - queue_events(resource, [resource.event(:name => :restarted, :status => "success")]) + if restarted + queue_events(resource, [resource.event(:name => :restarted, :status => "success")]) - transaction.resource_status(resource).restarted = true - end + transaction.resource_status(resource).restarted = true end - - # Queue events for other resources to respond to. All of these events have - # to be from the same resource. - def queue_events(resource, events) - @events += events - - # Do some basic normalization so we're not doing so many - # graph queries for large sets of events. - events.inject({}) do |collection, event| - collection[event.name] ||= [] - collection[event.name] << event - collection - end.collect do |name, list| - # It doesn't matter which event we use - they all have the same source - # and name here. - event = list[0] - - # Collect the targets of any subscriptions to those events. We pass - # the parent resource in so it will override the source in the events, - # since eval_generated children can't have direct relationships. - relationship_graph.matching_edges(event, resource).each do |edge| - next unless method = edge.callback - next unless edge.target.respond_to?(method) - - queue_events_for_resource(resource, edge.target, method, list) - end - - queue_events_for_resource(resource, resource, :refresh, [event]) if resource.self_refresh? and ! resource.deleting? - end + end + + # Queue events for other resources to respond to. All of these events have + # to be from the same resource. + def queue_events(resource, events) + @events += events + + # Do some basic normalization so we're not doing so many + # graph queries for large sets of events. + events.inject({}) do |collection, event| + collection[event.name] ||= [] + collection[event.name] << event + collection + end.collect do |name, list| + # It doesn't matter which event we use - they all have the same source + # and name here. + event = list[0] + + # Collect the targets of any subscriptions to those events. We pass + # the parent resource in so it will override the source in the events, + # since eval_generated children can't have direct relationships. + relationship_graph.matching_edges(event, resource).each do |edge| + next unless method = edge.callback + next unless edge.target.respond_to?(method) + + queue_events_for_resource(resource, edge.target, method, list) + end + + queue_events_for_resource(resource, resource, :refresh, [event]) if resource.self_refresh? and ! resource.deleting? end + end - def queue_events_for_resource(source, target, callback, events) - source.info "Scheduling #{callback} of #{target}" + def queue_events_for_resource(source, target, callback, events) + source.info "Scheduling #{callback} of #{target}" - @event_queues[target] ||= {} - @event_queues[target][callback] ||= [] - @event_queues[target][callback] += events - end + @event_queues[target] ||= {} + @event_queues[target][callback] ||= [] + @event_queues[target][callback] += events + end - def queued_events(resource) - return unless callbacks = @event_queues[resource] - callbacks.each do |callback, events| - yield callback, events - end + def queued_events(resource) + return unless callbacks = @event_queues[resource] + callbacks.each do |callback, events| + yield callback, events end + end - private + private - def process_callback(resource, callback, events) - process_noop_events(resource, callback, events) and return false unless events.detect { |e| e.status != "noop" } - resource.send(callback) + def process_callback(resource, callback, events) + process_noop_events(resource, callback, events) and return false unless events.detect { |e| e.status != "noop" } + resource.send(callback) - resource.notice "Triggered '#{callback}' from #{events.length} events" - return true - rescue => detail - resource.err "Failed to call #{callback}: #{detail}" + resource.notice "Triggered '#{callback}' from #{events.length} events" + return true + rescue => detail + resource.err "Failed to call #{callback}: #{detail}" - transaction.resource_status(resource).failed_to_restart = true - puts detail.backtrace if Puppet[:trace] - return false - end + transaction.resource_status(resource).failed_to_restart = true + puts detail.backtrace if Puppet[:trace] + return false + end - def process_noop_events(resource, callback, events) - resource.notice "Would have triggered '#{callback}' from #{events.length} events" + def process_noop_events(resource, callback, events) + resource.notice "Would have triggered '#{callback}' from #{events.length} events" - # And then add an event for it. - queue_events(resource, [resource.event(:status => "noop", :name => :noop_restart)]) - true # so the 'and if' works - end + # And then add an event for it. + queue_events(resource, [resource.event(:status => "noop", :name => :noop_restart)]) + true # so the 'and if' works + end end diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index 021c0200a..e6d1e0528 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -6,144 +6,144 @@ require 'puppet/indirector' # change produces, and Metrics are all of the numerical data involved # in the transaction. class Puppet::Transaction::Report - extend Puppet::Indirector + extend Puppet::Indirector - indirects :report, :terminus_class => :processor + indirects :report, :terminus_class => :processor - attr_reader :resource_statuses, :logs, :metrics, :host, :time + attr_reader :resource_statuses, :logs, :metrics, :host, :time - # This is necessary since Marshall doesn't know how to - # dump hash with default proc (see below @records) - def self.default_format - :yaml - end - - def <<(msg) - @logs << msg - self - end + # This is necessary since Marshall doesn't know how to + # dump hash with default proc (see below @records) + def self.default_format + :yaml + end - def add_times(name, value) - @external_times[name] = value - end + def <<(msg) + @logs << msg + self + end - def add_metric(name, hash) - metric = Puppet::Util::Metric.new(name) + def add_times(name, value) + @external_times[name] = value + end - hash.each do |name, value| - metric.newvalue(name, value) - end + def add_metric(name, hash) + metric = Puppet::Util::Metric.new(name) - @metrics[metric.name] = metric - metric + hash.each do |name, value| + metric.newvalue(name, value) end - def add_resource_status(status) - @resource_statuses[status.resource] = status + @metrics[metric.name] = metric + metric + end + + def add_resource_status(status) + @resource_statuses[status.resource] = status + end + + def calculate_metrics + calculate_resource_metrics + calculate_time_metrics + calculate_change_metrics + calculate_event_metrics + end + + def initialize + @metrics = {} + @logs = [] + @resource_statuses = {} + @external_times ||= {} + @host = Puppet[:certname] + @time = Time.now + end + + def name + host + end + + # Provide a summary of this report. + def summary + ret = "" + + @metrics.sort { |a,b| a[1].label <=> b[1].label }.each do |name, metric| + ret += "#{metric.label}:\n" + metric.values.sort { |a,b| + # sort by label + if a[0] == :total + 1 + elsif b[0] == :total + -1 + else + a[1] <=> b[1] + end + }.each do |name, label, value| + next if value == 0 + value = "%0.2f" % value if value.is_a?(Float) + ret += " %15s %s\n" % [label + ":", value] + end end - - def calculate_metrics - calculate_resource_metrics - calculate_time_metrics - calculate_change_metrics - calculate_event_metrics + ret + end + + # Based on the contents of this report's metrics, compute a single number + # that represents the report. The resulting number is a bitmask where + # individual bits represent the presence of different metrics. + def exit_status + status = 0 + status |= 2 if @metrics["changes"][:total] > 0 + status |= 4 if @metrics["resources"][:failed] > 0 + status + end + + private + + def calculate_change_metrics + metrics = Hash.new(0) + resource_statuses.each do |name, status| + metrics[:total] += status.change_count if status.change_count end - def initialize - @metrics = {} - @logs = [] - @resource_statuses = {} - @external_times ||= {} - @host = Puppet[:certname] - @time = Time.now - end + add_metric(:changes, metrics) + end - def name - host + def calculate_event_metrics + metrics = Hash.new(0) + resource_statuses.each do |name, status| + metrics[:total] += status.events.length + status.events.each do |event| + metrics[event.status] += 1 + end end - # Provide a summary of this report. - def summary - ret = "" - - @metrics.sort { |a,b| a[1].label <=> b[1].label }.each do |name, metric| - ret += "#{metric.label}:\n" - metric.values.sort { |a,b| - # sort by label - if a[0] == :total - 1 - elsif b[0] == :total - -1 - else - a[1] <=> b[1] - end - }.each do |name, label, value| - next if value == 0 - value = "%0.2f" % value if value.is_a?(Float) - ret += " %15s %s\n" % [label + ":", value] - end - end - ret - end + add_metric(:events, metrics) + end - # Based on the contents of this report's metrics, compute a single number - # that represents the report. The resulting number is a bitmask where - # individual bits represent the presence of different metrics. - def exit_status - status = 0 - status |= 2 if @metrics["changes"][:total] > 0 - status |= 4 if @metrics["resources"][:failed] > 0 - status - end + def calculate_resource_metrics + metrics = Hash.new(0) + metrics[:total] = resource_statuses.length - private + resource_statuses.each do |name, status| - def calculate_change_metrics - metrics = Hash.new(0) - resource_statuses.each do |name, status| - metrics[:total] += status.change_count if status.change_count - end - - add_metric(:changes, metrics) + Puppet::Resource::Status::STATES.each do |state| + metrics[state] += 1 if status.send(state) + end end - def calculate_event_metrics - metrics = Hash.new(0) - resource_statuses.each do |name, status| - metrics[:total] += status.events.length - status.events.each do |event| - metrics[event.status] += 1 - end - end + add_metric(:resources, metrics) + end - add_metric(:events, metrics) + def calculate_time_metrics + metrics = Hash.new(0) + resource_statuses.each do |name, status| + type = Puppet::Resource.new(name).type + metrics[type.to_s.downcase] += status.evaluation_time if status.evaluation_time end - def calculate_resource_metrics - metrics = Hash.new(0) - metrics[:total] = resource_statuses.length - - resource_statuses.each do |name, status| - - Puppet::Resource::Status::STATES.each do |state| - metrics[state] += 1 if status.send(state) - end - end - - add_metric(:resources, metrics) + @external_times.each do |name, value| + metrics[name.to_s.downcase] = value end - def calculate_time_metrics - metrics = Hash.new(0) - resource_statuses.each do |name, status| - type = Puppet::Resource.new(name).type - metrics[type.to_s.downcase] += status.evaluation_time if status.evaluation_time - end - - @external_times.each do |name, value| - metrics[name.to_s.downcase] = value - end - - add_metric(:time, metrics) - end + add_metric(:time, metrics) + end end diff --git a/lib/puppet/transaction/resource_harness.rb b/lib/puppet/transaction/resource_harness.rb index 5f90df5b9..aace6a38a 100644 --- a/lib/puppet/transaction/resource_harness.rb +++ b/lib/puppet/transaction/resource_harness.rb @@ -1,150 +1,150 @@ require 'puppet/resource/status' class Puppet::Transaction::ResourceHarness - extend Forwardable - def_delegators :@transaction, :relationship_graph + extend Forwardable + def_delegators :@transaction, :relationship_graph - attr_reader :transaction + attr_reader :transaction - def allow_changes?(resource) - return true unless resource.purging? and resource.deleting? - return true unless deps = relationship_graph.dependents(resource) and ! deps.empty? and deps.detect { |d| ! d.deleting? } + def allow_changes?(resource) + return true unless resource.purging? and resource.deleting? + return true unless deps = relationship_graph.dependents(resource) and ! deps.empty? and deps.detect { |d| ! d.deleting? } - deplabel = deps.collect { |r| r.ref }.join(",") - plurality = deps.length > 1 ? "":"s" - resource.warning "#{deplabel} still depend#{plurality} on me -- not purging" - false - end - - def apply_changes(status, changes) - changes.each do |change| - status << change.apply + deplabel = deps.collect { |r| r.ref }.join(",") + plurality = deps.length > 1 ? "":"s" + resource.warning "#{deplabel} still depend#{plurality} on me -- not purging" + false + end - cache(change.property.resource, change.property.name, change.is) if change.auditing? - end - status.changed = true - end + def apply_changes(status, changes) + changes.each do |change| + status << change.apply - # Used mostly for scheduling at this point. - def cached(resource, name) - Puppet::Util::Storage.cache(resource)[name] + cache(change.property.resource, change.property.name, change.is) if change.auditing? end + status.changed = true + end - # Used mostly for scheduling at this point. - def cache(resource, name, value) - Puppet::Util::Storage.cache(resource)[name] = value - end + # Used mostly for scheduling at this point. + def cached(resource, name) + Puppet::Util::Storage.cache(resource)[name] + end - def changes_to_perform(status, resource) - current = resource.retrieve_resource + # Used mostly for scheduling at this point. + def cache(resource, name, value) + Puppet::Util::Storage.cache(resource)[name] = value + end - cache resource, :checked, Time.now + def changes_to_perform(status, resource) + current = resource.retrieve_resource - return [] if ! allow_changes?(resource) + cache resource, :checked, Time.now - audited = copy_audited_parameters(resource, current) + return [] if ! allow_changes?(resource) - if param = resource.parameter(:ensure) - return [] if absent_and_not_being_created?(current, param) - return [Puppet::Transaction::Change.new(param, current[:ensure])] unless ensure_is_insync?(current, param) - return [] if ensure_should_be_absent?(current, param) - end + audited = copy_audited_parameters(resource, current) - resource.properties.reject { |p| p.name == :ensure }.reject do |param| - param.should.nil? - end.reject do |param| - param_is_insync?(current, param) - end.collect do |param| - change = Puppet::Transaction::Change.new(param, current[param.name]) - change.auditing = true if audited.include?(param.name) - change - end + if param = resource.parameter(:ensure) + return [] if absent_and_not_being_created?(current, param) + return [Puppet::Transaction::Change.new(param, current[:ensure])] unless ensure_is_insync?(current, param) + return [] if ensure_should_be_absent?(current, param) end - def copy_audited_parameters(resource, current) - return [] unless audit = resource[:audit] - audit = Array(audit).collect { |p| p.to_sym } - audited = [] - audit.find_all do |param| - next if resource[param] - - if value = cached(resource, param) - resource[param] = value - audited << param - else - resource.info "Storing newly-audited value #{current[param]} for #{param}" - cache(resource, param, current[param]) - end - end - - audited + resource.properties.reject { |p| p.name == :ensure }.reject do |param| + param.should.nil? + end.reject do |param| + param_is_insync?(current, param) + end.collect do |param| + change = Puppet::Transaction::Change.new(param, current[param.name]) + change.auditing = true if audited.include?(param.name) + change end - - def evaluate(resource) - start = Time.now - status = Puppet::Resource::Status.new(resource) - - if changes = changes_to_perform(status, resource) and ! changes.empty? - status.out_of_sync = true - status.change_count = changes.length - apply_changes(status, changes) - if ! resource.noop? - cache(resource, :synced, Time.now) - resource.flush if resource.respond_to?(:flush) - end - end - return status - rescue => detail - resource.fail "Could not create resource status: #{detail}" unless status - puts detail.backtrace if Puppet[:trace] - resource.err "Could not evaluate: #{detail}" - status.failed = true - return status - ensure - (status.evaluation_time = Time.now - start) if status + end + + def copy_audited_parameters(resource, current) + return [] unless audit = resource[:audit] + audit = Array(audit).collect { |p| p.to_sym } + audited = [] + audit.find_all do |param| + next if resource[param] + + if value = cached(resource, param) + resource[param] = value + audited << param + else + resource.info "Storing newly-audited value #{current[param]} for #{param}" + cache(resource, param, current[param]) + end end - def initialize(transaction) - @transaction = transaction + audited + end + + def evaluate(resource) + start = Time.now + status = Puppet::Resource::Status.new(resource) + + if changes = changes_to_perform(status, resource) and ! changes.empty? + status.out_of_sync = true + status.change_count = changes.length + apply_changes(status, changes) + if ! resource.noop? + cache(resource, :synced, Time.now) + resource.flush if resource.respond_to?(:flush) + end end - - def scheduled?(status, resource) - return true if Puppet[:ignoreschedules] - return true unless schedule = schedule(resource) - - # We use 'checked' here instead of 'synced' because otherwise we'll - # end up checking most resources most times, because they will generally - # have been synced a long time ago (e.g., a file only gets updated - # once a month on the server and its schedule is daily; the last sync time - # will have been a month ago, so we'd end up checking every run). - schedule.match?(cached(resource, :checked).to_i) + return status + rescue => detail + resource.fail "Could not create resource status: #{detail}" unless status + puts detail.backtrace if Puppet[:trace] + resource.err "Could not evaluate: #{detail}" + status.failed = true + return status + ensure + (status.evaluation_time = Time.now - start) if status + end + + def initialize(transaction) + @transaction = transaction + end + + def scheduled?(status, resource) + return true if Puppet[:ignoreschedules] + return true unless schedule = schedule(resource) + + # We use 'checked' here instead of 'synced' because otherwise we'll + # end up checking most resources most times, because they will generally + # have been synced a long time ago (e.g., a file only gets updated + # once a month on the server and its schedule is daily; the last sync time + # will have been a month ago, so we'd end up checking every run). + schedule.match?(cached(resource, :checked).to_i) + end + + def schedule(resource) + unless resource.catalog + resource.warning "Cannot schedule without a schedule-containing catalog" + return nil end - def schedule(resource) - unless resource.catalog - resource.warning "Cannot schedule without a schedule-containing catalog" - return nil - end + return nil unless name = resource[:schedule] + resource.catalog.resource(:schedule, name) || resource.fail("Could not find schedule #{name}") + end - return nil unless name = resource[:schedule] - resource.catalog.resource(:schedule, name) || resource.fail("Could not find schedule #{name}") - end - - private + private - def absent_and_not_being_created?(current, param) - current[:ensure] == :absent and param.should.nil? - end + def absent_and_not_being_created?(current, param) + current[:ensure] == :absent and param.should.nil? + end - def ensure_is_insync?(current, param) - param.insync?(current[:ensure]) - end + def ensure_is_insync?(current, param) + param.insync?(current[:ensure]) + end - def ensure_should_be_absent?(current, param) - param.should == :absent - end + def ensure_should_be_absent?(current, param) + param.should == :absent + end - def param_is_insync?(current, param) - param.insync?(current[param.name]) - end + def param_is_insync?(current, param) + param.insync?(current[param.name]) + end end |