Class: ForemanRhCloud::CloudPresence
  
  
  
  Instance Attribute Summary collapse
  
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  
  #execute_cloud_request
  
  
  
  
  
  
  
  
  
  
  #candlepin_id_cert, #cp_owner_id, #upstream_owner
  
  Constructor Details
  
    
  
  
    #initialize(organization, logger)  ⇒ CloudPresence 
  
  
  
  
    
Returns a new instance of CloudPresence.
   
 
  
  
    
      
8
9
10
11 
     | 
    
      # File 'app/services/foreman_rh_cloud/cloud_presence.rb', line 8
def initialize(organization, logger)
  @organization = organization
  @logger = logger
end 
     | 
  
 
  
 
  
    Instance Attribute Details
    
      
      
      
  
  
    #logger  ⇒ Object  
  
  
  
  
    
Returns the value of attribute logger.
   
 
  
  
    
      
6
7
8 
     | 
    
      # File 'app/services/foreman_rh_cloud/cloud_presence.rb', line 6
def logger
  @logger
end 
     | 
  
 
    
      
      
      
  
  
    #organization  ⇒ Object  
  
  
  
  
    
Returns the value of attribute organization.
   
 
  
  
    
      
6
7
8 
     | 
    
      # File 'app/services/foreman_rh_cloud/cloud_presence.rb', line 6
def organization
  @organization
end 
     | 
  
 
    
   
  
    Instance Method Details
    
      
  
  
    #announce_to_sources  ⇒ Object 
  
  
  
  
    
      
13
14
15 
     | 
    
      # File 'app/services/foreman_rh_cloud/cloud_presence.rb', line 13
def announce_to_sources
  register_rhc_instance
end 
     | 
  
 
    
      
  
  
    #create_satellite_instance_source  ⇒ Object 
  
  
  
  
    
      
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 
     | 
    
      # File 'app/services/foreman_rh_cloud/cloud_presence.rb', line 54
def create_satellite_instance_source
  create_response = JSON.parse(
    execute_cloud_request(
      method: :post,
      url: create_satellite_instance_source_url,
      headers: {
        content_type: :json,
      },
      ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
      ssl_client_key: OpenSSL::PKey.read(certs[:key]),
      payload: {
        name: "satellite: #{Foreman.instance_id} org: #{@organization.name}",
        source_ref: Foreman.instance_id,
        source_type_id: satellite_source_type,
      }.to_json
    )
  )
  @satellite_instance_source = create_response['id']
end
     | 
  
 
    
      
  
  
    #register_rhc_instance  ⇒ Object 
  
  
  
  
    
      
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 
     | 
    
      # File 'app/services/foreman_rh_cloud/cloud_presence.rb', line 75
def register_rhc_instance
  raise Foreman::Exception.new('rhc_instance_id is empty, cannot register RHC to the cloud') if Setting[:rhc_instance_id].empty?
  source_id = satellite_instance_source || create_satellite_instance_source
  create_response = JSON.parse(
    execute_cloud_request(
      method: :post,
      url: create_rhc_connections_url,
      headers: {
        content_type: :json,
      },
      ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
      ssl_client_key: OpenSSL::PKey.read(certs[:key]),
      payload: {
        source_id: source_id,
        rhc_id: Setting[:rhc_instance_id],
      }.to_json
    )
  )
  @satellite_instance_source = create_response['id']
end
     | 
  
 
    
      
  
  
    #satellite_instance_source  ⇒ Object 
  
  
  
  
    
      
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 
     | 
    
      # File 'app/services/foreman_rh_cloud/cloud_presence.rb', line 35
def satellite_instance_source
  @satellite_instance_source ||= begin
    source_response = JSON.parse(
      execute_cloud_request(
        method: :get,
        url: satellite_instance_source_url,
        headers: {
          content_type: :json,
        },
        ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
        ssl_client_key: OpenSSL::PKey.read(certs[:key])
      )
    )
    result = source_response['data'].first
    result&.dig('id')
  end
end
     | 
  
 
    
      
  
  
    #satellite_source_type  ⇒ Object 
  
  
  
  
    
      
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 
     | 
    
      # File 'app/services/foreman_rh_cloud/cloud_presence.rb', line 17
def satellite_source_type
  @satellite_source_type ||= begin
    source_type_response = JSON.parse(
      execute_cloud_request(
        method: :get,
        url: source_type_url,
        headers: {
          content_type: :json,
        },
        ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
        ssl_client_key: OpenSSL::PKey.read(certs[:key])
      )
    )
    source_type_response['data'].first['id']
  end
end
     |