Class: Katello::Pulp3::Api::Core
- Inherits:
-
Object
- Object
- Katello::Pulp3::Api::Core
show all
- Defined in:
- app/services/katello/pulp3/api/core.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(smart_proxy, repository_type = Katello::RepositoryTypeManager.find_by(:pulp3_api_class, self.class)) ⇒ Core
Returns a new instance of Core.
9
10
11
12
|
# File 'app/services/katello/pulp3/api/core.rb', line 9
def initialize(smart_proxy, repository_type = Katello::RepositoryTypeManager.find_by(:pulp3_api_class, self.class))
@smart_proxy = smart_proxy
@repository_type = repository_type
end
|
Instance Attribute Details
#repository_type ⇒ Object
Returns the value of attribute repository_type.
7
8
9
|
# File 'app/services/katello/pulp3/api/core.rb', line 7
def repository_type
@repository_type
end
|
#smart_proxy ⇒ Object
Returns the value of attribute smart_proxy.
7
8
9
|
# File 'app/services/katello/pulp3/api/core.rb', line 7
def smart_proxy
@smart_proxy
end
|
Class Method Details
.fetch_from_list ⇒ Object
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
# File 'app/services/katello/pulp3/api/core.rb', line 260
def self.fetch_from_list
page_size = Setting[:bulk_load_size]
page_opts = { "offset" => 0, limit: page_size }
response = {}
results = []
loop do
page_opts = page_opts.with_indifferent_access
break unless (
(response.count && (page_opts['offset'] < response.count)) ||
page_opts["offset"] == 0)
response = yield page_opts
results.concat(response.results)
page_opts[:offset] += page_size
end
results
end
|
.ignore_409_exception ⇒ Object
75
76
77
78
79
80
|
# File 'app/services/katello/pulp3/api/core.rb', line 75
def self.ignore_409_exception(*)
yield
rescue => e
raise e unless e&.code == 409
nil
end
|
.remote_uln_class ⇒ Object
20
21
22
|
# File 'app/services/katello/pulp3/api/core.rb', line 20
def self.remote_uln_class
fail NotImplementedError
end
|
Instance Method Details
#api_client ⇒ Object
32
33
34
35
36
|
# File 'app/services/katello/pulp3/api/core.rb', line 32
def api_client
config = smart_proxy.pulp3_configuration(repository_type.configuration_class)
config.params_encoder = Faraday::FlatParamsEncoder
api_client_class(repository_type.api_class.new(config))
end
|
#api_client_class(client) ⇒ Object
138
139
140
141
142
|
# File 'app/services/katello/pulp3/api/core.rb', line 138
def api_client_class(client)
request_id = ::Logging.mdc['request']
client.['Correlation-ID'] = request_id if request_id
client
end
|
#api_exception_class ⇒ Object
38
39
40
|
# File 'app/services/katello/pulp3/api/core.rb', line 38
def api_exception_class
client_module::ApiError
end
|
#artifacts_api ⇒ Object
129
130
131
|
# File 'app/services/katello/pulp3/api/core.rb', line 129
def artifacts_api
PulpcoreClient::ArtifactsApi.new(core_api_client)
end
|
#cancel_task(task_href) ⇒ Object
86
87
88
89
90
91
|
# File 'app/services/katello/pulp3/api/core.rb', line 86
def cancel_task(task_href)
data = PulpcoreClient::TaskResponse.new(state: 'canceled')
self.class.ignore_409_exception do
tasks_api.tasks_cancel(task_href, data)
end
end
|
#client_module ⇒ Object
14
15
16
|
# File 'app/services/katello/pulp3/api/core.rb', line 14
def client_module
repository_type.client_module_class
end
|
#core_api_client ⇒ Object
133
134
135
136
|
# File 'app/services/katello/pulp3/api/core.rb', line 133
def core_api_client
client = PulpcoreClient::ApiClient.new(smart_proxy.pulp3_configuration(PulpcoreClient::Configuration))
api_client_class(client)
end
|
#core_repositories_api ⇒ Object
63
64
65
|
# File 'app/services/katello/pulp3/api/core.rb', line 63
def core_repositories_api
PulpcoreClient::RepositoriesApi.new(core_api_client)
end
|
#core_repositories_list_all(options = {}) ⇒ Object
234
235
236
237
238
|
# File 'app/services/katello/pulp3/api/core.rb', line 234
def core_repositories_list_all(options = {})
self.class.fetch_from_list do |page_opts|
core_repositories_api.list(page_opts.merge(options))
end
end
|
#delete_distribution(href) ⇒ Object
230
231
232
|
# File 'app/services/katello/pulp3/api/core.rb', line 230
def delete_distribution(href)
ignore_404_exception { distributions_api.delete(href) }
end
|
#delete_orphans ⇒ Object
187
188
189
|
# File 'app/services/katello/pulp3/api/core.rb', line 187
def delete_orphans
[orphans_api.cleanup(PulpcoreClient::OrphansCleanup.new(orphan_protection_time: (smart_proxy.pulp_mirror? ? 0 : Setting[:orphan_protection_time])))]
end
|
#delete_remote(remote_href) ⇒ Object
191
192
193
|
# File 'app/services/katello/pulp3/api/core.rb', line 191
def delete_remote(remote_href)
ignore_404_exception { remotes_api.delete(remote_href) }
end
|
#distributions_api ⇒ Object
59
60
61
|
# File 'app/services/katello/pulp3/api/core.rb', line 59
def distributions_api
repository_type.distributions_api_class.new(api_client)
end
|
#distributions_list_all(args = {}) ⇒ Object
220
221
222
223
224
|
# File 'app/services/katello/pulp3/api/core.rb', line 220
def distributions_list_all(args = {})
self.class.fetch_from_list do |page_opts|
distributions_api.list(page_opts.merge(args))
end
end
|
#export_api ⇒ Object
117
118
119
|
# File 'app/services/katello/pulp3/api/core.rb', line 117
def export_api
PulpcoreClient::ExportersPulpExportsApi.new(core_api_client)
end
|
#exporter_api ⇒ Object
101
102
103
|
# File 'app/services/katello/pulp3/api/core.rb', line 101
def exporter_api
PulpcoreClient::ExportersPulpApi.new(core_api_client)
end
|
#get_distribution(href) ⇒ Object
226
227
228
|
# File 'app/services/katello/pulp3/api/core.rb', line 226
def get_distribution(href)
ignore_404_exception { distributions_api.read(href) }
end
|
#get_remotes_api ⇒ Object
Method is called with either :url or :href parameters for the sake of yum content.
51
52
53
|
# File 'app/services/katello/pulp3/api/core.rb', line 51
def get_remotes_api(*)
remotes_api
end
|
#ignore_404_exception ⇒ Object
172
173
174
175
176
177
|
# File 'app/services/katello/pulp3/api/core.rb', line 172
def ignore_404_exception(*)
yield
rescue self.api_exception_class => e
raise e unless e.code == 404
nil
end
|
#import_api ⇒ Object
121
122
123
|
# File 'app/services/katello/pulp3/api/core.rb', line 121
def import_api
PulpcoreClient::ImportersPulpImportsApi.new(core_api_client)
end
|
#importer_api ⇒ Object
105
106
107
|
# File 'app/services/katello/pulp3/api/core.rb', line 105
def importer_api
PulpcoreClient::ImportersPulpApi.new(core_api_client)
end
|
#importer_check_api ⇒ Object
109
110
111
|
# File 'app/services/katello/pulp3/api/core.rb', line 109
def importer_check_api
PulpcoreClient::ImportersPulpImportCheckApi.new(core_api_client)
end
|
#list_all(options = {}) ⇒ Object
240
241
242
243
244
|
# File 'app/services/katello/pulp3/api/core.rb', line 240
def list_all(options = {})
self.class.fetch_from_list do |page_opts|
repositories_api.list(page_opts.merge(options))
end
end
|
#orphans_api ⇒ Object
125
126
127
|
# File 'app/services/katello/pulp3/api/core.rb', line 125
def orphans_api
PulpcoreClient::OrphansCleanupApi.new(core_api_client)
end
|
#publications_api ⇒ Object
55
56
57
|
# File 'app/services/katello/pulp3/api/core.rb', line 55
def publications_api
repository_type.publications_api_class.new(api_client)
end
|
#publications_list_all(args = {}) ⇒ Object
214
215
216
217
218
|
# File 'app/services/katello/pulp3/api/core.rb', line 214
def publications_list_all(args = {})
self.class.fetch_from_list do |page_opts|
publications_api.list(page_opts.merge(args))
end
end
|
#purge_class ⇒ Object
179
180
181
|
# File 'app/services/katello/pulp3/api/core.rb', line 179
def purge_class
PulpcoreClient::Purge
end
|
#purge_completed_tasks ⇒ Object
183
184
185
|
# File 'app/services/katello/pulp3/api/core.rb', line 183
def purge_completed_tasks
tasks_api.purge(purge_class.new(finished_before: DateTime.now - Setting[:completed_pulp_task_protection_days]))
end
|
#remotes_api ⇒ Object
42
43
44
|
# File 'app/services/katello/pulp3/api/core.rb', line 42
def remotes_api
repository_type.remotes_api_class.new(api_client)
end
|
#remotes_list(args = {}) ⇒ Object
246
247
248
|
# File 'app/services/katello/pulp3/api/core.rb', line 246
def remotes_list(args = {})
remotes_api.list(args).results
end
|
#remotes_list_all(_smart_proxy, options = {}) ⇒ Object
250
251
252
253
254
|
# File 'app/services/katello/pulp3/api/core.rb', line 250
def remotes_list_all(_smart_proxy, options = {})
self.class.fetch_from_list do |page_opts|
remotes_api.list(page_opts.merge(options))
end
end
|
#remotes_uln_api ⇒ Object
46
47
48
|
# File 'app/services/katello/pulp3/api/core.rb', line 46
def remotes_uln_api
fail NotImplementedError
end
|
#repair ⇒ Object
256
257
258
|
# File 'app/services/katello/pulp3/api/core.rb', line 256
def repair
repair_api.post(PulpcoreClient::Repair.new(verify_checksums: true))
end
|
#repair_api ⇒ Object
144
145
146
|
# File 'app/services/katello/pulp3/api/core.rb', line 144
def repair_api
PulpcoreClient::RepairApi.new(core_api_client)
end
|
#repair_class ⇒ Object
82
83
84
|
# File 'app/services/katello/pulp3/api/core.rb', line 82
def repair_class
client_module::Repair
end
|
#repositories_api ⇒ Object
67
68
69
|
# File 'app/services/katello/pulp3/api/core.rb', line 67
def repositories_api
repository_type.repositories_api_class.new(api_client)
end
|
#repositories_reclaim_space_api ⇒ Object
93
94
95
|
# File 'app/services/katello/pulp3/api/core.rb', line 93
def repositories_reclaim_space_api
PulpcoreClient::RepositoriesReclaimSpaceApi.new(core_api_client)
end
|
#repository_sync_url_class ⇒ Object
28
29
30
|
# File 'app/services/katello/pulp3/api/core.rb', line 28
def repository_sync_url_class
repository_type.repo_sync_url_class
end
|
#repository_version_hrefs(options = {}) ⇒ Object
195
196
197
|
# File 'app/services/katello/pulp3/api/core.rb', line 195
def repository_version_hrefs(options = {})
repository_versions(options).map(&:pulp_href).uniq
end
|
#repository_versions(options = {}) ⇒ Object
199
200
201
202
203
204
205
206
207
208
|
# File 'app/services/katello/pulp3/api/core.rb', line 199
def repository_versions(options = {})
current_pulp_repositories = self.list_all(options)
repo_hrefs = current_pulp_repositories.collect { |repo| repo.pulp_href }.uniq
version_hrefs = repo_hrefs.collect do |href|
versions_list_for_repository(href, options)
end
version_hrefs.flatten
end
|
#repository_versions_api ⇒ Object
71
72
73
|
# File 'app/services/katello/pulp3/api/core.rb', line 71
def repository_versions_api
repository_type.repository_versions_api_class.new(api_client)
end
|
#signing_services_api ⇒ Object
156
157
158
|
# File 'app/services/katello/pulp3/api/core.rb', line 156
def signing_services_api
PulpcoreClient::SigningServicesApi.new(core_api_client)
end
|
#task_groups_api ⇒ Object
164
165
166
|
# File 'app/services/katello/pulp3/api/core.rb', line 164
def task_groups_api
PulpcoreClient::TaskGroupsApi.new(core_api_client)
end
|
#tasks_api ⇒ Object
160
161
162
|
# File 'app/services/katello/pulp3/api/core.rb', line 160
def tasks_api
PulpcoreClient::TasksApi.new(core_api_client)
end
|
#upload_class ⇒ Object
168
169
170
|
# File 'app/services/katello/pulp3/api/core.rb', line 168
def upload_class
PulpcoreClient::Upload
end
|
#upload_commit_class ⇒ Object
152
153
154
|
# File 'app/services/katello/pulp3/api/core.rb', line 152
def upload_commit_class
PulpcoreClient::UploadCommit
end
|
#uploads_api ⇒ Object
148
149
150
|
# File 'app/services/katello/pulp3/api/core.rb', line 148
def uploads_api
PulpcoreClient::UploadsApi.new(core_api_client)
end
|
#versions_list_for_repository(repository_href, options) ⇒ Object
210
211
212
|
# File 'app/services/katello/pulp3/api/core.rb', line 210
def versions_list_for_repository(repository_href, options)
self.class.fetch_from_list { |page_opts| repository_versions_api.list(repository_href, page_opts.merge(options)) }
end
|
#yum_export_api ⇒ Object
113
114
115
|
# File 'app/services/katello/pulp3/api/core.rb', line 113
def yum_export_api
PulpcoreClient::ExportersFilesystemExportsApi.new(core_api_client)
end
|
#yum_exporter_api ⇒ Object
97
98
99
|
# File 'app/services/katello/pulp3/api/core.rb', line 97
def yum_exporter_api
PulpcoreClient::ExportersFilesystemApi.new(core_api_client)
end
|