Class: ForemanMaintain::RepositoryManager::El
Constant Summary
Concerns::OsFacts::FALLBACK_OS_RELEASE_FILE, Concerns::OsFacts::OS_RELEASE_FILE
Instance Method Summary
collapse
#check_max_version, #check_min_version, #command_present?, #create_lv_snapshot, #directory_empty?, #execute, #execute!, #execute?, #execute_runner, #execute_with_status, #file_exists?, #file_nonzero?, #find_dir_containing_file, #find_package, #find_symlinks, #foreman_plugin_name, #format_shell_args, #get_lv_info, #get_lv_path, #hammer_package, #hammer_plugin_name, #hostname, included, #package_manager, #package_version, #packages_action, #parse_csv, #parse_json, #proxy_plugin_name, #repository_manager, #ruby_prefix, #server?, #shellescape, #systemd_installed?, #version
#centos?, #cpu_cores, #deb_major_version, #debian?, #debian_or_ubuntu?, #el7?, #el8?, #el?, #el_major_version, #el_short_name, #facts, #memory, #os_id, #os_id_like_list, #os_name, #os_release_file, #os_version, #os_version_codename, #os_version_id, #rhel?, #ubuntu?, #ubuntu_major_version
#check, #detector, #feature, #find_all_scenarios, #find_checks, #find_procedures, #find_scenarios, #procedure
#logger
Instance Method Details
#config_manager_options(repo_ids, options) ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/foreman_maintain/repository_manager/el.rb', line 46
def config_manager_options(repo_ids, options)
repo_ids_string = if repo_ids.is_a?(Array)
repo_ids.join(',')
else
repo_ids
end
format_shell_args("--#{options}" => repo_ids_string)
end
|
#disable_repos(repo_ids) ⇒ Object
6
7
8
9
10
11
12
|
# File 'lib/foreman_maintain/repository_manager/el.rb', line 6
def disable_repos(repo_ids)
if el7?
execute!("yum-config-manager #{config_manager_options(repo_ids, 'disable')}")
else
execute!("dnf config-manager #{config_manager_options(repo_ids, 'set-disabled')}")
end
end
|
#enable_repos(repo_ids) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/foreman_maintain/repository_manager/el.rb', line 24
def enable_repos(repo_ids)
if el7?
execute!("yum-config-manager #{config_manager_options(repo_ids, 'enable')}")
else
execute!("dnf config-manager #{config_manager_options(repo_ids, 'enable')}")
end
end
|
#enabled_repos ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/foreman_maintain/repository_manager/el.rb', line 70
def enabled_repos
cmd = "#{pkg_manager} repolist enabled -d 6 -e 0 2> /dev/null"
repos = execute(cmd)
return {} if repos.empty?
hash_of_repoids_urls(repos, /Repo-id|Repo-baseurl/)
end
|
#hash_of_repoids_urls(repos, regex) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/foreman_maintain/repository_manager/el.rb', line 78
def hash_of_repoids_urls(repos, regex)
ids_urls = Hash[*repos.split("\n").grep(regex).map do |entry|
entry.split(':', 2).last.strip
end]
trimmed_hash = {}
ids_urls.each do |id, url|
trimmed_id = id.split('/').first
trimmed_hash[trimmed_id] = url
end
trimmed_hash
end
|
#pkg_manager ⇒ Object
66
67
68
|
# File 'lib/foreman_maintain/repository_manager/el.rb', line 66
def pkg_manager
package_manager.class.name.split('::').last.downcase
end
|
#rhsm_available? ⇒ Boolean
55
56
57
|
# File 'lib/foreman_maintain/repository_manager/el.rb', line 55
def rhsm_available?
@rhsm_available ||= find_package('subscription-manager')
end
|
#rhsm_disable_repos(repo_ids) ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'lib/foreman_maintain/repository_manager/el.rb', line 14
def rhsm_disable_repos(repo_ids)
if rhsm_available?
execute!(%(subscription-manager repos #{rhsm_options(repo_ids, 'disable')}))
else
logger.info("subscription-manager is not available.\
Using #{pkg_manager} config manager instead.")
disable_repos(repo_ids)
end
end
|
#rhsm_enable_repos(repo_ids) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/foreman_maintain/repository_manager/el.rb', line 32
def rhsm_enable_repos(repo_ids)
if rhsm_available?
execute!(%(subscription-manager repos #{rhsm_options(repo_ids, 'enable')}))
else
logger.info("subscription-manager is not available.\
Using #{pkg_manager} config manager instead.")
enable_repos(repo_ids)
end
end
|
#rhsm_list_repos(list_option = '--list') ⇒ Object
59
60
61
62
63
64
|
# File 'lib/foreman_maintain/repository_manager/el.rb', line 59
def rhsm_list_repos(list_option = '--list')
repos = execute(%(LANG=en_US.utf-8 subscription-manager repos #{list_option} 2>&1))
return {} if repos.empty?
hash_of_repoids_urls(repos, /Repo ID|Repo URL/)
end
|
#rhsm_options(repo_ids, options) ⇒ Object
42
43
44
|
# File 'lib/foreman_maintain/repository_manager/el.rb', line 42
def rhsm_options(repo_ids, options)
repo_ids.map { |r| "--#{options}=#{r}" }.join(' ')
end
|