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
60 61 62 63 64 65 |
# File 'lib/runpuppet/agent.rb', line 60 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
67 68 69 70 71 |
# File 'lib/runpuppet/agent.rb', line 67 def append_params_to_url(url) url += (url.include?('?') ? '&' : '?') url += "hostname=#{config.hostname}&ip=#{config.local_ip}" url end |
#base_url(path) ⇒ Object
73 74 75 |
# File 'lib/runpuppet/agent.rb', line 73 def base_url(path) "#{config.puppet_controller_url.gsub(/\/$/, '')}/#{path.gsub(/^\//, '')}" end |
#check_status ⇒ Object
puppet
13 14 15 16 17 |
# File 'lib/runpuppet/agent.rb', line 13 def check_status action, branch = get("/puppet/run", @run_options).split('-') rescue [] branch ||= ([:branch] || config.default_branch) return action, branch end |
#get(path) ⇒ Object
base
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/runpuppet/agent.rb', line 39 def get(path) begin url = append_params_to_url(base_url(path)) puts "Getting #{url}" if [:verbose] result = RestClient.get(url) puts "got #{result}" if [:verbose] rescue Exception => e puts e.inspect puts "WARNING: error connecting in GET (PuppetMaster)" end end |
#post(path, params) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/runpuppet/agent.rb', line 51 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
31 32 33 34 35 |
# File 'lib/runpuppet/agent.rb', line 31 def report_facts require 'facter/application' facts = Facter::Application.run([]) post('/puppet/facts', :facts => facts.to_hash) end |
#report_failure ⇒ Object
27 28 29 |
# File 'lib/runpuppet/agent.rb', line 27 def report_failure get '/puppet/status?status=error' end |
#report_start ⇒ Object
19 20 21 |
# File 'lib/runpuppet/agent.rb', line 19 def report_start get '/puppet/status?status=started' end |
#report_success ⇒ Object
23 24 25 |
# File 'lib/runpuppet/agent.rb', line 23 def report_success get '/puppet/status?status=finished' end |