Class: Katello::Resources::Candlepin::Consumer
Instance Attribute Summary
Attributes inherited from HttpResource
#json
Class Method Summary
collapse
-
.available_pools(uuid, listall = false) ⇒ Object
-
.checkin(uuid, checkin_date) ⇒ Object
-
.compliance(uuid) ⇒ Object
-
.consume_entitlement(uuid, pool, quantity = nil) ⇒ Object
-
.content_overrides(id) ⇒ Object
-
.create(env_id, parameters, activation_key_cp_ids) ⇒ Object
-
.destroy(uuid) ⇒ Object
-
.entitlements(uuid) ⇒ Object
-
.events(uuid) ⇒ Object
-
.export(uuid) ⇒ Object
-
.get(params) ⇒ Object
-
.path(id = nil) ⇒ Object
-
.refresh_entitlements(uuid) ⇒ Object
-
.regenerate_identity_certificates(uuid) ⇒ Object
-
.register_hypervisors(params) ⇒ Object
-
.remove_certificate(uuid, serial_id) ⇒ Object
-
.remove_entitlement(uuid, ent_id) ⇒ Object
-
.remove_entitlements(uuid) ⇒ Object
-
.serials(uuid) ⇒ Object
-
.update(uuid, params) ⇒ Object
-
.update_content_override(id, content_label, name, value = nil) ⇒ Object
-
.virtual_guests(uuid) ⇒ Object
-
.virtual_host(uuid) ⇒ Object
default_headers, logger, name_to_key
#[], #[]=, create_thing, delete, hash_to_query, #initialize, join_path, logger, post, print_debug_info, process_response, put, raise_rest_client_exception, rest_client, url_encode
Class Method Details
.available_pools(uuid, listall = false) ⇒ Object
148
149
150
151
152
|
# File 'app/lib/katello/resources/candlepin.rb', line 148
def available_pools(uuid, listall = false)
url = Pool.path + "?consumer=#{uuid}&listall=#{listall}"
response = Candlepin::CandlepinResource.get(url, self.).body
JSON.parse(response)
end
|
.checkin(uuid, checkin_date) ⇒ Object
143
144
145
146
|
# File 'app/lib/katello/resources/candlepin.rb', line 143
def checkin(uuid, checkin_date)
checkin_date ||= DateTime.now
self.put(path(uuid), {:lastCheckin => checkin_date}.to_json, self.).body
end
|
.compliance(uuid) ⇒ Object
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
# File 'app/lib/katello/resources/candlepin.rb', line 216
def compliance(uuid)
response = Candlepin::CandlepinResource.get(join_path(path(uuid), 'compliance'), self.(uuid)).body
if response.present?
json = JSON.parse(response).with_indifferent_access
if json['reasons']
json['reasons'].sort! { |x, y| x['attributes']['name'] <=> y['attributes']['name'] }
else
json['reasons'] = []
end
json
else
return nil
end
end
|
.consume_entitlement(uuid, pool, quantity = nil) ⇒ Object
176
177
178
179
180
181
|
# File 'app/lib/katello/resources/candlepin.rb', line 176
def consume_entitlement(uuid, pool, quantity = nil)
uri = join_path(path(uuid), 'entitlements') + "?pool=#{pool}"
uri += "&quantity=#{quantity}" if quantity && quantity > 0
response = self.post(uri, "", self.).body
response.blank? ? [] : JSON.parse(response)
end
|
.content_overrides(id) ⇒ Object
.create(env_id, parameters, activation_key_cp_ids) ⇒ Object
107
108
109
110
111
112
113
114
|
# File 'app/lib/katello/resources/candlepin.rb', line 107
def create(env_id, parameters, activation_key_cp_ids)
parameters['installedProducts'] ||= [] url = "/candlepin/environments/#{url_encode(env_id)}/consumers/"
url += "?activation_keys=" + activation_key_cp_ids.join(",") if activation_key_cp_ids.length > 0
response = self.post(url, parameters.to_json, self.).body
JSON.parse(response).with_indifferent_access
end
|
.destroy(uuid) ⇒ Object
134
135
136
|
# File 'app/lib/katello/resources/candlepin.rb', line 134
def destroy(uuid)
self.delete(path(uuid), User.).code.to_i
end
|
.entitlements(uuid) ⇒ Object
.export(uuid) ⇒ Object
159
160
161
162
163
164
165
|
# File 'app/lib/katello/resources/candlepin.rb', line 159
def export(uuid)
= self.
['accept'] = 'application/zip'
response = Candlepin::CandlepinResource.get(join_path(path(uuid), 'export'), )
response
end
|
.get(params) ⇒ Object
98
99
100
101
102
103
104
105
|
# File 'app/lib/katello/resources/candlepin.rb', line 98
def get(params)
if params.is_a?(String)
JSON.parse(super(path(params), self.).body).with_indifferent_access
else
response = super(path + hash_to_query(params), self.).body
JSON.parse(response)
end
end
|
.path(id = nil) ⇒ Object
94
95
96
|
# File 'app/lib/katello/resources/candlepin.rb', line 94
def path(id = nil)
"/candlepin/consumers/#{id}"
end
|
.refresh_entitlements(uuid) ⇒ Object
172
173
174
|
# File 'app/lib/katello/resources/candlepin.rb', line 172
def refresh_entitlements(uuid)
self.post(join_path(path(uuid), 'entitlements'), "", self.).body
end
|
.regenerate_identity_certificates(uuid) ⇒ Object
154
155
156
157
|
# File 'app/lib/katello/resources/candlepin.rb', line 154
def regenerate_identity_certificates(uuid)
response = self.post(path(uuid), {}, self.).body
JSON.parse(response).with_indifferent_access
end
|
.register_hypervisors(params) ⇒ Object
116
117
118
119
120
121
122
|
# File 'app/lib/katello/resources/candlepin.rb', line 116
def register_hypervisors(params)
url = "/candlepin/hypervisors"
url << "?owner=#{params[:owner]}&env=#{params[:env]}"
attrs = params.except(:owner, :env)
response = self.post(url, attrs.to_json, self.).body
JSON.parse(response).with_indifferent_access
end
|
.remove_certificate(uuid, serial_id) ⇒ Object
193
194
195
196
|
# File 'app/lib/katello/resources/candlepin.rb', line 193
def remove_certificate(uuid, serial_id)
uri = join_path(path(uuid), 'certificates') + "/#{serial_id}"
self.delete(uri, self.).code.to_i
end
|
.remove_entitlement(uuid, ent_id) ⇒ Object
183
184
185
186
|
# File 'app/lib/katello/resources/candlepin.rb', line 183
def remove_entitlement(uuid, ent_id)
uri = join_path(path(uuid), 'entitlements') + "/#{ent_id}"
self.delete(uri, self.).code.to_i
end
|
.remove_entitlements(uuid) ⇒ Object
188
189
190
191
|
# File 'app/lib/katello/resources/candlepin.rb', line 188
def remove_entitlements(uuid)
uri = join_path(path(uuid), 'entitlements')
self.delete(uri, self.).code.to_i
end
|
.serials(uuid) ⇒ Object
138
139
140
141
|
# File 'app/lib/katello/resources/candlepin.rb', line 138
def serials(uuid)
response = Candlepin::CandlepinResource.get(join_path(path(uuid), 'certificates/serials'))
JSON.parse(response.body)
end
|
.update(uuid, params) ⇒ Object
124
125
126
127
128
129
130
131
132
|
# File 'app/lib/katello/resources/candlepin.rb', line 124
def update(uuid, params)
if params.empty?
true
else
self.put(path(uuid), params.to_json, self.).body
end
end
|
.update_content_override(id, content_label, name, value = nil) ⇒ Object
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
# File 'app/lib/katello/resources/candlepin.rb', line 245
def update_content_override(id, content_label, name, value = nil)
attrs = [{ :contentLabel => content_label, :name => name }]
if value
attrs[0][:value] = value
result = Candlepin::CandlepinResource.put(join_path(path(id), 'content_overrides'),
attrs.to_json, self.)
else
client = Candlepin::CandlepinResource.rest_client(Net::HTTP::Delete, :delete,
join_path(path(id), 'content_overrides'))
client.options[:payload] = attrs.to_json
result = client.delete({:accept => :json, :content_type => :json}.merge(User.))
end
::Katello::Util::Data.array_with_indifferent_access(JSON.parse(result))
end
|
.virtual_guests(uuid) ⇒ Object
.virtual_host(uuid) ⇒ Object
205
206
207
208
209
210
211
212
213
214
|
# File 'app/lib/katello/resources/candlepin.rb', line 205
def virtual_host(uuid)
response = Candlepin::CandlepinResource.get(join_path(path(uuid), 'host'), self.).body
if response.present?
JSON.parse(response).with_indifferent_access
else
return nil
end
rescue
return nil
end
|