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'- ENTITLEMENTS_PARTIAL =
'partial'- ENTITLEMENTS_INVALID =
'invalid'- SYSTEM =
"system"- HYPERVISOR =
"hypervisor"- CANDLEPIN =
"candlepin"- CP_TYPES =
[SYSTEM, HYPERVISOR, CANDLEPIN]
Instance Attribute Summary collapse
-
#uuid ⇒ Object
Returns the value of attribute uuid.
Class Method Summary collapse
Instance Method Summary collapse
- #available_product_content ⇒ Object
- #checkin(checkin_time) ⇒ Object
- #compliance_reasons ⇒ Object
- #entitlement_status ⇒ Object
- #filter_entitlements(pool_id = nil, quantities = nil) ⇒ Object
- #filtered_pools(match_attached, match_host, match_installed, no_overlap) ⇒ Object
-
#initialize(uuid) ⇒ Consumer
constructor
A new instance of Consumer.
- #products ⇒ Object
- #regenerate_identity_certificates ⇒ Object
- #set_content_override(content_label, name, value = nil) ⇒ Object
- #virtual_guests ⇒ Object
- #virtual_host ⇒ Object
Methods included from LazyAccessor
Constructor Details
#initialize(uuid) ⇒ Consumer
Returns a new instance of Consumer.
25 26 27 |
# File 'app/services/katello/candlepin/consumer.rb', line 25 def initialize(uuid) self.uuid = uuid end |
Instance Attribute Details
#uuid ⇒ Object
Returns the value of attribute uuid.
23 24 25 |
# File 'app/services/katello/candlepin/consumer.rb', line 23 def uuid @uuid end |
Class Method Details
.distribution_to_puppet_os(name) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/services/katello/candlepin/consumer.rb', line 123 def self.distribution_to_puppet_os(name) return ::Operatingsystem::REDHAT_ATOMIC_HOST_OS if name == ::Operatingsystem::REDHAT_ATOMIC_HOST_DISTRO_NAME name = name.downcase if name =~ /red\s*hat/ 'RedHat' elsif name =~ /centos/ 'CentOS' elsif name =~ /fedora/ 'Fedora' end end |
Instance Method Details
#available_product_content ⇒ Object
113 114 115 |
# File 'app/services/katello/candlepin/consumer.rb', line 113 def available_product_content products.flat_map(&:available_content) end |
#checkin(checkin_time) ⇒ Object
33 34 35 |
# File 'app/services/katello/candlepin/consumer.rb', line 33 def checkin(checkin_time) Resources::Candlepin::Consumer.checkin(uuid, checkin_time) end |
#compliance_reasons ⇒ Object
117 118 119 120 121 |
# File 'app/services/katello/candlepin/consumer.rb', line 117 def compliance_reasons Resources::Candlepin::Consumer.compliance(uuid)['reasons'].map do |reason| "#{reason['attributes']['name']}: #{reason['message']}" end end |
#entitlement_status ⇒ Object
37 38 39 |
# File 'app/services/katello/candlepin/consumer.rb', line 37 def entitlement_status consumer_attributes[:entitlementStatus] end |
#filter_entitlements(pool_id = nil, quantities = nil) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/services/katello/candlepin/consumer.rb', line 77 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 && 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
41 42 43 44 45 46 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 |
# File 'app/services/katello/candlepin/consumer.rb', line 41 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.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 |
#products ⇒ Object
108 109 110 111 |
# File 'app/services/katello/candlepin/consumer.rb', line 108 def products pool_ids = self.entitlements.map { |entitlement| entitlement['pool']['id'] } Katello::Product.joins(:subscriptions => :pools).where("#{Katello::Pool.table_name}.cp_id" => pool_ids).enabled.uniq end |
#regenerate_identity_certificates ⇒ Object
29 30 31 |
# File 'app/services/katello/candlepin/consumer.rb', line 29 def regenerate_identity_certificates Resources::Candlepin::Consumer.regenerate_identity_certificates(self.uuid) end |
#set_content_override(content_label, name, value = nil) ⇒ Object
104 105 106 |
# File 'app/services/katello/candlepin/consumer.rb', line 104 def set_content_override(content_label, name, value = nil) Resources::Candlepin::Consumer.update_content_override(self.uuid, content_label, name, value) end |
#virtual_guests ⇒ Object
93 94 95 96 |
# File 'app/services/katello/candlepin/consumer.rb', line 93 def virtual_guests guest_uuids = Resources::Candlepin::Consumer.virtual_guests(self.uuid).map { |guest| guest['uuid'] } ::Host.joins(:subscription_facet).where("#{Katello::Host::SubscriptionFacet.table_name}.uuid" => guest_uuids) end |
#virtual_host ⇒ Object
98 99 100 101 102 |
# File 'app/services/katello/candlepin/consumer.rb', line 98 def virtual_host 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 |