foreman_rh_cloud 7.0.45 → 8.0.46

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: 8db662f6cd6809ba5dd5b183ec76330b4a1d4eb6db931136c8e34dcdf53c796c
4
+ data.tar.gz: e410219ca7fcbd0555d157f05123cc7c7618b29531157de42a3e3413d9d96eb4
5
5
  SHA512:
6
- metadata.gz: 9f4a974b345a78cfb4071f6648effb5715e7dcd44fe8e0a0dd2a634a03db788a8b7f819bd785974ad378c3b1a8cb01ee1c58a428753335d732da7b2e3192c9a6
7
- data.tar.gz: e3319409f79b9de5eb04fe8bfd07b0efa99d4065bf2a41ef78cfb7db8d210bdbdb0a030c1b3feb406d9ba41627343c5afe2a8f301f22467bfb7eb15fba3c454d
6
+ metadata.gz: 601501b2ec41be00150bbc9797ad9fe7c93a92aea619ca1781ef3df88224e3f6fb04b2c16e2c2e974832ef67926794108d3c8f2c7654d52056e25a218887cd55
7
+ data.tar.gz: 6a7ca4b57eb655c5d4c3a880f0deac4af3f86c6a4b71ddd4ff02b7adc4aa9bf5c0cb2a70731f5472ce763b841a75f755835e0674d489c6b5d51759ee9d1c85f3
@@ -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)
@@ -45,11 +45,9 @@ module ForemanInventoryUpload
45
45
  end
46
46
 
47
47
  def content_data
48
- [
49
- ['lifecycle_environment', @host.lifecycle_environment&.name],
50
- ['content_view', @host.content_view&.name],
51
- ] +
52
- (@host.activation_keys || []).map { |item| ['activation_key', item.name] }
48
+ (@host.lifecycle_environments.uniq || []).map { |item| ['lifecycle_environment', item.name] } +
49
+ (@host.activation_keys || []).map { |item| ['activation_key', item.name] } +
50
+ (@host.content_views || []).map { |item| ['content_view', item.name] }
53
51
  end
54
52
 
55
53
  def satellite_server_data
@@ -1,3 +1,3 @@
1
1
  module ForemanRhCloud
2
- VERSION = '7.0.45'.freeze
2
+ VERSION = '8.0.46'.freeze
3
3
  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