Class: Puppet::Run

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

Overview

A basic class for running the agent. Used by ‘puppet kick` 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.



22
23
24
25
26
27
28
29
30
31
32
33
34
# 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

Instance Attribute Details

#backgroundObject (readonly)



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

def background
  @background
end

#optionsObject (readonly)



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

def options
  @options
end

#statusObject (readonly)



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

def status
  @status
end

Class Method Details

.from_data_hash(data) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
# 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) ⇒ Object



77
78
79
80
81
# File 'lib/puppet/run.rb', line 77

def self.from_hash(hash)
  obj = allocate
  obj.initialize_from_hash(hash)
  obj
end

.from_pson(hash) ⇒ Object



97
98
99
100
# 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

Instance Method Details

#agentObject



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

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

#background?Boolean

Returns:

  • (Boolean)


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

def background?
  background
end

#initialize_from_hash(hash) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# 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_runObject



47
48
49
50
51
52
53
54
55
56
# 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

#runObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# 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_hashObject



102
103
104
105
106
107
108
# File 'lib/puppet/run.rb', line 102

def to_data_hash
  {
    :options => @options,
    :background => @background,
    :status => @status
  }
end