Sha256: 7b993d34321aca7b73a7ca3265b78e26b0e7ad057a352418323ceadbfb8542ef

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 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
    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 = { :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

5 entries across 5 versions & 1 rubygems

Version Path
puppet-3.0.0 lib/puppet/run.rb
puppet-3.0.0.rc8 lib/puppet/run.rb
puppet-3.0.0.rc7 lib/puppet/run.rb
puppet-3.0.0.rc5 lib/puppet/run.rb
puppet-3.0.0.rc4 lib/puppet/run.rb