Sha256: e85e19a5953574a8b3c4d140abc60fb09d5018e91de025ffb4c919e83f5e7d5a

Contents?: true

Size: 1.42 KB

Versions: 58

Compression:

Stored size: 1.42 KB

Contents

require 'puppet/agent'
require 'puppet/configurer'
require 'puppet/indirector'

# A basic class for running the agent.  Used by
# puppetrun to kick off agents remotely.
class Puppet::Run
  extend Puppet::Indirector
  indirects :run, :terminus_class => :local

  attr_reader :status, :background, :options

  def agent
    Puppet::Agent.new(Puppet::Configurer)
  end

  def background?
    background
  end

  def initialize(options = {})
    if options.include?(:background)
      @background = options[:background]
      options.delete(:background)
    end

    valid_options = [:tags, :ignoreschedules]
    options.each do |key, value|
      raise ArgumentError, "Run does not accept #{key}" unless valid_options.include?(key)
    end

    @options = options
  end

  def log_run
    msg = ""
    msg += "triggered run" % if options[:tags]
      msg += " with tags #{options[:tags].inspect}"
    end

    msg += " ignoring schedules" if options[:ignoreschedules]

    Puppet.notice msg
  end

  def run
    if agent.running?
      @status = "running"
      return self
    end

    log_run

    if background?
      Thread.new { agent.run(options) }
    else
      agent.run(options)
    end

    @status = "success"

    self
  end

  def self.from_pson( pson )
    options = {}
    pson.each do |key, value|
      options[key.to_sym] = value
    end

    new(options)
  end

  def to_pson
    @options.merge(:background => @background).to_pson
  end
end

Version data entries

58 entries across 58 versions & 4 rubygems

Version Path
puppet-parse-0.1.4 lib/vendor/puppet/run.rb
puppet-parse-0.1.3 lib/vendor/puppet/run.rb
puppet-parse-0.1.2 lib/vendor/puppet/run.rb
puppet-parse-0.1.1 lib/vendor/puppet/run.rb
puppet-parse-0.1.0 lib/vendor/puppet/run.rb
puppet-parse-0.0.6 lib/vendor/puppet/run.rb
puppet-2.7.21 lib/puppet/run.rb
puppet-2.6.18 lib/puppet/run.rb
puppet-parse-0.0.5 lib/vendor/puppet/run.rb
puppet-parse-0.0.4 lib/vendor/puppet/run.rb
puppet-parse-0.0.2 lib/vendor/puppet/run.rb
puppet-2.7.20 lib/puppet/run.rb
puppet-2.7.20.rc1 lib/puppet/run.rb
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/lib/puppet/run.rb
puppet-2.7.19 lib/puppet/run.rb
supply_drop-0.11.0 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/run.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/puppet-2.7.18/lib/puppet/run.rb
supply_drop-0.10.2 examples/vendored-puppet/vendor/puppet-2.7.8/lib/puppet/run.rb
puppet-2.7.18 lib/puppet/run.rb
puppet-2.6.17 lib/puppet/run.rb