playbooks/roles/jenkins/files/opt/lifecycle-poller/worker.rb
#------------------------------------------------------------------------------
# 
# FUNCTION: isAgentIdle
#
# DESCRIPTION: This method returns whether the given agent is idle 
#
#------------------------------------------------------------------------------
isAgentIdle
DESCRIPTION: This method returns whether the given agent is idle
isAgentIdle DESCRIPTION : This method returns whether the given agent is idle
def isAgentIdle(agent)
  url = URI.parse("http://localhost:8080/computer/#{agent}/api/xml")
  req = Net::HTTP::Get.new(url.to_s)
  req.basic_auth('admin', $conf['masterAdminPassword'])
  res = Net::HTTP.start(url.host, url.port) {|http|
    http.request(req)
  }
  if res.code == '200'
    if res.body.include? '<idle>true</idle>'
      return true
    elsif res.body.include? '<idle>false</idle>'
      return false
    else
      $log.error "unexpected body: #{res.body}"
      return false
    end
  elsif res.code == '404'
    return true
  else
    $log.error "unexpected response code: #{res.code}"
    return false
  end
end
def isAgentIdle ( agent ) url = URI . parse ( "http://localhost:8080/computer/#{agent}/api/xml" ) req = Net :: HTTP :: Get . new ( url . to_s ) req . basic_auth ( 'admin' , $conf [ 'masterAdminPassword' ] ) res = Net :: HTTP . start ( url . host , url . port ) { | http | http . request ( req ) } if res . code == '200' if res . body . include? '<idle>true</idle>' return true elsif res . body . include? '<idle>false</idle>' return false else $log . error "unexpected body: #{res.body}" return false end elsif res . code == '404' return true else $log . error "unexpected response code: #{res.code}" return false end end
FUNCTION: isAgentIdle
DESCRIPTION: This method returns whether the given agent is idle
FUNCTION : isAgentIdle DESCRIPTION : This method returns whether the given agent is idle
agent
<not_specific>