Class: Katello::Pulp3::ContentViewVersion::Export
- Inherits:
-
Object
- Object
- Katello::Pulp3::ContentViewVersion::Export
show all
- Includes:
- ImportExportCommon
- Defined in:
- app/services/katello/pulp3/content_view_version/export.rb
Constant Summary
collapse
- SYNCABLE =
"syncable".freeze
- IMPORTABLE =
"importable".freeze
- UNDEFINED =
"undefined".freeze
- FORMATS =
Available formats for export (UNDEFINED excluded)
[SYNCABLE, IMPORTABLE].freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#api, #fetch_repository_info, #generate_id, #generate_name, #version_href_to_repository_href, #zero_version_href
Constructor Details
#initialize(smart_proxy:, content_view_version: nil, destination_server: nil, from_content_view_version: nil, repository: nil, base_path: nil) ⇒ Export
Returns a new instance of Export.
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 23
def initialize(smart_proxy:,
content_view_version: nil,
destination_server: nil,
from_content_view_version: nil,
repository: nil,
base_path: nil)
@smart_proxy = smart_proxy
@content_view_version = content_view_version
@destination_server = destination_server
@from_content_view_version = from_content_view_version
@repository = repository
@base_path = base_path
end
|
Instance Attribute Details
#base_path ⇒ Object
Returns the value of attribute base_path.
13
14
15
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 13
def base_path
@base_path
end
|
#content_view_version ⇒ Object
Returns the value of attribute content_view_version.
13
14
15
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 13
def content_view_version
@content_view_version
end
|
#destination_server ⇒ Object
Returns the value of attribute destination_server.
13
14
15
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 13
def destination_server
@destination_server
end
|
#from_content_view_version ⇒ Object
Returns the value of attribute from_content_view_version.
13
14
15
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 13
def from_content_view_version
@from_content_view_version
end
|
#repository ⇒ Object
Returns the value of attribute repository.
13
14
15
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 13
def repository
@repository
end
|
#smart_proxy ⇒ Object
Returns the value of attribute smart_proxy.
13
14
15
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 13
def smart_proxy
@smart_proxy
end
|
Class Method Details
.create(options) ⇒ Object
15
16
17
18
19
20
21
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 15
def self.create(options)
if options.delete(:format) == SYNCABLE
SyncableFormatExport.new(**options)
else
self.new(**options)
end
end
|
.find_export_view(name:, organization:, generated_for:, destination_server: nil) ⇒ Object
136
137
138
139
140
141
142
143
144
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 136
def self.find_export_view(name:, organization:, generated_for:, destination_server: nil)
full_name = destination_server.blank? ? name : "#{name}-#{destination_server}"
::Katello::ContentView.where(
name: full_name,
organization: organization,
generated_for: generated_for
).first
end
|
.find_or_create_export_view(name:, organization:, generated_for:, destination_server: nil) ⇒ Object
Find or create export view
147
148
149
150
151
152
153
154
155
156
157
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 147
def self.find_or_create_export_view(name:, organization:, generated_for:, destination_server: nil)
find_export_view(name: name, organization: organization, generated_for: generated_for, destination_server: destination_server) ||
begin
full_name = destination_server.blank? ? name : "#{name}-#{destination_server}"
::Katello::ContentView.create!(
name: full_name,
organization: organization,
generated_for: generated_for
)
end
end
|
.find_or_create_library_export_view(destination_server:, organization:, format: UNDEFINED) ⇒ Object
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 163
def self.find_or_create_library_export_view(destination_server:, organization:,
format: UNDEFINED)
case format
when UNDEFINED
fail ::Katello::Errors::InvalidExportFormat, _("Export format must be specified for library exports.")
when IMPORTABLE
return find_or_create_export_view(
destination_server: destination_server,
organization: organization,
name: ::Katello::ContentView::EXPORT_LIBRARY,
generated_for: :library_export)
when SYNCABLE
return find_or_create_export_view(
destination_server: destination_server,
organization: organization,
name: "#{::Katello::ContentView::EXPORT_LIBRARY}-SYNCABLE",
generated_for: :library_export_syncable)
else
fail ::Katello::Errors::InvalidExportFormat, _("Unknown library export format '%s'.") % format
end
end
|
.find_or_create_repository_export_view(repository:, format: UNDEFINED) ⇒ Object
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 185
def self.find_or_create_repository_export_view(repository:, format: UNDEFINED)
case format
when UNDEFINED
fail ::Katello::Errors::InvalidExportFormat, _("Export format must be specified for non-incremental repository exports.")
when IMPORTABLE
return find_or_create_export_view(destination_server: nil, organization: repository.organization,
name: "Export-#{repository.label}-#{repository.library_instance_or_self.id}", generated_for: :repository_export)
when SYNCABLE
return find_or_create_export_view(destination_server: nil, organization: repository.organization,
name: "Export-SYNCABLE-#{repository.label}-#{repository.library_instance_or_self.id}", generated_for: :repository_export_syncable)
else
fail ::Katello::Errors::InvalidExportFormat, _("Unknown repository export format '%s'.") % format
end
end
|
.generate_product_repo_strings(repositories:) ⇒ Object
200
201
202
203
204
205
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 200
def self.generate_product_repo_strings(repositories:)
repositories.map do |repo|
_("Product: '%{product}', Repository: '%{repository}'" % { product: repo.product.name,
repository: repo.name})
end
end
|
Instance Method Details
#create_export(exporter_data, chunk_size: nil) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 82
def create_export(exporter_data, chunk_size: nil)
exporter_href = exporter_data[:pulp_href]
options = { versions: version_hrefs }
options[:chunk_size] = "#{chunk_size}GB" if chunk_size
if from_content_view_version
from_exporter = Export.new(smart_proxy: smart_proxy, content_view_version: from_content_view_version)
start_versions = from_exporter.version_hrefs
added_repo_hrefs = repository_hrefs - from_exporter.repository_hrefs
added_repo_hrefs.each do |added_repo_href|
start_versions << zero_version_href(added_repo_href)
end
deleted_repo_hrefs = from_exporter.repository_hrefs - repository_hrefs
start_versions.select! do |href|
!deleted_repo_hrefs.include?(version_href_to_repository_href(href))
end
options[:start_versions] = start_versions
options[:full] = 'false'
end
export_api = api.export_api
[export_api.create(exporter_href, options)]
end
|
#create_exporter ⇒ Object
74
75
76
77
78
79
80
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 74
def create_exporter
exporter_api = api.exporter_api
options = { name: generate_id(content_view_version), path: generate_exporter_path }
options[:repositories] = repository_hrefs
exporter_api.create(options)
end
|
#date_dir ⇒ Object
70
71
72
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 70
def date_dir
DateTime.now.to_s.gsub(/\W/, '-')
end
|
#destroy_exporter(exporter_data) ⇒ Object
117
118
119
120
121
122
123
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 117
def destroy_exporter(exporter_data)
exporter_href = exporter_data[:pulp_href]
export_data = fetch_export(exporter_href)
api.exporter_api.partial_update(exporter_href, :last_export => nil)
api.export_api.delete(export_data.pulp_href) unless export_data.blank?
api.exporter_api.delete(exporter_href)
end
|
#fetch_export(exporter_href) ⇒ Object
113
114
115
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 113
def fetch_export(exporter_href)
api.export_api.list(exporter_href).results.first
end
|
#generate_exporter_path ⇒ Object
62
63
64
65
66
67
68
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 62
def generate_exporter_path
return base_path if base_path
export_path = "#{content_view_version.content_view.label}/#{content_view_version.version}/"
export_path += "#{destination_server}/".gsub(/\s/, '_') unless destination_server.blank?
export_path += "#{date_dir}"
@base_path = "#{Setting['pulpcore_export_destination']}/#{content_view_version.organization.label}/#{export_path}"
end
|
132
133
134
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 132
def generate_metadata
MetadataGenerator.new(export_service: self).generate!
end
|
#incremental? ⇒ Boolean
58
59
60
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 58
def incremental?
from_content_view_version.present?
end
|
#repositories(fetch_all: false) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 45
def repositories(fetch_all: false)
repos = if content_view_version.default?
content_view_version.repositories.exportable(format: format)
else
content_view_version.archived_repos.exportable(format: format)
end
if fetch_all
repos
else
repos.immediate_or_none
end
end
|
#repository_hrefs ⇒ Object
37
38
39
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 37
def repository_hrefs
version_hrefs.map { |href| version_href_to_repository_href(href) }.uniq
end
|
#validate!(fail_on_missing_content: true, validate_incremental: true, chunk_size: nil) ⇒ Object
125
126
127
128
129
130
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 125
def validate!(fail_on_missing_content: true, validate_incremental: true, chunk_size: nil)
ExportValidator.new(export_service: self,
fail_on_missing_content: fail_on_missing_content,
validate_incremental: validate_incremental,
chunk_size: chunk_size).validate!
end
|
#version_hrefs ⇒ Object
41
42
43
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 41
def version_hrefs
repositories.pluck(:version_href).compact
end
|