Class: ForemanInventoryUpload::Async::RemoveInsightsHostsJob
  
  
  
  
  
    - Inherits:
 
    - 
      Actions::EntryAction
      
        
          - Object
 
          
            - Actions::EntryAction
 
          
            - ForemanInventoryUpload::Async::RemoveInsightsHostsJob
 
          
        
        show all
      
     
  
  
  
  
  
  
  
      - Includes:
 
      - ForemanRhCloud::CertAuth
 
  
  
  
  
  
  
    - Defined in:
 
    - lib/foreman_inventory_upload/async/remove_insights_hosts_job.rb
 
  
  
 
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  
  #cert_auth_available?, #execute_cloud_request
  
  
  
  
  
  
  
  
  
  
  #candlepin_id_cert, #cp_owner_id, #upstream_owner
  
  
  
  
  
  
  
  
  
  
  #execute_cloud_request
  
  
  
    Instance Method Details
    
      
  
  
    #delete_page(host_uuids, organization)  ⇒ Object 
  
  
  
  
    
      
45
46
47
48
49
50
51
52
53
54
55
56 
     | 
    
      # File 'lib/foreman_inventory_upload/async/remove_insights_hosts_job.rb', line 45
def delete_page(host_uuids, organization)
  execute_cloud_request(
    organization: organization,
    method: :delete,
    url: ForemanInventoryUpload.hosts_by_ids_url(host_uuids),
    headers: {
      content_type: :json,
    }
  )
rescue RestClient::ExceptionWithResponse => error_response
  error_response.response
end
     | 
  
 
    
      
  
  
    #logger  ⇒ Object 
  
  
  
  
    
      
33
34
35 
     | 
    
      # File 'lib/foreman_inventory_upload/async/remove_insights_hosts_job.rb', line 33
def logger
  Foreman::Logging.logger('background')
end
     | 
  
 
    
      
  
  
    #organization  ⇒ Object 
  
  
  
  
    
      
41
42
43 
     | 
    
      # File 'lib/foreman_inventory_upload/async/remove_insights_hosts_job.rb', line 41
def organization
  @organization ||= Organization.find_by(id: input[:organization_id])
end 
     | 
  
 
    
      
  
  
    #page_size  ⇒ Object 
  
  
  
  
    
      
62
63
64
65 
     | 
    
      # File 'lib/foreman_inventory_upload/async/remove_insights_hosts_job.rb', line 62
def page_size
    40
end
     | 
  
 
    
      
  
  
    #plan(search_term, organization_id)  ⇒ Object 
  
  
  
  
    
      
6
7
8 
     | 
    
      # File 'lib/foreman_inventory_upload/async/remove_insights_hosts_job.rb', line 6
def plan(search_term, organization_id)
  plan_self(search_term: search_term, organization_id: organization_id)
end 
     | 
  
 
    
      
  
  
    #remove_host_records(uuids)  ⇒ Object 
  
  
  
  
    
      
58
59
60 
     | 
    
      # File 'lib/foreman_inventory_upload/async/remove_insights_hosts_job.rb', line 58
def remove_host_records(uuids)
  InsightsMissingHost.where(insights_id: uuids).delete_all
end 
     | 
  
 
    
      
  
  
    #run  ⇒ Object 
  
  
  
  
    
      
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 
     | 
    
      # File 'lib/foreman_inventory_upload/async/remove_insights_hosts_job.rb', line 10
def run
  logger.debug("Attempting to remove hosts by search term: #{search_term}")
  host_uuids = InsightsMissingHost.search_for(search_term).pluck(:insights_id)
  page_number = 1
  while (current_page = host_uuids.paginate(page: page_number, per_page: page_size)).present?
    logger.debug("Removing #{(page_number - 1) * page_size} - #{page_number * page_size}/#{current_page.total_entries} hosts: #{current_page.join(',')}")
    response = delete_page(current_page, organization)
        output["response_page#{page_number}"] = response.body
        if response.code >= 200 && response.code < 300
      remove_host_records(current_page)
    else
      error! "Cloud responded with code: #{response.code}"
    end
    page_number += 1
  end
end
     | 
  
 
    
      
  
  
    #search_term  ⇒ Object 
  
  
  
  
    
      
37
38
39 
     | 
    
      # File 'lib/foreman_inventory_upload/async/remove_insights_hosts_job.rb', line 37
def search_term
  input[:search_term]
end 
     |