forked from Katello/katello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
refresh_repos.rb
52 lines (45 loc) · 1.98 KB
/
refresh_repos.rb
1
2
3
4
5
6
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
module Actions
module Katello
module CapsuleContent
module RefreshRepos
def fetch_proxy_service(_smart_proxy)
fail NotImplementedError
end
def act_on_repo?(_repo)
fail NotImplementedError
end
def rescue_strategy
Dynflow::Action::Rescue::Skip if self.state == 'error'
end
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)
end
def invoke_external_task
tasks = []
environment = ::Katello::KTEnvironment.find_by(:id => input[:environment_id]) if input[:environment_id]
repository = ::Katello::Repository.find_by(:id => input[:repository_id]) if input[:repository_id]
content_view = ::Katello::ContentView.find_by(:id => input[:content_view_id]) if input[:content_view_id]
smart_proxy = SmartProxy.unscoped.find(input[:smart_proxy_id])
smart_proxy_helper = ::Katello::SmartProxyHelper.new(smart_proxy)
smart_proxy_service = fetch_proxy_service(smart_proxy)
current_repos_on_capsule = smart_proxy_service.current_repositories(environment, content_view)
current_repos_on_capsule_ids = current_repos_on_capsule.pluck(:id)
list_of_repos_to_sync = smart_proxy_helper.combined_repos_available_to_capsule(environment, content_view, repository)
list_of_repos_to_sync.each do |repo|
next unless act_on_repo?(repo, smart_proxy)
pulp_repo = repo.backend_service(smart_proxy)
if !current_repos_on_capsule_ids.include?(repo.id)
pulp_repo.create_mirror_entities
else
tasks += pulp_repo.refresh_mirror_entities
end
end
tasks
end
end
end
end
end