class Puppet::Run

A basic class for running the agent. Used by `puppet kick` to kick off agents remotely.

Attributes

background[R]
options[R]
status[R]

Public Instance Methods

agent() click to toggle source
# File lib/puppet/run.rb, line 13
def agent
  # Forking disabled for "puppet kick" runs
  Puppet::Agent.new(Puppet::Configurer, false)
end
background?() click to toggle source
# File lib/puppet/run.rb, line 18
def background?
  background
end
initialize_from_hash(hash) click to toggle source
# File lib/puppet/run.rb, line 36
def initialize_from_hash(hash)
  @options = {}

  hash['options'].each do |key, value|
    @options[key.to_sym] = value
  end

  @background = hash['background']
  @status = hash['status']
end
log_run() click to toggle source
# File lib/puppet/run.rb, line 47
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
run() click to toggle source
# File lib/puppet/run.rb, line 58
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
to_data_hash() click to toggle source
# File lib/puppet/run.rb, line 102
def to_data_hash
  {
    :options => @options,
    :background => @background,
    :status => @status
  }
end

Public Class Methods

from_data_hash(data) click to toggle source
# File lib/puppet/run.rb, line 83
def self.from_data_hash(data)
  if data['options']
    return from_hash(data)
  end

  options = { :pluginsync => Puppet[:pluginsync] }

  data.each do |key, value|
    options[key.to_sym] = value
  end

  new(options)
end
from_hash(hash) click to toggle source
# File lib/puppet/run.rb, line 77
def self.from_hash(hash)
  obj = allocate
  obj.initialize_from_hash(hash)
  obj
end
from_pson(hash) click to toggle source
# File lib/puppet/run.rb, line 97
def self.from_pson(hash)
  Puppet.deprecation_warning("from_pson is being removed in favour of from_data_hash.")
  self.from_data_hash(hash)
end
new(options = {}) click to toggle source
# File lib/puppet/run.rb, line 22
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