Class: Actions::Katello::CapsuleContent::SyncCapsule

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

Instance Method Summary collapse

Instance Method Details

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



7
8
9
10
11
12
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
45
46
47
48
49
50
51
52
53
# File 'app/lib/actions/katello/capsule_content/sync_capsule.rb', line 7

def plan(smart_proxy, options = {})
  plan_self(:smart_proxy_id => smart_proxy.id,
            :environment_id => options[:environment_id],
            :content_view_id => options[:content_view_id],
            :repository_id => options[:repository_id],
            :skip_content_counts_update => options[:skip_content_counts_update])
  action_subject(smart_proxy)
  environment = options[:environment]
  content_view = options[:content_view]
  repository = options[:repository]
   = options.fetch(:skip_metadata_check, false)
  sequence do
    repos = repos_to_sync(smart_proxy, environment, content_view, repository, )
    return nil if repos.empty?

    if environment.nil? && content_view.nil? && repository.nil?
      options[:repository_ids_list] = repos.pluck(:id)
    end
    if smart_proxy.has_feature?(SmartProxy::PULP3_FEATURE)
      plan_action(Actions::Pulp3::Orchestration::Repository::RefreshRepos, smart_proxy, options)
    end

    repos.in_groups_of(Setting[:foreman_proxy_content_batch_size], false) do |repo_batch|
      concurrence do
        repo_batch.each do |repo|
          if smart_proxy.pulp3_support?(repo)
            plan_action(Actions::Pulp3::CapsuleContent::Sync,
              repo, smart_proxy,
              skip_metadata_check: )
          end
        end
      end

      concurrence do
        repo_batch.each do |repo|
          if repo.is_a?(::Katello::Repository) &&
              repo.distribution_bootable? &&
              repo.download_policy == ::Katello::RootRepository::DOWNLOAD_ON_DEMAND
            plan_action(Katello::Repository::FetchPxeFiles,
                        id: repo.id,
                        capsule_id: smart_proxy.id)
          end
        end
      end
    end
  end
end

#repos_to_sync(smart_proxy, environment, content_view, repository, skip_metatadata_check = false) ⇒ Object

rubocop:enable Metrics/MethodLength



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/lib/actions/katello/capsule_content/sync_capsule.rb', line 56

def repos_to_sync(smart_proxy, environment, content_view, repository, skip_metatadata_check = false)
  smart_proxy_helper = ::Katello::SmartProxyHelper.new(smart_proxy)
  smart_proxy_helper.lifecycle_environment_check(environment, repository)
  if repository
    if skip_metatadata_check || !repository.smart_proxy_sync_histories.where(:smart_proxy_id => smart_proxy).any? { |sph| !sph.finished_at.nil? }
      [repository]
    end
  else
    repositories = smart_proxy_helper.repositories_available_to_capsule(environment, content_view).by_rpm_count
    repositories_to_skip = []
    if skip_metatadata_check
      smart_proxy_helper.clear_smart_proxy_sync_histories repositories
    else
      repositories_to_skip = ::Katello::Repository.synced_on_capsule smart_proxy
    end
    repositories - repositories_to_skip
  end
end

#rescue_strategyObject



95
96
97
# File 'app/lib/actions/katello/capsule_content/sync_capsule.rb', line 95

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

#resource_locksObject



86
87
88
# File 'app/lib/actions/katello/capsule_content/sync_capsule.rb', line 86

def resource_locks
  :link
end

#runObject



90
91
92
93
# File 'app/lib/actions/katello/capsule_content/sync_capsule.rb', line 90

def run
  smart_proxy = ::SmartProxy.unscoped.find(input[:smart_proxy_id])
  smart_proxy.sync_container_gateway
end

#update_content_counts(_execution_plan) ⇒ Object



75
76
77
78
79
80
81
82
83
84
# File 'app/lib/actions/katello/capsule_content/sync_capsule.rb', line 75

def update_content_counts(_execution_plan)
  if Setting[:automatic_content_count_updates] && !input[:skip_content_counts_update]
    smart_proxy = ::SmartProxy.unscoped.find(input[:smart_proxy_id])
    options = {environment_id: input[:environment_id], content_view_id: input[:content_view_id], repository_id: input[:repository_id]}
    ::ForemanTasks.async_task(::Actions::Katello::CapsuleContent::UpdateContentCounts, smart_proxy, options)
  else
    Rails.logger.info "Skipping content counts update as automatic content count updates are disabled. To enable automatic content count updates, set the 'automatic_content_count_updates' setting to true.
To update content counts manually, run the 'Update Content Counts' action."
  end
end