foreman_rh_cloud 7.0.45 → 7.0.47

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ccb21d6d17487bea0ab663a295419706f007207d62c41fc7e0fce30071fdbd0
4
- data.tar.gz: 7f45fd6cb0dfaca6ecd7d0a8a59488aebc91ef9a773056774c062da4623443d7
3
+ metadata.gz: c5493c69d3f1918da42b12dfc523e6bf387203e1d1cdd057d6bea1e401caeef6
4
+ data.tar.gz: 7413d1788622b27285da6a7257928b57b79bb6de8660ca9f966edcbb4cc7ee00
5
5
  SHA512:
6
- metadata.gz: 9f4a974b345a78cfb4071f6648effb5715e7dcd44fe8e0a0dd2a634a03db788a8b7f819bd785974ad378c3b1a8cb01ee1c58a428753335d732da7b2e3192c9a6
7
- data.tar.gz: e3319409f79b9de5eb04fe8bfd07b0efa99d4065bf2a41ef78cfb7db8d210bdbdb0a030c1b3feb406d9ba41627343c5afe2a8f301f22467bfb7eb15fba3c454d
6
+ metadata.gz: bf2220d31d2bc0b41291560ea0f25a8a88c33d73e281915ebe4534bf0a2fbd80be8f815776b38eade95366e92824179519decf91062f607a60c396e03a0387e2
7
+ data.tar.gz: 9d16b6f204bc3585e00b012e0fa47132ae4209fbaa85015c8db99ebce79aac167fa85374423366b2ff4ecd2cb725a20d7a5d52b61873f525b37ea7094e23fc7f
@@ -2,6 +2,6 @@
2
2
 
3
3
  class FixRhCloudSettingsCategoryToDsl < ActiveRecord::Migration[6.0]
4
4
  def up
5
- Setting.where(category: 'Setting::RhCloud').update_all(category: 'Setting')
5
+ Setting.where(category: 'Setting::RhCloud').update_all(category: 'Setting') if column_exists?(:settings, :category)
6
6
  end
7
7
  end
@@ -109,6 +109,18 @@ module ForemanInventoryUpload
109
109
  IPAddr.new(max_obfuscated + 1, Socket::AF_INET).to_s
110
110
  end
111
111
 
112
+ def hostname_match
113
+ bash_hostname = `uname -n`.chomp
114
+ foreman_hostname = ForemanRhCloud.foreman_host&.name
115
+ if bash_hostname == foreman_hostname
116
+ fqdn(foreman_hostname)
117
+ elsif Setting[:obfuscate_inventory_hostnames]
118
+ obfuscate_fqdn(bash_hostname)
119
+ else
120
+ bash_hostname
121
+ end
122
+ end
123
+
112
124
  def bios_uuid(host)
113
125
  value = fact_value(host, 'dmi::system::uuid') || ''
114
126
  uuid_value(value)
@@ -1,6 +1,7 @@
1
1
  module ForemanInventoryUpload
2
2
  module Generators
3
3
  class Metadata
4
+ include FactHelpers
4
5
  def initialize(output = [])
5
6
  @stream = JsonStream.new(output)
6
7
  end
@@ -28,6 +29,9 @@ module ForemanInventoryUpload
28
29
  @stream.simple_field('report_id', Foreman.uuid)
29
30
  @stream.simple_field('host_inventory_api_version', '1.0')
30
31
  @stream.simple_field('source', 'Satellite')
32
+ @stream.simple_field('reporting_host_name', hostname_match)
33
+ @stream.simple_field('reporting_host_ips', host_ips(ForemanRhCloud.foreman_host))
34
+ @stream.simple_field('reporting_host_bios_uuid', bios_uuid(ForemanRhCloud.foreman_host))
31
35
  @stream.simple_field('source_metadata', metadata)
32
36
  @stream.object_field('report_slices', :last) do
33
37
  yield(self)
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '7.0.45'.freeze
2
+ VERSION = '7.0.47'.freeze
3
3
  end
@@ -43,7 +43,17 @@ module InsightsCloud
43
43
  end
44
44
 
45
45
  def done?(current_status = invocation_status)
46
- job_invocation.finished? || current_status.map { |_host_id, task_status| task_status['report_done'] }.all?
46
+ ActiveModel::Type::Boolean.new.cast(current_status[:task_state][:task_done_reported])
47
+ end
48
+
49
+ def job_finished?
50
+ job_invocation.finished?
51
+ end
52
+
53
+ def all_hosts_finished?(current_status)
54
+ current_status[:hosts_state].values.all? do |status|
55
+ ActiveModel::Type::Boolean.new.cast(status['report_done'] == true)
56
+ end
47
57
  end
48
58
 
49
59
  # noop, we don't want to do anything when the polling task starts
@@ -95,7 +105,11 @@ module InsightsCloud
95
105
  end
96
106
 
97
107
  def host_status(host)
98
- external_task&.dig('invocation_status', host)
108
+ external_task&.dig('invocation_status', :hosts_state, host)
109
+ end
110
+
111
+ def task_done_state
112
+ ActiveModel::Type::Boolean.new.cast(external_task&.dig('invocation_status', :task_state, :task_done_reported))
99
113
  end
100
114
 
101
115
  def sequence(host)
@@ -111,13 +125,15 @@ module InsightsCloud
111
125
  end
112
126
 
113
127
  def invocation_status
114
- Hash[job_invocation.targeting.hosts.map do |host|
128
+ hosts_state = Hash[job_invocation.targeting.hosts.map do |host|
115
129
  next unless host.insights&.uuid
116
130
  [
117
131
  host.insights.uuid,
118
132
  task_status(job_invocation.sub_task_for_host(host), host.insights.uuid),
119
133
  ]
120
134
  end.compact]
135
+
136
+ {task_state: {task_done_reported: task_done_state}, hosts_state: hosts_state}
121
137
  end
122
138
 
123
139
  def task_status(host_task, host_name)
@@ -128,7 +144,7 @@ module InsightsCloud
128
144
  {
129
145
  'state' => host_task.state,
130
146
  'output' => host_task.main_action.live_output.map { |line| line['output'] }.join("\n"),
131
- 'exit_status' => host_task.main_action.exit_status,
147
+ 'exit_status' => ActiveModel::Type::Integer.new.cast(host_task.main_action.exit_status),
132
148
  'sequence' => sequence(host_name),
133
149
  'report_done' => host_done?(host_name),
134
150
  }
@@ -138,9 +154,9 @@ module InsightsCloud
138
154
  generator = InsightsCloud::Generators::PlaybookProgressGenerator.new(correlation_id)
139
155
  all_hosts_success = true
140
156
 
141
- invocation_status.each do |host_name, status|
157
+ invocation_status[:hosts_state].each do |host_name, status|
142
158
  # skip host if the host already reported that it's finished
143
- next if status['report_done']
159
+ next if ActiveModel::Type::Boolean.new.cast(status['report_done'])
144
160
 
145
161
  unless status['state'] == 'unknown'
146
162
  sequence = status['sequence']
@@ -154,7 +170,11 @@ module InsightsCloud
154
170
  all_hosts_success &&= status['exit_status'] == 0
155
171
  end
156
172
  end
157
- generator.job_finished_message(all_hosts_success) if done?(invocation_status)
173
+
174
+ if (job_finished? || all_hosts_finished?(invocation_status))
175
+ generator.job_finished_message(all_hosts_success)
176
+ invocation_status[:task_state][:task_done_reported] = true
177
+ end
158
178
 
159
179
  send_report(generator.generate)
160
180
  end
@@ -0,0 +1,63 @@
1
+ require 'io/console'
2
+
3
+ namespace :rh_cloud do |args|
4
+ desc 'Register Satellite Organization with Hybrid Cloud API. \
5
+ Specify org_id=x replace your organization ID with x. \
6
+ Specify SATELLITE_RH_CLOUD_URL=https://x with the Hybrid Cloud endpoint you are connecting to.'
7
+ task hybridcloud_register: [:environment] do
8
+ include ::ForemanRhCloud::CertAuth
9
+ include ::InsightsCloud::CandlepinCache
10
+
11
+ def logger
12
+ @logger ||= Logger.new(STDOUT)
13
+ end
14
+
15
+ def registrations_url
16
+ logger.warn("Custom url is not set, using the default one: #{ForemanRhCloud.base_url}") if ENV['SATELLITE_RH_CLOUD_URL'].empty?
17
+ ForemanRhCloud.base_url + '/api/identity/certificate/registrations'
18
+ end
19
+
20
+ if ENV['org_id'].nil?
21
+ logger.error('ERROR: org_id needs to be specified.')
22
+ exit(1)
23
+ end
24
+
25
+ organization = Organization.find_by(id: ENV['org_id'].to_i) # saw this coming in as a string, so making sure it gets passed as an integer.
26
+
27
+ @uid = cp_owner_id(organization)
28
+ logger.error('Organization provided does not have a manifest imported.') + exit(1) if @uid.nil?
29
+
30
+ puts 'Paste your token, output will be hidden.'
31
+ @token = STDIN.noecho(&:gets).chomp
32
+ logger.error('Token was not entered.') + exit(1) if @token.empty?
33
+
34
+ def headers
35
+ {
36
+ Authorization: "Bearer #{@token}"
37
+ }
38
+ end
39
+
40
+ def payload
41
+ {
42
+ "uid": @uid
43
+ }
44
+ end
45
+
46
+ def method
47
+ :post
48
+ end
49
+
50
+ begin
51
+ response = execute_cloud_request(
52
+ organization: organization,
53
+ method: method,
54
+ url: registrations_url,
55
+ headers: headers,
56
+ payload: payload.to_json
57
+ )
58
+ logger.debug(response)
59
+ rescue Exception => ex
60
+ logger.error(ex)
61
+ end
62
+ end
63
+ end