Class: Katello::Pulp3::RepositoryMirror
- Inherits:
-
Object
- Object
- Katello::Pulp3::RepositoryMirror
- Defined in:
- app/services/katello/pulp3/repository_mirror.rb
Instance Attribute Summary collapse
-
#repo_service ⇒ Object
Returns the value of attribute repo_service.
Instance Method Summary collapse
- #backend_object_name ⇒ Object
- #common_remote_options ⇒ Object
- #compute_remote_options ⇒ Object
- #content_guard_href ⇒ Object
- #count_by_pulpcore_type(service_class) ⇒ Object
- #create(_force = false) ⇒ Object
- #create_distribution(path) ⇒ Object
- #create_entities ⇒ Object
- #create_publication ⇒ Object
- #create_remote ⇒ Object
- #create_version(options = {}) ⇒ Object
- #delete(href = repository_href) ⇒ Object
- #distribution_options(path, options = {}) ⇒ Object
- #fetch_remote ⇒ Object
- #fetch_repository ⇒ Object
-
#initialize(repository_service) ⇒ RepositoryMirror
constructor
A new instance of RepositoryMirror.
- #latest_content_counts ⇒ Object
- #needs_updates? ⇒ Boolean
- #publication_href ⇒ Object
- #pulp3_enabled_repo_types ⇒ Object
- #refresh_distributions(_options = {}) ⇒ Object
- #refresh_entities ⇒ Object
- #remote_feed_url ⇒ Object
- #remote_href ⇒ Object
- #remote_options ⇒ Object
- #repair ⇒ Object
- #repository_href ⇒ Object
- #ssl_remote_options ⇒ Object
- #sync(options = {}) ⇒ Object
- #update ⇒ Object
- #version_href ⇒ Object
Constructor Details
#initialize(repository_service) ⇒ RepositoryMirror
Returns a new instance of RepositoryMirror.
11 12 13 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 11 def initialize(repository_service) @repo_service = repository_service end |
Instance Attribute Details
#repo_service ⇒ Object
Returns the value of attribute repo_service.
4 5 6 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 4 def repo_service @repo_service end |
Instance Method Details
#backend_object_name ⇒ Object
20 21 22 23 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 20 def backend_object_name #Create repos in pulp3 instance with the name as this repo's pulp_id repo.pulp_id end |
#common_remote_options ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 141 def = { name: backend_object_name, total_timeout: Setting[:sync_total_timeout], connect_timeout: Setting[:sync_connect_timeout_v2], sock_connect_timeout: Setting[:sync_sock_connect_timeout], sock_read_timeout: Setting[:sync_sock_read_timeout], rate_limit: Setting[:download_rate_limit], } .merge!({download_concurrency: repo.download_concurrency}) if repo.download_concurrency .merge!() end |
#compute_remote_options ⇒ Object
119 120 121 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 119 def repo_service.() end |
#content_guard_href ⇒ Object
15 16 17 18 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 15 def content_guard_href content_guard_api = ::Katello::Pulp3::Api::ContentGuard.new(smart_proxy) content_guard_api.list&.results&.first&.pulp_href end |
#count_by_pulpcore_type(service_class) ⇒ Object
207 208 209 210 211 212 213 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 207 def count_by_pulpcore_type(service_class) # Currently only supports SRPMs and Docker Manifest Lists fail NotImplementedError unless [::Katello::Pulp3::Srpm, ::Katello::Pulp3::DockerManifestList].include?(service_class) count = service_class.content_api(smart_proxy).list(service_class.(limit: 1, fields: ['count'], repository_version: version_href)).count return 0 if count.nil? count end |
#create(_force = false) ⇒ Object
53 54 55 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 53 def create(_force = false) api.repositories_api.create(name: backend_object_name) end |
#create_distribution(path) ⇒ Object
227 228 229 230 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 227 def create_distribution(path) distribution_data = api.distribution_class.new((path)) repo_service.distributions_api.create(distribution_data) end |
#create_entities ⇒ Object
48 49 50 51 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 48 def create_entities create create_remote unless fetch_remote end |
#create_publication ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 170 def create_publication if (href = version_href) if repo_service.repo.content_type == "deb" publication_data = api.publication_verbatim_class.new({repository_version: href}) api.publications_verbatim_api.create(publication_data) else publication_data = api.publication_class.new(repository_version: href) api.publications_api.create(publication_data) end end end |
#create_remote ⇒ Object
112 113 114 115 116 117 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 112 def create_remote # Do not consider remotes_uln_api, since the Katello server is not a ULN server. Even if the sync # to Katello used ULN, the sync from Katello server to smart proxy will use a normal RPM remote! remote_file_data = @repo_service.api.remote_class.new() api.remotes_api.create(remote_file_data) end |
#create_version(options = {}) ⇒ Object
88 89 90 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 88 def create_version( = {}) api.repository_versions_api.create(repository_href, ) end |
#delete(href = repository_href) ⇒ Object
61 62 63 64 65 66 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 61 def delete(href = repository_href) api.repositories_api.delete(href) if href rescue api.api_exception_class => e raise e if e.code != 404 nil end |
#distribution_options(path, options = {}) ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 92 def (path, = {}) ret = { base_path: path, name: "#{backend_object_name}", } ret[:content_guard] = repo.unprotected ? nil : content_guard_href ret[:publication] = [:publication] if .key? :publication ret[:repository_version] = [:repository_version] if .key? :repository_version ret end |
#fetch_remote ⇒ Object
123 124 125 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 123 def fetch_remote api.remotes_list(name: backend_object_name).first end |
#fetch_repository ⇒ Object
72 73 74 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 72 def fetch_repository repo_service.api.list_all(name: backend_object_name).first end |
#latest_content_counts ⇒ Object
215 216 217 218 219 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 215 def latest_content_counts version_pulp_href = version_href return unless version_pulp_href api.repository_versions_api.read(version_pulp_href)&.content_summary&.present end |
#needs_updates? ⇒ Boolean
37 38 39 40 41 42 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 37 def needs_updates? remote = fetch_remote return true if remote.blank? = repo_service. .keys.any? { |key| remote.send(key) != [key] } end |
#publication_href ⇒ Object
80 81 82 83 84 85 86 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 80 def publication_href if repo_service.repo.content_type == "deb" api.publications_verbatim_api.list(:repository_version => version_href).results.first&.pulp_href else api.publications_api.list(:repository_version => version_href).results.first&.pulp_href end end |
#pulp3_enabled_repo_types ⇒ Object
221 222 223 224 225 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 221 def pulp3_enabled_repo_types Katello::RepositoryTypeManager.enabled_repository_types.values.select do |repository_type| smart_proxy.pulp3_repository_type_support?(repository_type) end end |
#refresh_distributions(_options = {}) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 182 def refresh_distributions( = {}) path = repo_service.relative_path dist_params = {} if repo_service.repo.repository_type.pulp3_skip_publication dist_params[:repository_version] = version_href fail "could not lookup a version_href for repo #{repo_service.repo.id}" if version_href.nil? else dist_params[:publication] = publication_href fail "Could not lookup a publication_href for repo #{repo_service.repo.id}" if publication_href.nil? end = (path, dist_params) .delete(:content_guard) if repo_service.repo.content_type == "docker" if (distro = repo_service.lookup_distributions(base_path: path).first) || (distro = repo_service.lookup_distributions(name: "#{backend_object_name}").first) # update dist = .except(:name) api.distributions_api.partial_update(distro.pulp_href, ) else # create dist distribution_data = api.distribution_class.new() api.distributions_api.create(distribution_data) end end |
#refresh_entities ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 25 def refresh_entities href = remote_href if href # Do not consider remotes_uln_api, since the Katello server is not a ULN server. Even if the sync # to Katello used ULN, the sync from Katello server to smart proxy will use a normal RPM remote! [api.remotes_api.partial_update(href, )] else create_remote [] end end |
#remote_feed_url ⇒ Object
164 165 166 167 168 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 164 def remote_feed_url uri = ::SmartProxy.pulp_primary.pulp3_uri! uri.path = repo_service.partial_repo_path uri.to_s end |
#remote_href ⇒ Object
44 45 46 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 44 def remote_href fetch_remote.try(:pulp_href) end |
#remote_options ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 103 def = .merge!(url: remote_feed_url) if ( = repo_service.try(:mirror_remote_options)) .merge!() end end |
#repair ⇒ Object
232 233 234 235 236 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 232 def repair data = api.repair_class.new fail "Could not lookup a version_href for repo #{repo_service.repo.id}" if version_href.nil? api.repository_versions_api.repair(version_href, data) end |
#repository_href ⇒ Object
68 69 70 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 68 def repository_href fetch_repository.try(:pulp_href) end |
#ssl_remote_options ⇒ Object
154 155 156 157 158 159 160 161 162 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 154 def ueber_cert = ::Cert::Certs.ueber_cert(repo.root.organization) { client_cert: ueber_cert[:cert], client_key: ueber_cert[:key], ca_cert: ::Cert::Certs.ca_cert, tls_validation: true, } end |
#sync(options = {}) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 127 def sync( = {}) sync_params = repo_service.sync_url_params() sync_params[:remote] = remote_href if repo.yum? sync_params.delete(:skip_types) if sync_params[:skip_types] sync_params[:sync_policy] = 'mirror_complete' else sync_params.delete(:sync_policy) sync_params[:mirror] = true end repository_sync_url_data = api.repository_sync_url_class.new(sync_params) [api.repositories_api.sync(repository_href, repository_sync_url_data)] end |
#update ⇒ Object
57 58 59 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 57 def update api.repositories_api.update(repository_href, name: backend_object_name) end |
#version_href ⇒ Object
76 77 78 |
# File 'app/services/katello/pulp3/repository_mirror.rb', line 76 def version_href fetch_repository&.latest_version_href end |