Class: Runcible::Extensions::Repository

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

Class Method Summary collapse

Methods inherited from Resources::Repository

associate_distributor, associate_importer, create, delete, delete_distributor, delete_importer, path, publish, 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, config=, generate_log_message, generate_payload, get_response, log_debug, log_exception, process_response, required_params

Class 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



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

def self.create_or_update_schedule(repo_id, type, schedule)
  schedules = Runcible::Resources::RepositorySchedule.list(repo_id, type)
  if schedules.empty?
    Runcible::Resources::RepositorySchedule.create(repo_id, type, schedule)
  else
    Runcible::Resources::RepositorySchedule.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



43
44
45
# File 'lib/runcible/extensions/repository.rb', line 43

def self.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



34
35
36
# File 'lib/runcible/extensions/repository.rb', line 34

def self.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



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/runcible/extensions/repository.rb', line 54

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

  optional[:distributors] = distributors.collect do |d|
    if d.is_a?(Distributor)
      {'distributor_type' => d.type_id,
        "distributor_config" => d.config,
        "auto_publish" => d.auto_publish,
        "distributor_id" => d.id
      }
    else
      {'distributor_type' => d['type_id'],
       "distributor_config" => d['config'],
       "auto_publish" => d['auto_publish'],
       "distributor_id" => d['id']
      }
    end
  end if !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



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

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

  self.unit_search(id, criteria).collect{|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



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

def self.errata(id)
   criteria = {:type_ids=>[Runcible::Extensions::Errata.content_type]}
   self.unit_search(id, criteria).collect{|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



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

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

   self.unit_search(id, criteria).collect{|i| i['unit_id']}
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



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

def self.package_categories(id)
  criteria = {:type_ids=>[Runcible::Extensions::PackageCategory.content_type]}
  self.unit_search(id, criteria).collect{|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



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

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

  self.unit_search(id, criteria).collect{|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



251
252
253
254
255
256
257
# File 'lib/runcible/extensions/repository.rb', line 251

def self.publish_all(repo_id)
  to_ret = []
  self.retrieve_with_details(repo_id)['distributors'].each do |d|
    to_ret << self.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



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

def self.publish_status(repo_id)
  Runcible::Resources::Task.list(["pulp:repository:#{repo_id}", "pulp:action:publish"])
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)


240
241
242
243
244
245
# File 'lib/runcible/extensions/repository.rb', line 240

def self.remove_schedules(repo_id, type)
  schedules = Runcible::Resources::RepositorySchedule.list(repo_id, type)
  schedules.each do |schedule|
    Runcible::Resources::RepositorySchedule.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



263
264
265
# File 'lib/runcible/extensions/repository.rb', line 263

def self.retrieve_with_details(repo_id)
  self.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



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/runcible/extensions/repository.rb', line 114

def self.rpm_ids(id)
  # lazy evaluated iterator from zero to infinite
  pages = Enumerator.new { |y| page = 0; loop { y << page; page += 1 } }

  # TODO this is hotfix, pagination support should be added to Runcible
  pages.inject([]) 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    = self.unit_search(id, criteria).collect { |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



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

def self.rpms(id)
  criteria = {:type_ids=>[Runcible::Extensions::Rpm.content_type]}
  self.unit_search(id, criteria).collect{|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



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

def self.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'] ]
          }}
  self.unit_search(id, criteria).collect{|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



102
103
104
105
106
107
# File 'lib/runcible/extensions/repository.rb', line 102

def self.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



86
87
88
# File 'lib/runcible/extensions/repository.rb', line 86

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