Class: Runcible::Extensions::Repository
- Inherits:
-
Resources::Repository
- Object
- Base
- Resources::Repository
- Runcible::Extensions::Repository
- Defined in:
- lib/runcible/extensions/repository.rb
Instance Method Summary collapse
-
#create_or_update_schedule(repo_id, type, schedule) ⇒ RestClient::Response
Creates or updates a sync schedule for a repository.
-
#create_with_distributors(id, distributors) ⇒ RestClient::Response
Utility function that allows distributors to be added at repository creation time.
-
#create_with_importer(id, importer) ⇒ RestClient::Response
Utility function that allows an importer to be added at repository creation time.
-
#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.
-
#distributions(id) ⇒ RestClient::Response
Retrieves the distributions for a single repository.
-
#errata(id) ⇒ RestClient::Response
Retrieves the errata for a single repository.
-
#errata_ids(id) ⇒ RestClient::Response
Retrieves the errata IDs for a single repository.
-
#package_categories(id) ⇒ RestClient::Response
Retrieves the package group categoriess for a single repository.
-
#package_groups(id) ⇒ RestClient::Response
Retrieves the package groups for a single repository.
-
#publish_all(repo_id) ⇒ RestClient::Response
Publishes a repository for all of it’s distributors.
-
#publish_status(repo_id) ⇒ RestClient::Response
Retrieves the publish status for a repository.
-
#puppet_module_ids(id) ⇒ RestClient::Response
Retrieves the puppet module IDs for a single repository.
-
#puppet_modules(id) ⇒ RestClient::Response
Retrieves the puppet modules for a single repository.
-
#regenerate_applicability_by_ids(ids) ⇒ RestClient::Response
Regenerate the applicability for consumers bound to a given set of repositories.
-
#remove_schedules(repo_id, type) ⇒ RestClient::Response
Removes a scheduled sync from a repository.
-
#retrieve_with_details(repo_id) ⇒ RestClient::Response
Retrieves a repository with details that include importer and distributors.
-
#rpm_ids(id) ⇒ Array<String>
Retrieves the RPM IDs for a single repository.
-
#rpms(id) ⇒ RestClient::Response
Retrieves the RPMs for a single repository.
-
#rpms_by_nvre(id, name, version = nil, release = nil, epoch = nil) ⇒ RestClient::Response
Retrieves the RPMs by NVRE for a single repository.
-
#search_by_repository_ids(repository_ids) ⇒ RestClient::Response
Retrieves a set of repositories by their IDs.
-
#sync_status(repo_id) ⇒ RestClient::Response
Retrieves the sync status for a repository.
Methods inherited from Resources::Repository
#associate_distributor, #associate_importer, #create, #delete, #delete_distributor, #delete_importer, 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, #format_payload_json, #generate_log_message, #generate_payload, #get_response, #initialize, #lazy_config=, #log_debug, #log_exception, #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
265 266 267 268 269 270 271 272 |
# File 'lib/runcible/extensions/repository.rb', line 265 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
43 44 45 |
# File 'lib/runcible/extensions/repository.rb', line 43 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
34 35 36 |
# File 'lib/runcible/extensions/repository.rb', line 34 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
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 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/runcible/extensions/repository.rb', line 54 def create_with_importer_and_distributors(id, importer, distributors=[], optional={}) if importer.is_a?(Runcible::Models::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 repo_type = if importer.methods.include?(:repo_type) importer.repo_type elsif importer.is_a?(Hash) && importer.has_key?(:repo_type) importer[:repo_type] else nil end if optional.has_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.collect do |d| if d.is_a?(Runcible::Models::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
214 215 216 217 218 |
# File 'lib/runcible/extensions/repository.rb', line 214 def distributions(id) criteria = {:type_ids=>[Runcible::Extensions::Distribution.content_type]} unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access} end |
#errata(id) ⇒ RestClient::Response
Retrieves the errata for a single repository
205 206 207 208 |
# File 'lib/runcible/extensions/repository.rb', line 205 def errata(id) criteria = {:type_ids=>[Runcible::Extensions::Errata.content_type]} 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
194 195 196 197 198 199 |
# File 'lib/runcible/extensions/repository.rb', line 194 def errata_ids(id) criteria = {:type_ids=>[Runcible::Extensions::Errata.content_type], :fields=>{:unit=>[], :association=>['unit_id']}} unit_search(id, criteria).collect{|i| i['unit_id']} end |
#package_categories(id) ⇒ RestClient::Response
Retrieves the package group categoriess for a single repository
234 235 236 237 |
# File 'lib/runcible/extensions/repository.rb', line 234 def package_categories(id) criteria = {:type_ids=>[Runcible::Extensions::PackageCategory.content_type]} 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
224 225 226 227 228 |
# File 'lib/runcible/extensions/repository.rb', line 224 def package_groups(id) criteria = {:type_ids=>[Runcible::Extensions::PackageGroup.content_type]} 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
290 291 292 293 294 295 296 |
# File 'lib/runcible/extensions/repository.rb', line 290 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
107 108 109 |
# File 'lib/runcible/extensions/repository.rb', line 107 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
243 244 245 246 247 248 |
# File 'lib/runcible/extensions/repository.rb', line 243 def puppet_module_ids(id) criteria = {:type_ids=>[Runcible::Extensions::PuppetModule.content_type], :fields=>{:unit=>[], :association=>['unit_id']}} unit_search(id, criteria).collect{|i| i['unit_id']} end |
#puppet_modules(id) ⇒ RestClient::Response
Retrieves the puppet modules for a single repository
254 255 256 257 |
# File 'lib/runcible/extensions/repository.rb', line 254 def puppet_modules(id) criteria = {:type_ids=>[Runcible::Extensions::PuppetModule.content_type]} unit_search(id, criteria).collect{|i| i['metadata'].with_indifferent_access} end |
#regenerate_applicability_by_ids(ids) ⇒ RestClient::Response
Regenerate the applicability for consumers bound to a given set of repositories
310 311 312 313 314 315 |
# File 'lib/runcible/extensions/repository.rb', line 310 def regenerate_applicability_by_ids(ids) criteria = { 'repo_criteria' => { 'filters' => { 'id' => { '$in' => ids } } } } regenerate_applicability(criteria) end |
#remove_schedules(repo_id, type) ⇒ RestClient::Response
Removes a scheduled sync from a repository
279 280 281 282 283 284 |
# File 'lib/runcible/extensions/repository.rb', line 279 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
302 303 304 |
# File 'lib/runcible/extensions/repository.rb', line 302 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
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/runcible/extensions/repository.rb', line 128 def rpm_ids(id) criteria = {:type_ids=>[Runcible::Extensions::Rpm.content_type], :fields=>{:unit=>[], :association=>['unit_id']}} self.unit_search(id, criteria).collect{|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 { |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 = 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
158 159 160 161 |
# File 'lib/runcible/extensions/repository.rb', line 158 def rpms(id) criteria = {:type_ids=>[Runcible::Extensions::Rpm.content_type]} 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
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/runcible/extensions/repository.rb', line 171 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).collect{|p| p['metadata'].with_indifferent_access} end |
#search_by_repository_ids(repository_ids) ⇒ RestClient::Response
Retrieves a set of repositories by their IDs
115 116 117 118 119 120 |
# File 'lib/runcible/extensions/repository.rb', line 115 def search_by_repository_ids(repository_ids) criteria = {:filters => { "id" => {"$in" => repository_ids}} } search(criteria) end |