Class: Actions::Pulp::Repository::Refresh

Inherits:
Abstract
  • Object
show all
Defined in:
app/lib/actions/pulp/repository/refresh.rb

Instance Method Summary collapse

Methods inherited from Abstract

#pulp_extensions, #pulp_resources

Instance Method Details

#importer_certs(repository) ⇒ Object



81
82
83
84
85
86
87
88
89
# File 'app/lib/actions/pulp/repository/refresh.rb', line 81

def importer_certs(repository)
  ueber_cert = ::Cert::Certs.ueber_cert(repository.organization)

  {
    :ssl_ca_cert => ::Cert::Certs.ca_cert,
    :ssl_client_cert => ueber_cert[:cert],
    :ssl_client_key => ueber_cert[:key]
  }
end

#plan(repository, input = {}) ⇒ Object



9
10
11
12
13
14
# File 'app/lib/actions/pulp/repository/refresh.rb', line 9

def plan(repository, input = {})
  repository_details = pulp_extensions(input[:capsule_id]).repository.retrieve_with_details(repository.pulp_id)
  update_or_associate_importer(input[:capsule_id], repository, repository_details)
  update_or_associate_distributors(input[:capsule_id], repository, repository_details)
  remove_unnecessary_distributors(input[:capsule_id], repository, repository_details)
end

#remove_unnecessary_distributors(capsule_id, repository, repository_details) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/lib/actions/pulp/repository/refresh.rb', line 65

def remove_unnecessary_distributors(capsule_id, repository, repository_details)
  concurrence do
    existing_distributors = repository_details["distributors"]
    generated_distributors = repository.generate_distributors(capsule_id.present?)
    existing_distributors.each do |distributor|
      found = generated_distributors.find { |dist| dist.type_id == distributor['distributor_type_id'] }
      unless found
        plan_action(Pulp::Repository::DeleteDistributor, :repo_id => repository.pulp_id,
                                                         :distributor_id => distributor['id'],
                                                         :capsule_id => capsule_id
                   )
      end
    end
  end
end

#update_or_associate_distributors(capsule_id, repository, repository_details) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/lib/actions/pulp/repository/refresh.rb', line 40

def update_or_associate_distributors(capsule_id, repository, repository_details)
  concurrence do
    existing_distributors = repository_details["distributors"]
    repository.generate_distributors(capsule_id.present?).each do |distributor|
      found = existing_distributors.find { |i| i['distributor_type_id'] == distributor.type_id }
      if found
        plan_action(::Actions::Pulp::Repository::RefreshDistributor,
                    :repo_id => repository.pulp_id,
                    :id => found['id'],
                    :config => distributor.config,
                    :capsule_id => capsule_id
                    )
      else
        plan_action(::Actions::Pulp::Repository::AssociateDistributor,
                    :repo_id => repository.pulp_id,
                    :type_id => distributor.type_id,
                    :config => distributor.config,
                    :capsule_id => capsule_id,
                    :hash => { :distributor_id => distributor.id }
                    )
      end
    end
  end
end

#update_or_associate_importer(capsule_id, repository, repository_details) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/lib/actions/pulp/repository/refresh.rb', line 16

def update_or_associate_importer(capsule_id, repository, repository_details)
  existing_importers = repository_details["importers"]
  importer = capsule_id ? repository.generate_importer(true) : repository.generate_importer
  importer_config = capsule_id ? importer.config.merge!(importer_certs(repository)) : importer.config
  found = existing_importers.find { |i| i['importer_type_id'] == importer.id }

  if found
    plan_action(::Actions::Pulp::Repository::UpdateImporter,
                :repo_id => repository.pulp_id,
                :id => found['id'],
                :config => importer_config,
                :capsule_id => capsule_id
                )
  else
    plan_action(::Actions::Pulp::Repository::AssociateImporter,
                :repo_id => repository.pulp_id,
                :type_id => repository.importers.first['importer_type_id'],
                :config => importer_config,
                :capsule_id => capsule_id,
                :hash => { :importer_id => importer.id }
                )
  end
end