Class: Runcible::Extensions::Repository

Inherits:
Resources::Repository show all
Defined in:
lib/runcible/extensions/repository.rb

Instance Attribute Summary

Attributes inherited from Base

#logs

Instance Method Summary collapse

Methods inherited from Resources::Repository

#associate_distributor, #associate_importer, #create, #delete, #delete_distributor, #delete_importer, #download, path, #publish, #regenerate_applicability, #retrieve, #retrieve_all, #search, #sync, #sync_history, #unassociate_units, #unit_copy, #unit_search, #update, #update_distributor, #update_importer

Methods inherited from Base

#add_http_auth_header, #add_oauth_header, #call, #combine_get_params, #config, #exception_to_log, #format_payload_json, #generate_payload, #get_response, #initialize, #lazy_config=, #log_debug, #log_exception, #log_info, #logger, #path, #process_response, #required_params

Constructor Details

This class inherits a constructor from Runcible::Base

Instance Method Details

#create_or_update_schedule(repo_id, type, schedule) ⇒ RestClient::Response

Creates or updates a sync schedule for a repository

Parameters:

  • repo_id (String)

    the ID of the repository

  • type (String)

    the importer type

  • schedule (String)

    the time as an iso8601 interval

Returns:

  • (RestClient::Response)

    the newly created or updated schedule



376
377
378
379
380
381
382
383
384
# File 'lib/runcible/extensions/repository.rb', line 376

def create_or_update_schedule(repo_id, type, schedule)
  schedules = Runcible::Resources::RepositorySchedule.new(self.config).list(repo_id, type)
  if schedules.empty?
    Runcible::Resources::RepositorySchedule.new(self.config).create(repo_id, type, schedule)
  else
    Runcible::Resources::RepositorySchedule.new(self.config).update(repo_id, type,
                                                schedules[0]['_id'], :schedule => schedule)
  end
end

#create_with_distributors(id, distributors) ⇒ RestClient::Response

Utility function that allows distributors to be added at repository creation time

Parameters:

  • id (String)

    the id of the repository being created

  • distributors (Array)

    an array of hashes representing distributors or an array of Distributor objects

Returns:

  • (RestClient::Response)

    the created repository



20
21
22
# File 'lib/runcible/extensions/repository.rb', line 20

def create_with_distributors(id, distributors)
  create_with_importer_and_distributors(id, nil, distributors)
end

#create_with_importer(id, importer) ⇒ RestClient::Response

Utility function that allows an importer to be added at repository creation time

Parameters:

  • id (String)

    the id of the repository being created

  • importer (Hash, Runcible::Extensions::Importer)

    either a hash representing an importer or an Importer object

Returns:

  • (RestClient::Response)

    the created repository



10
11
12
# File 'lib/runcible/extensions/repository.rb', line 10

def create_with_importer(id, importer)
  create_with_importer_and_distributors(id, importer)
end

#create_with_importer_and_distributors(id, importer, distributors = [], optional = {}) ⇒ RestClient::Response

Utility function that allows an importer and distributors to be added at repository creation time

Parameters:

  • id (String)

    the id of the repository being created

  • importer (Hash, Runcible::Extensions::Importer)

    either a hash representing an importer or an Importer object

  • distributors (Array) (defaults to: [])

    an array of hashes representing distributors or an array of Distributor objects

  • optional (Hash) (defaults to: {})

    container for all optional parameters

Returns:

  • (RestClient::Response)

    the created repository



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/runcible/extensions/repository.rb', line 33

def create_with_importer_and_distributors(id, importer, distributors = [], optional = {})
  if importer && importer.is_a?(Runcible::Models::Importer)
    optional[:importer_type_id] = importer.id
    optional[:importer_config] = importer.config
  elsif importer
    optional[:importer_type_id] = importer.delete('id') || importer.delete(:id)
    optional[:importer_config] = importer
  end

  repo_type = if importer.methods.include?(:repo_type)
                importer.repo_type
              elsif importer.is_a?(Hash) && importer.key?(:repo_type)
                importer[:repo_type]
              end

  if optional.key?(:importer_type_id) && repo_type
    # pulp needs _repo-type in order to determine the type of repo to create.
    optional[:notes] = { '_repo-type' => importer.repo_type }
  end

  optional[:distributors] = distributors.map do |d|
    if d.is_a?(Runcible::Models::Distributor)
      {'distributor_type_id' => d.type_id,
       'distributor_config' => d.config,
       'auto_publish' => d.auto_publish,
       'distributor_id' => d.id
      }
    else
      {'distributor_type_id' => d['type_id'],
       'distributor_config' => d['config'],
       'auto_publish' => d['auto_publish'],
       'distributor_id' => d['id']
      }
    end
  end unless distributors.empty?
  optional[:id] = id
  create(id, optional)
end

#distributions(id) ⇒ RestClient::Response

Retrieves the distributions for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository distributions



196
197
198
199
200
# File 'lib/runcible/extensions/repository.rb', line 196

def distributions(id)
  criteria = {:type_ids => [Runcible::Extensions::Distribution.content_type]}

  unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
end

#docker_image_ids(id) ⇒ RestClient::Response

Retrieves the docker image IDs for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository docker image IDs



325
326
327
328
329
330
# File 'lib/runcible/extensions/repository.rb', line 325

def docker_image_ids(id)
  criteria = {:type_ids => [Runcible::Extensions::DockerImage.content_type],
              :fields => {:unit => [], :association => ['unit_id']}}

  unit_search(id, criteria).map { |i| i['unit_id'] }
end

#docker_images(id) ⇒ RestClient::Response

Retrieves the docker images for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository docker images



336
337
338
339
# File 'lib/runcible/extensions/repository.rb', line 336

def docker_images(id)
  criteria = {:type_ids => [Runcible::Extensions::DockerImage.content_type]}
  unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
end

#docker_manifest_ids(id) ⇒ RestClient::Response

Retrieves the docker manifest IDs for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository docker manifest IDs



265
266
267
268
269
270
# File 'lib/runcible/extensions/repository.rb', line 265

def docker_manifest_ids(id)
  criteria = {:type_ids => [Runcible::Extensions::DockerManifest.content_type],
              :fields => {:unit => [], :association => ['unit_id']}}

  unit_search(id, criteria).map { |i| i['unit_id'] }
end

#docker_manifest_list_ids(id) ⇒ RestClient::Response

Retrieves the docker manifest list IDs for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository docker manifest IDs



285
286
287
288
289
290
# File 'lib/runcible/extensions/repository.rb', line 285

def docker_manifest_list_ids(id)
  criteria = {:type_ids => [Runcible::Extensions::DockerManifestList.content_type],
              :fields => {:unit => [], :association => ['unit_id']}}

  unit_search(id, criteria).map { |i| i['unit_id'] }
end

#docker_manifest_lists(id) ⇒ RestClient::Response

Retrieves the docker manifest lists for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository docker manifests



296
297
298
299
# File 'lib/runcible/extensions/repository.rb', line 296

def docker_manifest_lists(id)
  criteria = {:type_ids => [Runcible::Extensions::DockerManifestList.content_type]}
  unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
end

#docker_manifests(id) ⇒ RestClient::Response

Retrieves the docker manifests for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository docker manifests



276
277
278
279
# File 'lib/runcible/extensions/repository.rb', line 276

def docker_manifests(id)
  criteria = {:type_ids => [Runcible::Extensions::DockerManifest.content_type]}
  unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
end

#docker_tag_ids(id) ⇒ RestClient::Response

Retrieves the docker tag IDs for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository docker tag IDs



305
306
307
308
309
310
# File 'lib/runcible/extensions/repository.rb', line 305

def docker_tag_ids(id)
  criteria = {:type_ids => [Runcible::Extensions::DockerTag.content_type],
              :fields => {:unit => [], :association => ['unit_id']}}

  unit_search(id, criteria).map { |i| i['unit_id'] }
end

#docker_tags(id) ⇒ RestClient::Response

Retrieves the docker tags for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository docker tags



316
317
318
319
# File 'lib/runcible/extensions/repository.rb', line 316

def docker_tags(id)
  criteria = {:type_ids => [Runcible::Extensions::DockerTag.content_type]}
  unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
end

#errata(id) ⇒ RestClient::Response

Retrieves the errata for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository errata



187
188
189
190
# File 'lib/runcible/extensions/repository.rb', line 187

def errata(id)
  criteria = {:type_ids => [Runcible::Extensions::Errata.content_type]}
  unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
end

#errata_ids(id) ⇒ RestClient::Response

Retrieves the errata IDs for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository errata IDs



176
177
178
179
180
181
# File 'lib/runcible/extensions/repository.rb', line 176

def errata_ids(id)
  criteria = {:type_ids => [Runcible::Extensions::Errata.content_type],
              :fields => {:unit => [], :association => ['unit_id']}}

  unit_search(id, criteria).map { |i| i['unit_id'] }
end

#file_ids(id) ⇒ RestClient::Response

Retrieves the file IDs for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository file IDs



354
355
356
357
358
359
# File 'lib/runcible/extensions/repository.rb', line 354

def file_ids(id)
  criteria = {:type_ids => [Runcible::Extensions::File.content_type],
              :fields => {:unit => [], :association => ['unit_id']}}

  unit_search(id, criteria).map { |i| i['unit_id'] }
end

#files(id) ⇒ RestClient::Response

Retrieves the files for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository files



365
366
367
368
# File 'lib/runcible/extensions/repository.rb', line 365

def files(id)
  criteria = {:type_ids => [Runcible::Extensions::File.content_type]}
  unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
end

#ostree_branch_ids(id) ⇒ RestClient::Response

Retrieves the ostree branch IDs for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository ostree branch IDs



245
246
247
248
249
250
# File 'lib/runcible/extensions/repository.rb', line 245

def ostree_branch_ids(id)
  criteria = {:type_ids => [Runcible::Extensions::OstreeBranch.content_type],
              :fields => {:unit => [], :association => ['unit_id']}}

  unit_search(id, criteria).map { |i| i['unit_id'] }
end

#ostree_branches(id) ⇒ RestClient::Response

Retrieves the ostree branches for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository ostree branches



256
257
258
259
# File 'lib/runcible/extensions/repository.rb', line 256

def ostree_branches(id)
  criteria = {:type_ids => [Runcible::Extensions::OstreeBranch.content_type]}
  unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
end

#package_categories(id) ⇒ RestClient::Response

Retrieves the package group categoriess for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository package group categories



216
217
218
219
# File 'lib/runcible/extensions/repository.rb', line 216

def package_categories(id)
  criteria = {:type_ids => [Runcible::Extensions::PackageCategory.content_type]}
  unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
end

#package_groups(id) ⇒ RestClient::Response

Retrieves the package groups for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository package groups



206
207
208
209
210
# File 'lib/runcible/extensions/repository.rb', line 206

def package_groups(id)
  criteria = {:type_ids => [Runcible::Extensions::PackageGroup.content_type]}

  unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
end

#publish_all(repo_id) ⇒ RestClient::Response

Publishes a repository for all of it’s distributors

Parameters:

  • repo_id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    set of tasks representing each publish



402
403
404
405
406
407
408
# File 'lib/runcible/extensions/repository.rb', line 402

def publish_all(repo_id)
  to_ret = []
  retrieve_with_details(repo_id)['distributors'].each do |d|
    to_ret << publish(repo_id, d['id'])
  end
  to_ret
end

#publish_status(repo_id) ⇒ RestClient::Response

Retrieves the publish status for a repository

Parameters:

  • repo_id (String)

    the repository ID

Returns:

  • (RestClient::Response)

    a task representing the sync status



84
85
86
# File 'lib/runcible/extensions/repository.rb', line 84

def publish_status(repo_id)
  Runcible::Resources::Task.new(self.config).list(["pulp:repository:#{repo_id}", 'pulp:action:publish'])
end

#puppet_module_ids(id) ⇒ RestClient::Response

Retrieves the puppet module IDs for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository puppet module IDs



225
226
227
228
229
230
# File 'lib/runcible/extensions/repository.rb', line 225

def puppet_module_ids(id)
  criteria = {:type_ids => [Runcible::Extensions::PuppetModule.content_type],
              :fields => {:unit => [], :association => ['unit_id']}}

  unit_search(id, criteria).map { |i| i['unit_id'] }
end

#puppet_modules(id) ⇒ RestClient::Response

Retrieves the puppet modules for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository puppet modules



236
237
238
239
# File 'lib/runcible/extensions/repository.rb', line 236

def puppet_modules(id)
  criteria = {:type_ids => [Runcible::Extensions::PuppetModule.content_type]}
  unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
end

#regenerate_applicability_by_ids(ids, parallel = false) ⇒ RestClient::Response

Regenerate the applicability for consumers bound to a given set of repositories

Parameters:

  • ids (String, Array)

    array of repo ids

  • parallel (boolean) (defaults to: false)

    when true run the regeneration in parallel and return a task group tracking the summary, when false run this operation serially and return a list of spawned tasks that are to be tracked separately. False is the default option.

Returns:

  • (RestClient::Response)


427
428
429
430
431
432
433
# File 'lib/runcible/extensions/repository.rb', line 427

def regenerate_applicability_by_ids(ids, parallel = false)
  criteria = {
    'parallel' => parallel,
    'repo_criteria' => { 'filters' => { 'id' => { '$in' => ids } } }
  }
  regenerate_applicability(criteria)
end

#remove_schedules(repo_id, type) ⇒ RestClient::Response

Removes a scheduled sync from a repository

Parameters:

  • repo_id (String)

    the ID of the repository

  • type (String)

    the importer type

Returns:

  • (RestClient::Response)


391
392
393
394
395
396
# File 'lib/runcible/extensions/repository.rb', line 391

def remove_schedules(repo_id, type)
  schedules = Runcible::Resources::RepositorySchedule.new(self.config).list(repo_id, type)
  schedules.each do |schedule|
    Runcible::Resources::RepositorySchedule.new(self.config).delete(repo_id, type, schedule['_id'])
  end
end

#retrieve_with_details(repo_id) ⇒ RestClient::Response

Retrieves a repository with details that include importer and distributors

Parameters:

  • repo_id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the repository with full details



414
415
416
# File 'lib/runcible/extensions/repository.rb', line 414

def retrieve_with_details(repo_id)
  retrieve(repo_id, :details => true)
end

#rpm_ids(id) ⇒ Array<String>

Retrieves the RPM IDs for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (Array<String>)

    the array of repository RPM IDs



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/runcible/extensions/repository.rb', line 104

def rpm_ids(id)
  criteria = {:type_ids => [Runcible::Extensions::Rpm.content_type],
              :fields => {:unit => [], :association => ['unit_id']}}
  self.unit_search(id, criteria).map { |i| i['unit_id'] }
rescue RestClient::RequestTimeout
  self.logger.warn('Call to rpm_ids timed out')
  # lazy evaluated iterator from zero to infinite
  pages = Enumerator.new do |y|
    page = 0
    loop do
      y << page
      page += 1
    end
  end

  # TODO: this is hotfix, pagination support should be added to Runcible
  pages.reduce([]) do |rpm_ids, page|
    page_size = 500
    criteria  = { :type_ids => [Runcible::Extensions::Rpm.content_type],
                  :fields   => { :unit => [], :association => ['unit_id'] },
                  :limit    => page_size,
                  :skip     => 0 + page * page_size }
    result    = unit_search(id, criteria).map { |i| i['unit_id'] }
    rpm_ids.concat(result)
    if result.empty? || result.size < 500
      break rpm_ids
    else
      rpm_ids
    end
  end
end

#rpms(id) ⇒ RestClient::Response

Retrieves the RPMs for a single repository

Parameters:

  • id (String)

    the ID of the repository

Returns:

  • (RestClient::Response)

    the set of repository RPMs



140
141
142
143
# File 'lib/runcible/extensions/repository.rb', line 140

def rpms(id)
  criteria = {:type_ids => [Runcible::Extensions::Rpm.content_type]}
  unit_search(id, criteria).map { |i| i['metadata'].with_indifferent_access }
end

#rpms_by_nvre(id, name, version = nil, release = nil, epoch = nil) ⇒ RestClient::Response

Retrieves the RPMs by NVRE for a single repository

Parameters:

  • id (String)

    the ID of the repository

  • name (String)

    the name of the RPMs

  • version (String) (defaults to: nil)

    the version of the RPMs

  • release (String) (defaults to: nil)

    the release of the RPMs

  • epoch (String) (defaults to: nil)

    the epoch of the RPMs

Returns:

  • (RestClient::Response)

    the set of repository RPMs



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/runcible/extensions/repository.rb', line 153

def rpms_by_nvre(id, name, version = nil, release = nil, epoch = nil)
  and_condition = []
  and_condition << {:name => name} if name
  and_condition << {:version => version} if version
  and_condition << {:release => release} if release
  and_condition << {:epoch => epoch} if epoch

  criteria = {:type_ids => [Runcible::Extensions::Rpm.content_type],
              :filters => {
                :unit => {
                  '$and' => and_condition
                }
              },
              :sort => {
                :unit => [['name', 'ascending'], ['version', 'descending']]
              }}
  unit_search(id, criteria).map { |p| p['metadata'].with_indifferent_access }
end

#search_by_repository_ids(repository_ids) ⇒ RestClient::Response

Retrieves a set of repositories by their IDs

Parameters:

  • repository_ids (Array)

    the repository ID

Returns:

  • (RestClient::Response)

    the set of repositories requested



92
93
94
95
96
97
# File 'lib/runcible/extensions/repository.rb', line 92

def search_by_repository_ids(repository_ids)
  criteria = {:filters =>
                { 'id' => {'$in' => repository_ids}}
             }
  search(criteria)
end

#sync_status(repo_id) ⇒ RestClient::Response

Retrieves the sync status for a repository

Parameters:

  • repo_id (String)

    the repository ID

Returns:

  • (RestClient::Response)

    a task representing the sync status



76
77
78
# File 'lib/runcible/extensions/repository.rb', line 76

def sync_status(repo_id)
  Runcible::Resources::Task.new(self.config).list(["pulp:repository:#{repo_id}", 'pulp:action:sync'])
end

#update_docker_tags(id, tags) ⇒ RestClient::Response

Updates the docker tags in a repo

Parameters:

  • id (String)

    the ID of the repository

  • tags (Hash)

    for an image in the following format the [=> <image hash>, :tag =>“value”]

Returns:

  • (RestClient::Response)


346
347
348
# File 'lib/runcible/extensions/repository.rb', line 346

def update_docker_tags(id, tags)
  update(id, :scratchpad => {:tags => tags})
end