Class: Katello::Pulp3::ContentViewVersion::Import
- Inherits:
-
Object
- Object
- Katello::Pulp3::ContentViewVersion::Import
show all
- Includes:
- ImportExportCommon
- Defined in:
- app/services/katello/pulp3/content_view_version/import.rb
Instance Attribute 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(organization:, smart_proxy:, path:, metadata_map:) ⇒ Import
Returns a new instance of Import.
9
10
11
12
13
14
15
|
# File 'app/services/katello/pulp3/content_view_version/import.rb', line 9
def initialize(organization:, smart_proxy:, path:, metadata_map:)
@organization = organization
@smart_proxy = smart_proxy
@path = path
@metadata_map = metadata_map
@content_view = find_or_create_import_view
end
|
Instance Attribute Details
#content_view ⇒ Object
Returns the value of attribute content_view.
7
8
9
|
# File 'app/services/katello/pulp3/content_view_version/import.rb', line 7
def content_view
@content_view
end
|
Returns the value of attribute metadata_map.
7
8
9
|
# File 'app/services/katello/pulp3/content_view_version/import.rb', line 7
def metadata_map
@metadata_map
end
|
#organization ⇒ Object
Returns the value of attribute organization.
7
8
9
|
# File 'app/services/katello/pulp3/content_view_version/import.rb', line 7
def organization
@organization
end
|
#path ⇒ Object
Returns the value of attribute path.
7
8
9
|
# File 'app/services/katello/pulp3/content_view_version/import.rb', line 7
def path
@path
end
|
#smart_proxy ⇒ Object
Returns the value of attribute smart_proxy.
7
8
9
|
# File 'app/services/katello/pulp3/content_view_version/import.rb', line 7
def smart_proxy
@smart_proxy
end
|
Instance Method Details
#check! ⇒ Object
36
37
38
|
# File 'app/services/katello/pulp3/content_view_version/import.rb', line 36
def check!
ImportValidator.new(import: self).check!
end
|
#create_import(importer_href) ⇒ Object
22
23
24
|
# File 'app/services/katello/pulp3/content_view_version/import.rb', line 22
def create_import(importer_href)
[api.import_api.create(importer_href, toc: "#{@path}/#{@metadata_map.toc}")]
end
|
#create_importer(content_view_version) ⇒ Object
17
18
19
20
|
# File 'app/services/katello/pulp3/content_view_version/import.rb', line 17
def create_importer(content_view_version)
api.importer_api.create(name: generate_id(content_view_version),
repo_mapping: repository_mapping(content_view_version))
end
|
#destroy_importer(importer_href) ⇒ Object
30
31
32
33
34
|
# File 'app/services/katello/pulp3/content_view_version/import.rb', line 30
def destroy_importer(importer_href)
import_data = fetch_import(importer_href)
api.import_api.delete(import_data.pulp_href) unless import_data.blank?
api.importer_api.delete(importer_href)
end
|
#fetch_import(importer_href) ⇒ Object
26
27
28
|
# File 'app/services/katello/pulp3/content_view_version/import.rb', line 26
def fetch_import(importer_href)
api.import_api.list(importer_href).results.first
end
|
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'app/services/katello/pulp3/content_view_version/import.rb', line 40
def intersecting_repos_library_and_metadata
queries = metadata_map.repositories.map do |repo|
if repo.redhat && repo.product.cp_id && repo.content&.id
library_repositories.where("#{Katello::Product.table_name}.cp_id": repo.product.cp_id,
"#{::Katello::RootRepository.table_name}" => {
content_id: repo.content.id,
arch: repo.arch,
major: repo.major,
minor: repo.minor })
else
library_repositories.where("#{Katello::Product.table_name}.label": repo.product.label,
"#{Katello::RootRepository.table_name}.label": repo.label)
end
end
queries.inject(&:or)
end
|
#library_repositories ⇒ Object
61
62
63
64
65
66
67
68
|
# File 'app/services/katello/pulp3/content_view_version/import.rb', line 61
def library_repositories
Katello::Repository.
in_default_view.
exportable.
joins(:product => :provider, :content_view_version => :content_view).
joins(:root).
where("#{::Katello::ContentView.table_name}.organization_id": organization)
end
|
#reset_content_view_repositories! ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'app/services/katello/pulp3/content_view_version/import.rb', line 70
def reset_content_view_repositories!
repo_ids = intersecting_repos_library_and_metadata.pluck("#{Katello::Repository.table_name}.id")
content_view.update!(repository_ids: repo_ids)
end
|