Class: Katello::Host::PackageProfileUploader
- Inherits:
-
Object
- Object
- Katello::Host::PackageProfileUploader
- Defined in:
- app/services/katello/host/package_profile_uploader.rb
Class Method Summary collapse
Instance Method Summary collapse
- #import_package_profile(profile) ⇒ Object
-
#initialize(profile_string:, host: nil) ⇒ PackageProfileUploader
constructor
A new instance of PackageProfileUploader.
- #trigger_applicability_generation ⇒ Object
- #upload ⇒ Object
Constructor Details
#initialize(profile_string:, host: nil) ⇒ PackageProfileUploader
Returns a new instance of PackageProfileUploader.
4 5 6 7 |
# File 'app/services/katello/host/package_profile_uploader.rb', line 4 def initialize(profile_string:, host: nil) @profile_string = profile_string @host = host end |
Class Method Details
.import_package_profile_for_host(host_id, profile) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/katello/host/package_profile_uploader.rb', line 24 def self.import_package_profile_for_host(host_id, profile) host = ::Host.find_by(:id => host_id) if host.nil? Rails.logger.warn("Host with ID %s not found; continuing" % host_id) elsif host.content_facet.nil? || host.content_facet.uuid.nil? Rails.logger.warn("Host with ID %s has no content facet; continuing" % host_id) else begin simple_packages = profile.map { |item| ::Katello::SimplePackage.new(item) } host.import_package_profile(simple_packages) rescue ActiveRecord::InvalidForeignKey # this happens if the host gets deleted in between the "find_by" and "import_package_profile" Rails.logger.warn("Host installed package list with ID %s was not able to be written to the DB (host likely is deleted); continuing" % host_id) end end end |
Instance Method Details
#import_package_profile(profile) ⇒ Object
16 17 18 |
# File 'app/services/katello/host/package_profile_uploader.rb', line 16 def import_package_profile(profile) self.class.import_package_profile_for_host(@host&.id, profile) end |
#trigger_applicability_generation ⇒ Object
20 21 22 |
# File 'app/services/katello/host/package_profile_uploader.rb', line 20 def trigger_applicability_generation ::Katello::Host::ContentFacet.trigger_applicability_generation(@host&.id) end |
#upload ⇒ Object
9 10 11 12 13 14 |
# File 'app/services/katello/host/package_profile_uploader.rb', line 9 def upload profile = JSON.parse(@profile_string) #free the huge string from the memory @profile_string = 'TRIMMED'.freeze import_package_profile(profile) end |