Sha256: df975a69bfda8273d9b8a29fce8553e26dc6c56c4de0082e3e3221c03144453c

Contents?: true

Size: 1.53 KB

Versions: 14

Compression:

Stored size: 1.53 KB

Contents

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

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

  attr_reader :status, :background, :options

  def agent
    # Forking disabled for "puppet kick" runs
    Puppet::Agent.new(Puppet::Configurer, false)
  end

  def background?
    background
  end

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

    valid_options = [:tags, :ignoreschedules, :pluginsync]
    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 = { :pluginsync => Puppet[:pluginsync] }
    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

14 entries across 14 versions & 2 rubygems

Version Path
puppet-3.2.1 lib/puppet/run.rb
puppet-3.2.1.rc1 lib/puppet/run.rb
puppet-3.2.0.rc2 lib/puppet/run.rb
librarian-puppet-0.9.9 vendor/gems/ruby/1.9.1/gems/puppet-3.1.0/lib/puppet/run.rb
puppet-3.2.0.rc1 lib/puppet/run.rb
puppet-3.1.1 lib/puppet/run.rb
librarian-puppet-0.9.8 vendor/gems/ruby/1.9.1/gems/puppet-3.1.0/lib/puppet/run.rb
puppet-3.1.0 lib/puppet/run.rb
puppet-3.1.0.rc2 lib/puppet/run.rb
puppet-3.1.0.rc1 lib/puppet/run.rb
puppet-3.0.2 lib/puppet/run.rb
puppet-3.0.2.rc3 lib/puppet/run.rb
puppet-3.0.2.rc2 lib/puppet/run.rb
puppet-3.0.2.rc1 lib/puppet/run.rb