Class: Actions::Katello::CapsuleContent::Sync

Inherits:
EntryAction
  • Object
show all
Defined in:
app/lib/actions/katello/capsule_content/sync.rb

Instance Method Summary collapse

Instance Method Details

#get_repository_ids(capsule, environment, content_view, repository) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/lib/actions/katello/capsule_content/sync.rb', line 46

def get_repository_ids(capsule, environment, content_view, repository)
  if environment
    repository_ids = capsule.repos_available_to_capsule(environment, content_view).map(&:pulp_id)
  elsif repository
    repository_ids = [repository.pulp_id]
    environment = repository.environment
  else
    repository_ids = capsule.repos_available_to_capsule.map(&:pulp_id)
  end

  if environment && !capsule.lifecycle_environments.include?(environment)
    fail _("Lifecycle environment '%{environment}' is not attached to this capsule.") % { :environment => environment.name }
  end

  repository_ids
end

#humanized_nameObject



9
10
11
# File 'app/lib/actions/katello/capsule_content/sync.rb', line 9

def humanized_name
  _("Synchronize capsule content")
end

#plan(capsule_content, options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/lib/actions/katello/capsule_content/sync.rb', line 13

def plan(capsule_content, options = {})
  action_subject(capsule_content.capsule)

  environment = options.fetch(:environment, nil)
  repository = options.fetch(:repository, nil)
  content_view = options.fetch(:content_view, nil)

  fail _("Action not allowed for the default capsule.") if capsule_content.default_capsule?

  need_updates = repos_needing_updates(capsule_content, environment, content_view)
  repository_ids = get_repository_ids(capsule_content, environment, content_view, repository)
  unless repository_ids.blank?
    sequence do
      need_updates.each do |repo|
        plan_action(Pulp::Repository::Refresh, repo, capsule_id: capsule_content.capsule.id)
      end

      plan_action(ConfigureCapsule, capsule_content, environment, content_view)

      smart_proxy = SmartProxy.where(:content_host_id => capsule_content.consumer.id).first
      fail _("Smart Proxy not found for capsule.") unless smart_proxy
      concurrence do
        repository_ids.each do |repo_id|
          plan_action(Pulp::Consumer::SyncCapsule,
                      capsule_id: smart_proxy.id,
                      repo_pulp_id: repo_id)
        end
      end
      plan_action(RemoveOrphans, :capsule_id => capsule_content.capsule.id)
    end
  end
end

#repos_needing_distributor_updates(capsule, environment, content_view) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'app/lib/actions/katello/capsule_content/sync.rb', line 69

def repos_needing_distributor_updates(capsule, environment, content_view)
  repos = capsule.repos_available_to_capsule(environment, content_view)
  repos.select do |repo|
    repo_details = capsule.pulp_repo_facts(repo.pulp_id)
    next unless repo_details
    capsule_distributors = repo_details["distributors"]
    !(repo.distributors_match?(capsule_distributors))
  end
end

#repos_needing_importer_updates(capsule, environment, content_view) ⇒ Object



79
80
81
82
83
84
85
86
87
# File 'app/lib/actions/katello/capsule_content/sync.rb', line 79

def repos_needing_importer_updates(capsule, environment, content_view)
  repos = capsule.repos_available_to_capsule(environment, content_view)
  repos.select do |repo|
    repo_details = capsule.pulp_repo_facts(repo.pulp_id)
    next unless repo_details
    capsule_importer = repo_details["importers"][0].try(:[], "config")
    capsule_importer.nil? || !(repo.importer_matches?(capsule_importer))
  end
end

#repos_needing_updates(capsule_content, environment, content_view) ⇒ Object



63
64
65
66
67
# File 'app/lib/actions/katello/capsule_content/sync.rb', line 63

def repos_needing_updates(capsule_content, environment, content_view)
  need_importer_update = repos_needing_importer_updates(capsule_content, environment, content_view)
  need_distributor_update = repos_needing_distributor_updates(capsule_content, environment, content_view)
  (need_distributor_update + need_importer_update).uniq
end

#rescue_strategyObject



89
90
91
# File 'app/lib/actions/katello/capsule_content/sync.rb', line 89

def rescue_strategy
  Dynflow::Action::Rescue::Skip
end

#resource_locksObject



5
6
7
# File 'app/lib/actions/katello/capsule_content/sync.rb', line 5

def resource_locks
  :link
end