Class: Katello::Pulp3::ContentViewVersion::Import

Inherits:
Object
  • Object
show all
Includes:
ImportExportCommon
Defined in:
app/services/katello/pulp3/content_view_version/import.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ImportExportCommon

#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
   = 
  @content_view = find_or_create_import_view
end

Instance Attribute Details

#content_viewObject (readonly)

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

#metadata_mapObject (readonly)

Returns the value of attribute metadata_map.



7
8
9
# File 'app/services/katello/pulp3/content_view_version/import.rb', line 7

def 
  
end

#organizationObject (readonly)

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

#pathObject (readonly)

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_proxyObject (readonly)

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

#intersecting_repos_library_and_metadataObject



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 
  # Returns repositories in library that are part of the metadata
  # In other words if metadata had repos {label:foo, product: bar}
  # this would match it to the repo with the label foo and product bar
  # in the library.
  queries = .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_repositoriesObject



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!
  # Given metadata from the dump and a content view
  # this method
  # 1) Fetches ids of the library repos whose product name, repo name amd redhat?
  # =>  match values provided in the metadata's repository mapping
  # 2) Removes all the repositories associated to this content view
  # 3) Adds the repositories matched from the dump
  # The main intent of this method is to assume that the user intends for the
  # content view to exaclty look like what is specified in metadata
  repo_ids = .pluck("#{Katello::Repository.table_name}.id")
  content_view.update!(repository_ids: repo_ids)
end