Class: Katello::Pulp3::PulpContentUnit

Inherits:
Object
  • Object
show all
Defined in:
app/services/katello/pulp3/pulp_content_unit.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uuid) ⇒ PulpContentUnit

Returns a new instance of PulpContentUnit.



82
83
84
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 82

def initialize(uuid)
  self.uuid = uuid
end

Instance Attribute Details

#backend_dataObject



158
159
160
161
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 158

def backend_data
  @backend_data ||= fetch_backend_data
  @backend_data.try(:with_indifferent_access)
end

#uuidObject

Returns the value of attribute uuid.



79
80
81
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 79

def uuid
  @uuid
end

Class Method Details

.add_timestamps(rows) ⇒ Object



104
105
106
107
108
109
110
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 104

def self.add_timestamps(rows)
  rows.each do |row|
    row[:created_at] = DateTime.now
    row[:updated_at] = DateTime.now
  end
  rows
end

.backend_unit_identifierObject



71
72
73
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 71

def self.backend_unit_identifier
  nil
end

.content_apiObject

rubocop:enable Metrics/MethodLength



49
50
51
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 49

def self.content_api
  fail NotImplementedError
end

.content_api_create(opts = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 53

def self.content_api_create(opts = {})
  relative_path = opts.delete(:relative_path)
  if Katello::RepositoryTypeManager.generic_content_type?(opts[:content_type])
    repository_type = Katello::Repository.find(opts[:repository_id]).repository_type
    content_type = opts[:content_type]
    self.content_api(repository_type, content_type).create(relative_path, opts)
  elsif self.content_type == 'rpm' || self.content_type == 'srpm'
    # The pulp_rpm API bindings expect relative_path to be within the options hash.
    self.content_api.create(opts)
  else
    self.content_api.create(relative_path, opts)
  end
end

.content_typeObject



94
95
96
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 94

def self.content_type
  self::CONTENT_TYPE
end

.content_unit_list(page_opts) ⇒ Object



154
155
156
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 154

def self.content_unit_list(page_opts)
  self.content_api.list page_opts
end

.create_contentObject



67
68
69
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 67

def self.create_content
  fail NotImplementedError
end

.fetch_content_list(page_opts) ⇒ Object



167
168
169
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 167

def self.fetch_content_list(page_opts)
  content_unit_list page_opts
end

.find_duplicate_unit(repository, unit_type_id, file, checksum) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 171

def self.find_duplicate_unit(repository, unit_type_id, file, checksum)
  filter_label = :sha256
  path_label = :relative_path
  if unit_type_id == 'ostree_ref'
    filter_label = :checksum
  end
  if unit_type_id == 'rpm'
    filter_label = :pkg_id
    path_label = :location_href
  end
  content_backend_service = SmartProxy.pulp_primary.content_service(unit_type_id)
  duplicates_allowed = ::Katello::RepositoryTypeManager.find_content_type(unit_type_id).try(:duplicates_allowed)
  if repository.generic? && duplicates_allowed
    filename_key = ::Katello::RepositoryTypeManager.find_content_type(unit_type_id).filename_key
    duplicate_sha_path_content_list = content_backend_service.content_api(repository.repository_type, unit_type_id).list(
      filter_label => checksum,
      filename_key => file[:filename])
  elsif repository.generic?
    duplicate_sha_path_content_list = content_backend_service.content_api(repository.repository_type, unit_type_id).list(
      filter_label => checksum)
  elsif unit_type_id == 'deb'
    duplicate_sha_path_content_list = content_backend_service.content_api.list(filter_label => checksum)
  else
    duplicate_sha_path_content_list = content_backend_service.content_api.list(
      filter_label => checksum,
      path_label => file[:filename])
  end
  duplicate_sha_path_content_list
end

.katello_name_from_pulpcore_name(pulpcore_name, repo) ⇒ Object

rubocop:disable Metrics/MethodLength



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 11

def self.katello_name_from_pulpcore_name(pulpcore_name, repo)
  # Counts shouldn't be needed for more than the default generic content unit type.
  if repo.generic?
    generic_unit = repo.repository_type.default_managed_content_type
    if pulpcore_name == generic_unit.pulpcore_name
      return generic_unit.content_type
    end
  end

  case pulpcore_name
  when ::Katello::Pulp3::Rpm::PULPCORE_CONTENT_TYPE
    ::Katello::Rpm::CONTENT_TYPE
  when ::Katello::Pulp3::Srpm::PULPCORE_CONTENT_TYPE
    ::Katello::Srpm::CONTENT_TYPE
  when ::Katello::Pulp3::PackageGroup::PULPCORE_CONTENT_TYPE
    ::Katello::PackageGroup::CONTENT_TYPE
  when ::Katello::Pulp3::Erratum::PULPCORE_CONTENT_TYPE
    ::Katello::Erratum::CONTENT_TYPE
  when ::Katello::Pulp3::ModuleStream::PULPCORE_CONTENT_TYPE
    'module_stream'
  when ::Katello::Pulp3::DockerTag::PULPCORE_CONTENT_TYPE
    ::Katello::DockerTag::CONTENT_TYPE
  when ::Katello::Pulp3::DockerManifest::PULPCORE_CONTENT_TYPE
    ::Katello::DockerManifest::CONTENT_TYPE
  when ::Katello::Pulp3::DockerManifestList::PULPCORE_CONTENT_TYPE
    ::Katello::DockerManifestList::CONTENT_TYPE
  when ::Katello::Pulp3::FileUnit::PULPCORE_CONTENT_TYPE
    ::Katello::FileUnit::CONTENT_TYPE
  when ::Katello::Pulp3::Deb::PULPCORE_CONTENT_TYPE
    ::Katello::Deb::CONTENT_TYPE
  when ::Katello::Pulp3::AnsibleCollection::PULPCORE_CONTENT_TYPE
    ::Katello::AnsibleCollection::CONTENT_TYPE
  else
    pulpcore_name
  end
end

.model_classObject



86
87
88
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 86

def self.model_class
  Katello::RepositoryTypeManager.model_class(self)
end

.page_options(page_opts = {}) ⇒ Object



145
146
147
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 145

def self.page_options(page_opts = {})
  page_opts
end

.pulp_data(href) ⇒ Object



149
150
151
152
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 149

def self.pulp_data(href)
  content_unit = self.content_api.read(href)
  content_unit.as_json
end

.pulp_units_batch_all(content_unit_hrefs) ⇒ Object



112
113
114
115
116
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 112

def self.pulp_units_batch_all(content_unit_hrefs)
  Enumerator.new do |yielder|
    yielder.yield content_unit_hrefs.collect { |href| pulp_data(href) }
  end
end

.pulp_units_batch_for_repo(repository, options = {}) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 118

def self.pulp_units_batch_for_repo(repository, options = {})
  fetch_identifiers = options.fetch(:fetch_identifiers, false)
  page_size = options.fetch(:page_size, Setting[:bulk_load_size])
  repository_version_href = repository.version_href
  page_opts = { "offset" => 0, repository_version: repository_version_href, limit: page_size }
  page_opts[:fields] = self.const_get(:PULP_INDEXED_FIELDS).join(",") if self.constants.include?(:PULP_INDEXED_FIELDS)
  page_opts[:fields] = 'pulp_href' if fetch_identifiers
  response = {}
  Enumerator.new do |yielder|
    loop do
      page_opts = page_opts.with_indifferent_access
      break unless (
        (response["count"] && page_opts["offset"] < response["count"]) ||
        page_opts["offset"] == 0)
      page_opts = page_options page_opts
      if repository.generic?
        response = fetch_content_list page_opts, repository.repository_type, options[:content_type]
      else
        response = fetch_content_list page_opts
      end
      response = response.as_json.with_indifferent_access
      yielder.yield response[:results]
      page_opts[:offset] += page_size
    end
  end
end

.pulp_units_for_ids(content_unit_hrefs) ⇒ Object



98
99
100
101
102
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 98

def self.pulp_units_for_ids(content_unit_hrefs)
  Enumerator.new do |yielder|
    yielder.yield content_unit_hrefs.collect { |href| pulp_data(href).with_indifferent_access }
  end
end

.supports_id_fetch?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 75

def self.supports_id_fetch?
  true
end

.unit_identifierObject



90
91
92
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 90

def self.unit_identifier
  "pulp_href"
end

Instance Method Details

#fetch_backend_dataObject



163
164
165
# File 'app/services/katello/pulp3/pulp_content_unit.rb', line 163

def fetch_backend_data
  self.class.pulp_data(self.uuid)
end