Puppet Function: cd4peadm::status_check
- Defined in:
- lib/puppet/functions/cd4peadm/status_check.rb
- Function type:
- Ruby 4.x API
Overview
database migrations to run until we move them into their own lifecycle event.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/puppet/functions/cd4peadm/status_check.rb', line 8 Puppet::Functions.create_function(:'cd4peadm::status_check') do # @param resolvable_hostname The resolvable hostname to check # @return boolean - true if the status api endpoint returns healthy, false if not dispatch :status_check do param 'String', :resolvable_hostname return_type 'Boolean' end def status_check(resolvable_hostname) uri = URI("https://#{resolvable_hostname}/status") max_attempts = 15 sleep_duration_secs = 5 call_function('out::message', "Checking connectivity from bolt runner to #{uri}") for i in 1..max_attempts do attempt = "Attempt #{i} of #{max_attempts}:" begin Net::HTTP.start(uri.host, uri.port, :use_ssl => true, :verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https| request = Net::HTTP::Get.new(uri) response = https.request(request) if response.kind_of?(Net::HTTPSuccess) if 'healthy' == response.body.downcase call_function('out::message', "#{attempt} Received healthy response, all services up and running.") return true else call_function('out::message', "#{attempt} Reached #{uri}, but did not receive healthy status response. Waiting another 5 seconds.") end else call_function('out::message', "#{attempt} Error Reaching #{uri}. Got http code #{response.code}. Waiting another 5 seconds and trying again.") end end rescue StandardError => e call_function('out::message', "#{attempt} Error Reaching #{uri}. #{e.}. Waiting another 5 seconds and trying again.") end sleep sleep_duration_secs end return false end end |