Class: Katello::Pulp3::Content
- Inherits:
-
Object
- Object
- Katello::Pulp3::Content
- Extended by:
- Abstract::Pulp::Content
- Defined in:
- app/services/katello/pulp3/content.rb
Class Method Summary collapse
-
.create_upload(size = 0, checksum = nil, content_type = nil, repository = nil) ⇒ Object
rubocop:disable Metrics/ParameterLists.
- .delete_upload(upload_href) ⇒ Object
- .upload_chunk(upload_href, offset, content, size) ⇒ Object
Methods included from Abstract::Pulp::Content
create_upload, delete_upload, upload_chunk
Class Method Details
.create_upload(size = 0, checksum = nil, content_type = nil, repository = nil) ⇒ Object
rubocop:disable Metrics/ParameterLists
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/services/katello/pulp3/content.rb', line 8 def create_upload(size = 0, checksum = nil, content_type = nil, repository = nil) content_unit_href = nil content_type = ::Katello::RepositoryTypeManager.find_content_type(content_type) if checksum && !content_type.repository_import_on_upload content_backend_service = SmartProxy.pulp_primary.content_service(content_type) if repository&.generic? content_list = content_backend_service.content_api(repository.repository_type, content_type).list('sha256': checksum) else content_list = content_backend_service.content_api.list("sha256": checksum) end content_unit_href = content_list.results.first.pulp_href unless content_list.results.empty? return {"content_unit_href" => content_unit_href} if content_unit_href end upload_href = uploads_api.create(upload_class.new(size: size)).pulp_href {"upload_id" => upload_href.split("/").last} end |
.delete_upload(upload_href) ⇒ Object
26 27 28 |
# File 'app/services/katello/pulp3/content.rb', line 26 def delete_upload(upload_href) #Commit deletes upload request for pulp3. Not needed other than to implement abstract method. end |
.upload_chunk(upload_href, offset, content, size) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/services/katello/pulp3/content.rb', line 30 def upload_chunk(upload_href, offset, content, size) upload_href = "/pulp/api/v3/uploads/" + upload_href + "/" offset = offset.try(:to_i) size = size.try(:to_i) begin filechunk = Tempfile.new('filechunk', :encoding => 'ascii-8bit') filechunk.write(content) filechunk.flush actual_chunk_size = File.size(filechunk) uploads_api.update(content_range(offset, offset + actual_chunk_size - 1, size), upload_href, filechunk) ensure filechunk.close filechunk.unlink end end |