Module: Glue::Candlepin::Pool::InstanceMethods

Defined in:
app/models/katello/glue/candlepin/pool.rb

Instance Method Summary collapse

Instance Method Details

#create_product_associationsObject



111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/models/katello/glue/candlepin/pool.rb', line 111

def create_product_associations
  products = self.backend_data["providedProducts"] + self.backend_data["derivedProvidedProducts"]
  cp_product_ids = products.map { |product| product["productId"] }
  cp_product_ids << self.subscription.cp_id if self.subscription

  cp_product_ids.each do |cp_id|
    product = ::Katello::Product.where(:cp_id => cp_id, :organization_id => self.organization.id)
    if product.any?
      ::Katello::Util::Support.active_record_retry do
        ::Katello::PoolProduct.where(:pool_id => self.id, :product_id => product.first.id).first_or_create
      end
    end
  end
end

#import_dataObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/models/katello/glue/candlepin/pool.rb', line 76

def import_data
  pool_attributes = {}
  pool_json = self.backend_data

  IMPORT_ROOT_ATTRIBUTES.each do |name|
    pool_attributes[name.underscore] = pool_json[name]
  end

  pool_attributes[:pool_type] = pool_json[:type]
  pool_attributes[:stacking_id] = pool_json[:stackId]

  combined_attributes = pool_json[:productAttributes] + pool_json[:attributes]
  combined_attributes.each do |attr|
    case attr[:name]
    when 'multi-entitlement'
      pool_attributes[:multi_entitlement] = attr[:value] == 'yes'
    when 'requires_host'
      pool_attributes[:hypervisor_id] = ::Katello::Host::SubscriptionFacet.find_by(uuid: attr[:value])&.host_id
    when 'unmapped_guests_only'
      pool_attributes[:unmapped_guest] = attr[:value] == 'true'
    when 'virt_only'
      pool_attributes[:virt_only] = attr[:value] == 'true'
    when 'virt_limit'
      pool_attributes[:virt_who] = attr[:value].to_i > 0
    else
      if IMPORT_ATTRIBUTES.include?(attr[:name])
        pool_attributes[attr[:name]] = attr[:value]
      end
    end
  end

  update!(pool_attributes)
  create_product_associations
end