Class: Puppet::Run
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/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
#background ⇒ Object
Returns the value of attribute background.
11
12
13
|
# File 'lib/puppet/run.rb', line 11
def background
@background
end
|
Returns the value of attribute options.
11
12
13
|
# File 'lib/puppet/run.rb', line 11
def options
@options
end
|
Returns the value of attribute status.
11
12
13
|
# File 'lib/puppet/run.rb', line 11
def status
@status
end
|
Class Method Details
.from_hash(hash) ⇒ Object
76
77
78
79
80
|
# File 'lib/puppet/run.rb', line 76
def self.from_hash(hash)
obj = allocate
obj.initialize_from_hash(hash)
obj
end
|
.from_pson(hash) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/puppet/run.rb', line 82
def self.from_pson(hash)
if hash['options']
return from_hash(hash)
end
options = {}
hash.each do |key, value|
options[key.to_sym] = value
end
new(options)
end
|
Instance Method Details
13
14
15
|
# File 'lib/puppet/run.rb', line 13
def agent
Puppet::Agent.new(Puppet::Configurer)
end
|
#background? ⇒ Boolean
17
18
19
|
# File 'lib/puppet/run.rb', line 17
def background?
background
end
|
#initialize_from_hash(hash) ⇒ Object
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/puppet/run.rb', line 35
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
|
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/puppet/run.rb', line 46
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
|
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/puppet/run.rb', line 57
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
|
96
97
98
|
# File 'lib/puppet/run.rb', line 96
def to_pson
@options.merge(:background => @background).to_pson
end
|