Class: ForemanMaintain::RepositoryManager::El

Inherits:
Object
  • Object
show all
Includes:
Concerns::OsFacts, Concerns::SystemHelpers
Defined in:
lib/foreman_maintain/repository_manager/el.rb

Constant Summary

Constants included from Concerns::OsFacts

Concerns::OsFacts::FALLBACK_OS_RELEASE_FILE, Concerns::OsFacts::OS_RELEASE_FILE

Instance Method Summary collapse

Methods included from Concerns::SystemHelpers

#check_max_version, #check_min_version, #command_present?, #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, #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

Methods included from Concerns::OsFacts

#centos?, #cpu_cores, #deb_major_version, #debian?, #debian_or_ubuntu?, #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

Methods included from Concerns::Finders

#check, #detector, #feature, #find_all_scenarios, #find_procedures, #find_scenarios, #procedure

Methods included from Concerns::Logger

#logger

Instance Method Details

#config_manager_options(repo_ids, options) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/foreman_maintain/repository_manager/el.rb', line 38

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
# File 'lib/foreman_maintain/repository_manager/el.rb', line 6

def disable_repos(repo_ids)
  execute!("dnf config-manager #{config_manager_options(repo_ids, 'set-disabled')}")
end

#enable_repos(repo_ids) ⇒ Object



20
21
22
# File 'lib/foreman_maintain/repository_manager/el.rb', line 20

def enable_repos(repo_ids)
  execute!("dnf config-manager #{config_manager_options(repo_ids, 'enable')}")
end

#enabled_reposObject



62
63
64
65
66
67
68
# File 'lib/foreman_maintain/repository_manager/el.rb', line 62

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



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/foreman_maintain/repository_manager/el.rb', line 70

def hash_of_repoids_urls(repos, regex)
  ids_urls = Hash[*repos.split("\n").grep(regex).map do |entry|
                    entry.split(':', 2).last.strip
                  end]

  # repolist output includes extra info in the output
  #
  # rhel-7-server-rpms/7Server/x86_64
  # rhel-server-rhscl-7-rpms/7Server/x86_64
  # This trims anything after first '/' to get correct repo label
  trimmed_hash = {}
  ids_urls.each do |id, url|
    trimmed_id = id.split('/').first
    trimmed_hash[trimmed_id] = url
  end
  trimmed_hash
end

#pkg_managerObject



58
59
60
# File 'lib/foreman_maintain/repository_manager/el.rb', line 58

def pkg_manager
  package_manager.class.name.split('::').last.downcase
end

#rhsm_available?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/foreman_maintain/repository_manager/el.rb', line 47

def rhsm_available?
  @rhsm_available ||= find_package('subscription-manager')
end

#rhsm_disable_repos(repo_ids) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/foreman_maintain/repository_manager/el.rb', line 10

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



24
25
26
27
28
29
30
31
32
# File 'lib/foreman_maintain/repository_manager/el.rb', line 24

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



51
52
53
54
55
56
# File 'lib/foreman_maintain/repository_manager/el.rb', line 51

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



34
35
36
# File 'lib/foreman_maintain/repository_manager/el.rb', line 34

def rhsm_options(repo_ids, options)
  repo_ids.map { |r| "--#{options}=#{r}" }.join(' ')
end