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
- FORMATS =
[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.
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 19
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.
10
11
12
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 10
def base_path
@base_path
end
|
#content_view_version ⇒ Object
Returns the value of attribute content_view_version.
10
11
12
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 10
def content_view_version
@content_view_version
end
|
#destination_server ⇒ Object
Returns the value of attribute destination_server.
10
11
12
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 10
def destination_server
@destination_server
end
|
#from_content_view_version ⇒ Object
Returns the value of attribute from_content_view_version.
10
11
12
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 10
def from_content_view_version
@from_content_view_version
end
|
#repository ⇒ Object
Returns the value of attribute repository.
10
11
12
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 10
def repository
@repository
end
|
#smart_proxy ⇒ Object
Returns the value of attribute smart_proxy.
10
11
12
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 10
def smart_proxy
@smart_proxy
end
|
Class Method Details
.create(options) ⇒ Object
11
12
13
14
15
16
17
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 11
def self.create(options)
if options.delete(:format) == SYNCABLE
SyncableFormatExport.new(options)
else
self.new(options)
end
end
|
.find_generated_export_view(create_by_default: false, destination_server:, organization:, name:, generated_for:) ⇒ Object
132
133
134
135
136
137
138
139
140
141
142
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 132
def self.find_generated_export_view(create_by_default: false,
destination_server:,
organization:,
name:,
generated_for:)
name += "-#{destination_server}" unless destination_server.blank?
select_method = create_by_default ? :first_or_create : :first
::Katello::ContentView.where(name: name,
organization: organization,
generated_for: generated_for).send(select_method)
end
|
.find_library_export_view(create_by_default: false, destination_server:, organization:, format: IMPORTABLE) ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 148
def self.find_library_export_view(create_by_default: false,
destination_server:,
organization:,
format: IMPORTABLE)
if format == IMPORTABLE
generated_for = :library_export
name = ::Katello::ContentView::EXPORT_LIBRARY
else
generated_for = :library_export_syncable
name = "#{::Katello::ContentView::EXPORT_LIBRARY}-SYNCABLE"
end
find_generated_export_view(create_by_default: create_by_default,
destination_server: destination_server,
organization: organization,
name: name,
generated_for: generated_for)
end
|
.find_repository_export_view(create_by_default: false, repository:, format: IMPORTABLE) ⇒ Object
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 167
def self.find_repository_export_view(create_by_default: false,
repository:,
format: IMPORTABLE)
if format == IMPORTABLE
generated_for = :repository_export
name = "Export-#{repository.label}-#{repository.library_instance_or_self.id}"
else
generated_for = :repository_export_syncable
name = "Export-SYNCABLE-#{repository.label}-#{repository.library_instance_or_self.id}"
end
find_generated_export_view(create_by_default: create_by_default,
destination_server: nil,
organization: repository.organization,
name: name,
generated_for: generated_for)
end
|
.generate_product_repo_strings(repositories:) ⇒ Object
184
185
186
187
188
189
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 184
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
78
79
80
81
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
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 78
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
70
71
72
73
74
75
76
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 70
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
66
67
68
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 66
def date_dir
DateTime.now.to_s.gsub(/\W/, '-')
end
|
#destroy_exporter(exporter_data) ⇒ Object
113
114
115
116
117
118
119
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 113
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
109
110
111
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 109
def fetch_export(exporter_href)
api.export_api.list(exporter_href).results.first
end
|
144
145
146
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 144
def format
is_a?(SyncableFormatExport) ? SYNCABLE : IMPORTABLE
end
|
#generate_exporter_path ⇒ Object
58
59
60
61
62
63
64
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 58
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
|
128
129
130
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 128
def generate_metadata
MetadataGenerator.new(export_service: self).generate!
end
|
#incremental? ⇒ Boolean
54
55
56
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 54
def incremental?
from_content_view_version.present?
end
|
#repositories(fetch_all: false) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 41
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
33
34
35
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 33
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
121
122
123
124
125
126
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 121
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
37
38
39
|
# File 'app/services/katello/pulp3/content_view_version/export.rb', line 37
def version_hrefs
repositories.pluck(:version_href).compact
end
|