Class: Runpuppet::Agent
- Inherits:
-
Object
- Object
- Runpuppet::Agent
- Defined in:
- lib/runpuppet/agent.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#run_options ⇒ Object
Returns the value of attribute run_options.
Instance Method Summary collapse
- #append_params_to_post(params) ⇒ Object
- #append_params_to_url(url) ⇒ Object
- #base_url(path) ⇒ Object
-
#check_status ⇒ Object
puppet.
-
#get(path) ⇒ Object
base.
-
#initialize(context) ⇒ Agent
constructor
A new instance of Agent.
- #post(path, params) ⇒ Object
- #report_facts ⇒ Object
- #report_failure ⇒ Object
- #report_start ⇒ Object
- #report_success ⇒ Object
Constructor Details
#initialize(context) ⇒ Agent
Returns a new instance of Agent.
6 7 8 9 |
# File 'lib/runpuppet/agent.rb', line 6 def initialize(context) @config = context.config @run_options = context. end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
4 5 6 |
# File 'lib/runpuppet/agent.rb', line 4 def config @config end |
#run_options ⇒ Object
Returns the value of attribute run_options.
5 6 7 |
# File 'lib/runpuppet/agent.rb', line 5 def @run_options end |
Instance Method Details
#append_params_to_post(params) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/runpuppet/agent.rb', line 68 def append_params_to_post(params) params = params.dup params[:hostname] = config.hostname params[:ip] = config.local_ip return params end |
#append_params_to_url(url) ⇒ Object
75 76 77 78 79 |
# File 'lib/runpuppet/agent.rb', line 75 def append_params_to_url(url) url += (url.include?('?') ? '&' : '?') url += "hostname=#{config.hostname}&ip=#{config.local_ip}" url end |
#base_url(path) ⇒ Object
81 82 83 |
# File 'lib/runpuppet/agent.rb', line 81 def base_url(path) "#{config.puppet_controller_url.gsub(/\/$/, '')}/#{path.gsub(/^\//, '')}" end |
#check_status ⇒ Object
puppet
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/runpuppet/agent.rb', line 13 def check_status begin r = get("/puppet/run") rescue Exception => e end if r return (action, branch = *r.split('-')) else return nil end end |
#get(path) ⇒ Object
base
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/runpuppet/agent.rb', line 46 def get(path) begin url = append_params_to_url(base_url(path)) puts "Getting #{url}" if [:debug] result = RestClient.get(url) puts "got #{result}" if [:debug] return result rescue Exception => e puts e.inspect puts "WARNING: error connecting in GET (PuppetMaster)" end end |
#post(path, params) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/runpuppet/agent.rb', line 59 def post(path, params) begin RestClient.post base_url(path), append_params_to_post(params) rescue Exception => e puts e.inspect puts "WARNING: error connecting in POST (PuppetMaster)" end end |
#report_facts ⇒ Object
38 39 40 41 42 |
# File 'lib/runpuppet/agent.rb', line 38 def report_facts require 'facter/application' facts = Facter::Application.run([]) post('/puppet/facts', :facts => facts.to_hash) end |
#report_failure ⇒ Object
34 35 36 |
# File 'lib/runpuppet/agent.rb', line 34 def report_failure get '/puppet/status?status=error' end |
#report_start ⇒ Object
26 27 28 |
# File 'lib/runpuppet/agent.rb', line 26 def report_start get '/puppet/status?status=started' end |
#report_success ⇒ Object
30 31 32 |
# File 'lib/runpuppet/agent.rb', line 30 def report_success get '/puppet/status?status=finished' end |