Class: Puppet::Run

Inherits:
Object show all
Extended by:
Indirector
Defined in:
lib/vendor/puppet/run.rb

Overview

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

Defined Under Namespace

Classes: Local, Rest

Constant Summary

Constants included from Indirector

Indirector::BadNameRegexp

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Indirector

configure_routes, indirects

Constructor Details

#initialize(options = {}) ⇒ Run

Returns a new instance of Run.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vendor/puppet/run.rb', line 21

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

Instance Attribute Details

#backgroundObject (readonly)

Returns the value of attribute background.



11
12
13
# File 'lib/vendor/puppet/run.rb', line 11

def background
  @background
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/vendor/puppet/run.rb', line 11

def options
  @options
end

#statusObject (readonly)

Returns the value of attribute status.



11
12
13
# File 'lib/vendor/puppet/run.rb', line 11

def status
  @status
end

Class Method Details

.from_pson(pson) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/vendor/puppet/run.rb', line 65

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

  new(options)
end

Instance Method Details

#agentObject



13
14
15
# File 'lib/vendor/puppet/run.rb', line 13

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

#background?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/vendor/puppet/run.rb', line 17

def background?
  background
end

#log_runObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/vendor/puppet/run.rb', line 35

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

#runObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/vendor/puppet/run.rb', line 46

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_psonObject



74
75
76
# File 'lib/vendor/puppet/run.rb', line 74

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