lib/puppet_x/xebialabs/xldeploy/ci.rb
# this method runs a discovery on a ci
this method runs a discovery on a ci
this method runs a discovery on a ci
def run_discovery(discovery_max_wait = '120')
    inspection = rest_post "inspection/prepare/", desired_xml
    task_id = rest_post "inspection/", inspection
    rest_post "task/#{task_id}/start"
    max_wait = discovery_max_wait.to_i
    while max_wait > 0
      state = get_task_state(task_id)
      case state
        when 'EXECUTED'
          break
        when 'STOPPED', 'DONE', 'CANCELLED'
          fail "Discovery of #{id} failed, invalid inspection task #{task_id} state #{state}"
        when 'EXECUTING', 'PENDING', 'QUEUED'
          p "Waiting for discovery to finish, task: #{task_id}, current state: #{state}, wait time left: #{max_wait}"
      end
      max_wait = max_wait - 1
      sleep 1
    end
    if max_wait == 0
      fail "Discovery of #{:id} failed, max wait time #{discovery_max_wait} exceeded"
    end
    rest_post "task/#{task_id}/archive"
    inspection_result = rest_get "inspection/retrieve/#{task_id}"
    if inspection_result != "No resource method found for GET, return 405 with Allow header"
      rest_post "repository/cis", inspection_result
    end
  end
def run_discovery ( discovery_max_wait = '120' ) inspection = rest_post "inspection/prepare/" , desired_xml task_id = rest_post "inspection/" , inspection rest_post "task/#{task_id}/start" max_wait = discovery_max_wait . to_i while max_wait > 0 state = get_task_state ( task_id ) case state when 'EXECUTED' break when 'STOPPED' , 'DONE' , 'CANCELLED' fail "Discovery of #{id} failed, invalid inspection task #{task_id} state #{state}" when 'EXECUTING' , 'PENDING' , 'QUEUED' p "Waiting for discovery to finish, task: #{task_id}, current state: #{state}, wait time left: #{max_wait}" end max_wait = max_wait - 1 sleep 1 end if max_wait == 0 fail "Discovery of #{:id} failed, max wait time #{discovery_max_wait} exceeded" end rest_post "task/#{task_id}/archive" inspection_result = rest_get "inspection/retrieve/#{task_id}" if inspection_result != "No resource method found for GET, return 405 with Allow header" rest_post "repository/cis" , inspection_result end end
this method runs a discovery on a ci
this method runs a discovery on a ci
discovery_max_wait
<not_specific>