Class: ForemanMaintain::PackageManager::Yum

Inherits:
Base
  • Object
show all
Defined in:
lib/foreman_maintain/package_manager/yum.rb

Direct Known Subclasses

Dnf

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
PROTECTOR_PLUGIN_FILE =
'/usr/lib/yum-plugins/foreman-protector.py'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse_envra(envra) ⇒ Object



7
8
9
10
11
# File 'lib/foreman_maintain/package_manager/yum.rb', line 7

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

#clean_cache(assumeyes: false) ⇒ Object



60
61
62
# File 'lib/foreman_maintain/package_manager/yum.rb', line 60

def clean_cache(assumeyes: false)
  yum_action('clean', 'all', :assumeyes => assumeyes)
end

#files_not_owned_by_package(directory) ⇒ Object



69
70
71
72
# File 'lib/foreman_maintain/package_manager/yum.rb', line 69

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) ⇒ Object



41
42
43
44
45
46
# File 'lib/foreman_maintain/package_manager/yum.rb', line 41

def find_installed_package(name)
  status, result = sys.execute_with_status(%(rpm -q '#{name}'))
  if status == 0
    result
  end
end

#install(packages, assumeyes: false) ⇒ Object



48
49
50
# File 'lib/foreman_maintain/package_manager/yum.rb', line 48

def install(packages, assumeyes: false)
  yum_action('install', packages, :assumeyes => assumeyes)
end

#install_version_lockingObject



30
31
32
33
34
# File 'lib/foreman_maintain/package_manager/yum.rb', line 30

def install_version_locking(*)
  install_extras('foreman_protector/foreman-protector.py', PROTECTOR_PLUGIN_FILE)
  install_extras('foreman_protector/foreman-protector.conf', PROTECTOR_CONFIG_FILE)
  install_extras('foreman_protector/foreman-protector.whitelist', PROTECTOR_WHITELIST_FILE)
end

#installed?(packages) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/foreman_maintain/package_manager/yum.rb', line 36

def installed?(packages)
  packages_list = [packages].flatten(1).map { |pkg| "'#{pkg}'" }.join(' ')
  sys.execute?(%(rpm -q #{packages_list}))
end

#lock_versionsObject



13
14
15
# File 'lib/foreman_maintain/package_manager/yum.rb', line 13

def lock_versions
  enable_protector
end

#remove(packages, assumeyes: false) ⇒ Object



52
53
54
# File 'lib/foreman_maintain/package_manager/yum.rb', line 52

def remove(packages, assumeyes: false)
  yum_action('remove', packages, :assumeyes => assumeyes)
end

#unlock_versionsObject



17
18
19
# File 'lib/foreman_maintain/package_manager/yum.rb', line 17

def unlock_versions
  disable_protector
end

#update(packages = [], assumeyes: false) ⇒ Object



56
57
58
# File 'lib/foreman_maintain/package_manager/yum.rb', line 56

def update(packages = [], assumeyes: false)
  yum_action('update', packages, :assumeyes => assumeyes)
end

#update_available?(package) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
67
# File 'lib/foreman_maintain/package_manager/yum.rb', line 64

def update_available?(package)
  cmd_output = yum_action('check-update -q', package, :with_status => true, :assumeyes => false)
  cmd_output[0] == 100
end

#version_locking_enabled?Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/foreman_maintain/package_manager/yum.rb', line 25

def version_locking_enabled?
  File.exist?(PROTECTOR_PLUGIN_FILE) && File.exist?(PROTECTOR_CONFIG_FILE) &&
    File.exist?(PROTECTOR_WHITELIST_FILE)
end

#versions_locked?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/foreman_maintain/package_manager/yum.rb', line 21

def versions_locked?
  !!(protector_config =~ /^\s*enabled\s*=\s*1/)
end