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

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

Instance Method Summary collapse

Instance Method Details

#backend_dataObject



77
78
79
# File 'app/models/katello/glue/candlepin/pool.rb', line 77

def backend_data
  self.class.candlepin_data(self.cp_id)
end

#create_activation_key_associationsObject



124
125
126
127
128
129
130
131
132
133
# File 'app/models/katello/glue/candlepin/pool.rb', line 124

def create_activation_key_associations
  keys = Resources::Candlepin::ActivationKey.get(nil, "?include=id&include=pools.pool.id")
  activation_key_ids = keys.collect do |key|
    key['id'] if key['pools'].present? && key['pools'].any? { |pool| pool['pool']['id'] == cp_id }
  end
  related_keys = ::Katello::ActivationKey.where(:cp_id => activation_key_ids.compact)
  related_keys.each do |key|
    Katello::PoolActivationKey.where(:activation_key_id => key.id, :pool_id => self.id).first_or_create
  end
end

#hostObject



135
136
137
# File 'app/models/katello/glue/candlepin/pool.rb', line 135

def host
  System.find_by(:uuid => host_id) if host_id
end

#import_dataObject



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
110
111
112
113
114
115
116
117
118
# File 'app/models/katello/glue/candlepin/pool.rb', line 81

def import_data
  pool_attributes = {}
  pool_json = self.backend_data
  product_attributes = pool_json["productAttributes"] + pool_json["attributes"]

  product_attributes.map { |attr| pool_attributes[attr["name"].underscore.to_sym] = attr["value"] }

  if !pool_json["sourceStackId"].nil?
    subscription = ::Katello::Subscription.where(:product_id => pool_json["sourceStackId"])
  else
    subscription = ::Katello::Subscription.where(:cp_id => pool_json["subscriptionId"])
  end

  pool_attributes[:subscription_id] = subscription.first.id if subscription.any?

  %w(accountNumber contractNumber quantity startDate endDate accountNumber consumed).each do |json_attribute|
    pool_attributes[json_attribute.underscore] = pool_json[json_attribute]
  end
  pool_attributes[:pool_type] = pool_json["type"] if pool_json.key?("type")

  if pool_attributes.key?(:multi_entitlement)
    pool_attributes[:multi_entitlement] = pool_attributes[:multi_entitlement] == "yes" ? true : false
  end

  if pool_attributes.key?(:virtual)
    pool_attributes[:virt_only] = pool_attributes["virtual"] == 'true' ? true : false
  end
  pool_attributes[:host_id] = pool_attributes["requiresHost"] if pool_attributes.key?("requiresHost")

  if pool_attributes.key?(:unmapped_guests_only) && pool_attributes[:unmapped_guests_only] == 'true'
    pool_attributes[:unmapped_guest] = true
  end

  exceptions = pool_attributes.keys.map(&:to_sym) - self.attribute_names.map(&:to_sym)
  self.update_attributes(pool_attributes.except!(*exceptions))
  self.save!
  self.create_activation_key_associations
end

#import_lazy_attributesObject



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
# File 'app/models/katello/glue/candlepin/pool.rb', line 41

def import_lazy_attributes
  json = self.backend_data

  pool_attributes = json["attributes"] + json["productAttributes"]
  json["virt_only"] = false
  pool_attributes.each do |attr|
    json[attr["name"]] = attr["value"]
    case attr["name"]
    when 'requires_host'
      json["host_id"] = attr['value']
    when 'virt_limit'
      json["virt_limit"] = attr['value'].to_i
    when 'support_type'
      json['support_type'] = attr['value']
    end
  end

  json["calculatedAttributes"].each do |key|
    json["suggested_quantity"] = json["calculatedAttributes"]["suggested_quantity"].to_i if key == 'suggested_quantity'
  end if json["calculatedAttributes"]

  json["product_id"] = json["productId"] if json["productId"]

  if self.subscription
    subscription.backend_data["product"]["attributes"].map { |attr| json[attr["name"].underscore.to_sym] = attr["value"] }
  end
  json
end

#provider?(organization) ⇒ Boolean



70
71
72
73
74
75
# File 'app/models/katello/glue/candlepin/pool.rb', line 70

def provider?(organization)
  providers = self.subscription.products.collect do |provider|
    Katello::Provider.where(:id => provider.provider_id, :organization_id => organization.id).first
  end
  providers.any?
end

#systemsObject



120
121
122
# File 'app/models/katello/glue/candlepin/pool.rb', line 120

def systems
  System.all_by_pool(cp_id)
end