Class: Katello::Resources::Candlepin::Consumer
Constant Summary
Constants inherited
from HttpResource
HttpResource::REQUEST_MAP
Instance Attribute Summary
Attributes inherited from HttpResource
#json
Class Method Summary
collapse
path
default_headers, fetch_paged, included_list, logger, name_to_key, process_response, raise_rest_client_exception
#[], #[]=, hash_to_query, #initialize, issue_request, join_path, logger, process_response, raise_rest_client_exception, rest_client
#filter_sensitive_data
Class Method Details
.all_uuids ⇒ Object
8
9
10
11
12
13
14
|
# File 'app/lib/katello/resources/candlepin/consumer.rb', line 8
def all_uuids
cp_consumers = Organization.all.map do |org|
::Katello::Resources::Candlepin::Consumer.get('owner' => org.label, :include_only => [:uuid], :sort_by => "uuid")
end
cp_consumers.flatten!
cp_consumers.map { |consumer| consumer["uuid"] }
end
|
.async_hypervisors(owner:, reporter_id:, raw_json:) ⇒ Object
47
48
49
50
51
52
53
|
# File 'app/lib/katello/resources/candlepin/consumer.rb', line 47
def async_hypervisors(owner:, reporter_id:, raw_json:)
url = "/candlepin/hypervisors/#{owner}?reporter_id=#{reporter_id}"
= self.
['content-type'] = 'text/plain'
response = self.post(url, raw_json, )
JSON.parse(response).with_indifferent_access
end
|
.checkin(uuid, checkin_date) ⇒ Object
91
92
93
94
|
# File 'app/lib/katello/resources/candlepin/consumer.rb', line 91
def checkin(uuid, checkin_date)
checkin_date ||= Time.now
self.put(path(uuid), {:lastCheckin => checkin_date}.to_json, self.).body
end
|
.content_overrides(id) ⇒ Object
.create(env_ids, parameters, activation_key_cp_ids, org) ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'app/lib/katello/resources/candlepin/consumer.rb', line 37
def create(env_ids, parameters, activation_key_cp_ids, org)
parameters['installedProducts'] ||= [] parameters['environments'] = env_ids.map { |cp_id| { id: cp_id } }
url = "/candlepin/consumers/?owner=#{org.label}"
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
82
83
84
|
# File 'app/lib/katello/resources/candlepin/consumer.rb', line 82
def destroy(uuid)
self.delete(path(uuid), User.).code.to_i
end
|
.get(params) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
|
# File 'app/lib/katello/resources/candlepin/consumer.rb', line 16
def get(params)
if params.is_a?(String)
JSON.parse(super(path(params), self.).body).with_indifferent_access
else
includes = params.key?(:include_only) ? "&" + included_list(params.delete(:include_only)) : ""
fetch_paged do |page_add|
response = super(path + hash_to_query(params) + includes + "&#{page_add}", self.).body
JSON.parse(response).map(&:with_indifferent_access)
end
end
end
|
.get_all_with_facts(uuids) ⇒ Object
29
30
31
32
33
34
35
|
# File 'app/lib/katello/resources/candlepin/consumer.rb', line 29
def get_all_with_facts(uuids)
consumers = []
uuids.each do |uuid|
consumers << get(uuid)
end
consumers
end
|
.hypervisors_heartbeat(owner:, reporter_id:) ⇒ Object
55
56
57
58
59
|
# File 'app/lib/katello/resources/candlepin/consumer.rb', line 55
def hypervisors_heartbeat(owner:, reporter_id:)
url = "/candlepin/hypervisors/#{owner}/heartbeat?reporter_id=#{reporter_id}"
response = self.put(url, {}.to_json, self.).body
JSON.parse(response).with_indifferent_access
end
|
.regenerate_identity_certificates(uuid) ⇒ Object
96
97
98
99
|
# File 'app/lib/katello/resources/candlepin/consumer.rb', line 96
def regenerate_identity_certificates(uuid)
response = self.post(path(uuid), {}, self.).body
JSON.parse(response).with_indifferent_access
end
|
.register_hypervisors(params) ⇒ Object
61
62
63
64
65
66
67
|
# File 'app/lib/katello/resources/candlepin/consumer.rb', line 61
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
|
.serials(uuid) ⇒ Object
86
87
88
89
|
# File 'app/lib/katello/resources/candlepin/consumer.rb', line 86
def serials(uuid)
response = Candlepin::CandlepinResource.get(join_path(path(uuid), 'certificates/serials'))
JSON.parse(response.body)
end
|
.update(uuid, params) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'app/lib/katello/resources/candlepin/consumer.rb', line 69
def update(uuid, params)
if params.empty?
true
else
if params.key?(:environment) && params[:environment].key?(:id)
params[:environments] = [{"id": params[:environment][:id]}]
end
self.put(path(uuid), params.to_json, self.).body
end
end
|
.update_content_overrides(id, content_overrides) ⇒ Object
expected params id : UUID of the consumer content_overrides => Array of entitlement hashes objects
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'app/lib/katello/resources/candlepin/consumer.rb', line 127
def update_content_overrides(id, content_overrides)
attrs_to_delete = []
attrs_to_update = []
content_overrides.each do |content_override|
if content_override[:value]
attrs_to_update << content_override
else
attrs_to_delete << content_override
end
end
if attrs_to_update.present?
result = Candlepin::CandlepinResource.put(join_path(path(id), 'content_overrides'),
attrs_to_update.to_json, self.)
end
if attrs_to_delete.present?
client = Candlepin::CandlepinResource.rest_client(Net::HTTP::Delete, :delete,
join_path(path(id), 'content_overrides'))
client.options[:payload] = attrs_to_delete.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
108
109
110
111
112
113
114
115
116
117
|
# File 'app/lib/katello/resources/candlepin/consumer.rb', line 108
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 RestClient::Exception
return nil
end
|