Class: Katello::Candlepin::Consumer
- Inherits:
-
Object
- Object
- Katello::Candlepin::Consumer
- Includes:
- LazyAccessor
- Defined in:
- app/services/katello/candlepin/consumer.rb
Constant Summary collapse
- ENTITLEMENTS_VALID =
'valid'.freeze
- ENTITLEMENTS_PARTIAL =
'partial'.freeze
- ENTITLEMENTS_INVALID =
'invalid'.freeze
- ENTITLEMENTS_DISABLED =
'disabled'.freeze
- SYSTEM =
"system".freeze
- HYPERVISOR =
"hypervisor".freeze
- CANDLEPIN =
"candlepin".freeze
- CP_TYPES =
[SYSTEM, HYPERVISOR, CANDLEPIN].freeze
Instance Attribute Summary collapse
-
#owner_label ⇒ Object
Returns the value of attribute owner_label.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Class Method Summary collapse
Instance Method Summary collapse
- #checkin(checkin_time) ⇒ Object
- #compliance_reasons ⇒ Object
- #entitlement_status ⇒ Object
- #entitlements? ⇒ Boolean
- #filter_entitlements(pool_id = nil, quantities = nil) ⇒ Object
- #filtered_pools(match_attached, match_host, match_installed, no_overlap) ⇒ Object
-
#initialize(uuid, owner_label) ⇒ Consumer
constructor
A new instance of Consumer.
- #pool_ids ⇒ Object
- #regenerate_identity_certificates ⇒ Object
- #system_purpose ⇒ Object
- #virtual_guests ⇒ Object
- #virtual_host ⇒ Object
Methods included from LazyAccessor
Constructor Details
#initialize(uuid, owner_label) ⇒ Consumer
Returns a new instance of Consumer.
30 31 32 33 |
# File 'app/services/katello/candlepin/consumer.rb', line 30 def initialize(uuid, owner_label) self.uuid = uuid self.owner_label = owner_label end |
Instance Attribute Details
#owner_label ⇒ Object
Returns the value of attribute owner_label.
28 29 30 |
# File 'app/services/katello/candlepin/consumer.rb', line 28 def owner_label @owner_label end |
#uuid ⇒ Object
Returns the value of attribute uuid.
28 29 30 |
# File 'app/services/katello/candlepin/consumer.rb', line 28 def uuid @uuid end |
Class Method Details
.distribution_to_puppet_os(name) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'app/services/katello/candlepin/consumer.rb', line 140 def self.distribution_to_puppet_os(name) return ::::REDHAT_ATOMIC_HOST_OS if name == ::::REDHAT_ATOMIC_HOST_DISTRO_NAME name = name.downcase if name =~ /red\s*hat/ 'RedHat' elsif name =~ /centos/ 'CentOS' elsif name =~ /fedora/ 'Fedora' elsif name =~ /sles/ || name =~ /suse.*enterprise.*/ 'SLES' elsif name =~ /debian/ 'Debian' elsif name =~ /ubuntu/ 'Ubuntu' elsif name =~ /oracle/ 'OracleLinux' elsif name =~ /almalinux/ 'AlmaLinux' elsif name =~ /rocky/ 'Rocky' elsif name =~ /amazon/ 'Amazon' else 'Unknown' end end |
.friendly_compliance_reasons(candlepin_reasons) ⇒ Object
133 134 135 136 137 138 |
# File 'app/services/katello/candlepin/consumer.rb', line 133 def self.friendly_compliance_reasons(candlepin_reasons) candlepin_reasons.map do |reason| product_name = reason['productName'] || reason['attributes']['name'] "#{product_name}: #{reason['message']}" end end |
Instance Method Details
#checkin(checkin_time) ⇒ Object
39 40 41 |
# File 'app/services/katello/candlepin/consumer.rb', line 39 def checkin(checkin_time) Resources::Candlepin::Consumer.checkin(uuid, checkin_time) end |
#compliance_reasons ⇒ Object
117 118 119 |
# File 'app/services/katello/candlepin/consumer.rb', line 117 def compliance_reasons self.class.friendly_compliance_reasons(Resources::Candlepin::Consumer.compliance(uuid)['reasons']) end |
#entitlement_status ⇒ Object
43 44 45 |
# File 'app/services/katello/candlepin/consumer.rb', line 43 def entitlement_status consumer_attributes[:entitlementStatus] end |
#entitlements? ⇒ Boolean
125 126 127 128 129 130 131 |
# File 'app/services/katello/candlepin/consumer.rb', line 125 def entitlements? # use cahced consumer_attributes if possible count = @consumer_attributes.try(:[], 'entitlementCount') return count > 0 if count !entitlements.empty? end |
#filter_entitlements(pool_id = nil, quantities = nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/services/katello/candlepin/consumer.rb', line 83 def filter_entitlements(pool_id = nil, quantities = nil) filtered = entitlements filtered = filtered.select { |ent| ent['pool']['id'].to_s == pool_id.to_s } if pool_id if quantities&.any? quantities.map!(&:to_s) filtered = quantities.map do |quantity| index = filtered.index { |ent| ent['quantity'].to_s == quantity } filtered.delete_at(index) if index end filtered.compact! end filtered end |
#filtered_pools(match_attached, match_host, match_installed, no_overlap) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/services/katello/candlepin/consumer.rb', line 47 def filtered_pools(match_attached, match_host, match_installed, no_overlap) if match_host pools = self.available_pools elsif match_attached pools = self.entitlements.map { |ent| ent['pool'] } else pools = self.all_available_pools end # Only available pool's with a product on the system' if match_installed pools = pools.select do |pool| self.installed_products.any? do |installed_product| pool['providedProducts'].any? do |provided_product| installed_product['productId'] == provided_product['productId'] end end end end # None of the available pool's products overlap a consumed pool's products if no_overlap pools = pools.select do |pool| pool['providedProducts'].all? do |provided_product| self.entitlements.all? do |consumed_entitlement| consumed_entitlement['pool']['providedProducts'].all? do |consumed_product| consumed_product['cp_id'] != provided_product['productId'] end end end end end ::Katello::Pool.where(:cp_id => pools.map { |pool| pool['id'] }) end |
#pool_ids ⇒ Object
99 100 101 |
# File 'app/services/katello/candlepin/consumer.rb', line 99 def pool_ids entitlements.map { |ent| ent['pool']['id'].to_s } end |
#regenerate_identity_certificates ⇒ Object
35 36 37 |
# File 'app/services/katello/candlepin/consumer.rb', line 35 def regenerate_identity_certificates Resources::Candlepin::Consumer.regenerate_identity_certificates(self.uuid) end |
#system_purpose ⇒ Object
121 122 123 |
# File 'app/services/katello/candlepin/consumer.rb', line 121 def system_purpose @system_purpose ||= Katello::Candlepin::SystemPurpose.new(purpose_compliance) end |
#virtual_guests ⇒ Object
103 104 105 106 107 108 |
# File 'app/services/katello/candlepin/consumer.rb', line 103 def virtual_guests return @virtual_guests unless @virtual_guests.nil? return [] if self.uuid.nil? guest_uuids = Resources::Candlepin::Consumer.virtual_guests(self.uuid).map { |guest| guest['uuid'] } @virtual_guests = ::Host.joins(:subscription_facet).where("#{Katello::Host::SubscriptionFacet.table_name}.uuid" => guest_uuids) end |
#virtual_host ⇒ Object
110 111 112 113 114 115 |
# File 'app/services/katello/candlepin/consumer.rb', line 110 def virtual_host return nil if self.uuid.nil? if (virtual_host_info = Resources::Candlepin::Consumer.virtual_host(self.uuid)) ::Host.joins(:subscription_facet).where("#{Katello::Host::SubscriptionFacet.table_name}.uuid" => virtual_host_info[:uuid]).first end end |