Class: ForemanMaintain::PackageManager::Yum
- Defined in:
- lib/foreman_maintain/package_manager/yum.rb
Direct Known Subclasses
Constant Summary collapse
- PROTECTOR_CONFIG_FILE =
'/etc/yum/pluginconf.d/foreman-protector.conf'.freeze
- PROTECTOR_WHITELIST_FILE =
'/etc/yum/pluginconf.d/foreman-protector.whitelist'.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #check_update(packages: nil, with_status: false) ⇒ Object
- #clean_cache(assumeyes: false) ⇒ Object
- #files_not_owned_by_package(directory) ⇒ Object
- #find_installed_package(name, queryformat = '') ⇒ Object
- #install(packages, assumeyes: false) ⇒ Object
- #installed?(packages) ⇒ Boolean
- #list_installed_packages(queryformat = '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n') ⇒ Object
- #lock_versions ⇒ Object
- #protector_whitelist_file_nonzero? ⇒ Boolean
- #reinstall(packages, assumeyes: false) ⇒ Object
- #remove(packages, assumeyes: false) ⇒ Object
- #unlock_versions ⇒ Object
- #update(packages = [], assumeyes: false, yum_options: []) ⇒ Object
- #update_available?(package) ⇒ Boolean
- #version_locking_supported? ⇒ Boolean
- #versions_locked? ⇒ Boolean
Class Method Details
.parse_envra(envra) ⇒ Object
6 7 8 9 10 |
# File 'lib/foreman_maintain/package_manager/yum.rb', line 6 def self.parse_envra(envra) # envra format: 0:foreman-1.20.1.10-1.el7sat.noarch parsed = envra.match(/\d*:?(?<name>.*)-[^-]+-[^-]+\.[^.]+/) parsed ? Hash[parsed.names.map(&:to_sym).zip(parsed.captures)].merge(:envra => envra) : nil end |
Instance Method Details
#check_update(packages: nil, with_status: false) ⇒ Object
70 71 72 73 |
# File 'lib/foreman_maintain/package_manager/yum.rb', line 70 def check_update(packages: nil, with_status: false) yum_action('check-update', packages, :assumeyes => true, :valid_exit_statuses => [100], :with_status => with_status) end |
#clean_cache(assumeyes: false) ⇒ Object
66 67 68 |
# File 'lib/foreman_maintain/package_manager/yum.rb', line 66 def clean_cache(assumeyes: false) yum_action('clean', 'all', :assumeyes => assumeyes) end |
#files_not_owned_by_package(directory) ⇒ Object
80 81 82 83 |
# File 'lib/foreman_maintain/package_manager/yum.rb', line 80 def files_not_owned_by_package(directory) find_cmd = "find #{directory} -exec /bin/sh -c 'rpm -qf {} &> /dev/null || echo {}' \\;" sys.execute(find_cmd).split("\n") end |
#find_installed_package(name, queryformat = '') ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/foreman_maintain/package_manager/yum.rb', line 39 def find_installed_package(name, queryformat = '') rpm_cmd = "rpm -q '#{name}'" unless queryformat.empty? rpm_cmd += " --qf '#{queryformat}'" end status, result = sys.execute_with_status(rpm_cmd) if status == 0 result end end |
#install(packages, assumeyes: false) ⇒ Object
50 51 52 |
# File 'lib/foreman_maintain/package_manager/yum.rb', line 50 def install(packages, assumeyes: false) yum_action('install', packages, :assumeyes => assumeyes) end |
#installed?(packages) ⇒ Boolean
34 35 36 37 |
# File 'lib/foreman_maintain/package_manager/yum.rb', line 34 def installed?(packages) packages_list = [packages].flatten(1).map { |pkg| "'#{pkg}'" }.join(' ') sys.execute?(%(rpm -q #{packages_list})) end |
#list_installed_packages(queryformat = '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n') ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/foreman_maintain/package_manager/yum.rb', line 85 def list_installed_packages(queryformat = '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n') # The queryformat should only include valid tag(s) as per `rpm --querytags` list. # If any special formatting is required with querytag then it should be provided with tag i.e, # "--%{VENDOR}" # The queryformat string must end with '\n' sys.execute!("rpm -qa --qf '#{queryformat}'").split("\n") end |
#lock_versions ⇒ Object
12 13 14 |
# File 'lib/foreman_maintain/package_manager/yum.rb', line 12 def lock_versions enable_protector end |
#protector_whitelist_file_nonzero? ⇒ Boolean
25 26 27 28 |
# File 'lib/foreman_maintain/package_manager/yum.rb', line 25 def protector_whitelist_file_nonzero? File.exist?(PROTECTOR_WHITELIST_FILE) && !File.zero?(PROTECTOR_WHITELIST_FILE) end |
#reinstall(packages, assumeyes: false) ⇒ Object
54 55 56 |
# File 'lib/foreman_maintain/package_manager/yum.rb', line 54 def reinstall(packages, assumeyes: false) yum_action('reinstall', packages, :assumeyes => assumeyes) end |
#remove(packages, assumeyes: false) ⇒ Object
58 59 60 |
# File 'lib/foreman_maintain/package_manager/yum.rb', line 58 def remove(packages, assumeyes: false) yum_action('remove', packages, :assumeyes => assumeyes) end |
#unlock_versions ⇒ Object
16 17 18 |
# File 'lib/foreman_maintain/package_manager/yum.rb', line 16 def unlock_versions disable_protector end |
#update(packages = [], assumeyes: false, yum_options: []) ⇒ Object
62 63 64 |
# File 'lib/foreman_maintain/package_manager/yum.rb', line 62 def update(packages = [], assumeyes: false, yum_options: []) yum_action('update', packages, :assumeyes => assumeyes, :yum_options => ) end |
#update_available?(package) ⇒ Boolean
75 76 77 78 |
# File 'lib/foreman_maintain/package_manager/yum.rb', line 75 def update_available?(package) cmd_output = yum_action('check-update -q', package, :with_status => true, :assumeyes => false) cmd_output[0] == 100 end |
#version_locking_supported? ⇒ Boolean
30 31 32 |
# File 'lib/foreman_maintain/package_manager/yum.rb', line 30 def version_locking_supported? true end |
#versions_locked? ⇒ Boolean
20 21 22 23 |
# File 'lib/foreman_maintain/package_manager/yum.rb', line 20 def versions_locked? !!(protector_config =~ /^\s*enabled\s*=\s*1/) && protector_whitelist_file_nonzero? end |