module ForemanMaintain::Concerns::SystemHelpers

Public Class Methods

included(klass) click to toggle source
# File lib/foreman_maintain/concerns/system_helpers.rb, line 10
def self.included(klass)
  klass.extend(self)
end

Public Instance Methods

check_min_version(name, minimal_version) click to toggle source
# File lib/foreman_maintain/concerns/system_helpers.rb, line 37
def check_min_version(name, minimal_version)
  current_version = package_version(name)
  if current_version
    return current_version >= version(minimal_version)
  end
end
downstream_installation?() click to toggle source
# File lib/foreman_maintain/concerns/system_helpers.rb, line 44
def downstream_installation?
  execute?('rpm -q satellite') ||
    (execute('rpm -q foreman') =~ /6sat.noarch/)
end
execute(command, options = {}) click to toggle source
# File lib/foreman_maintain/concerns/system_helpers.rb, line 85
def execute(command, options = {})
  command_runner = Utils::CommandRunner.new(logger, command, options)
  execution.puts '' if command_runner.interactive? && respond_to?(:execution)
  command_runner.run
  command_runner.output
end
execute!(command, options = {}) click to toggle source
# File lib/foreman_maintain/concerns/system_helpers.rb, line 74
def execute!(command, options = {})
  command_runner = Utils::CommandRunner.new(logger, command, options)
  execution.puts '' if command_runner.interactive? && respond_to?(:execution)
  command_runner.run
  if command_runner.success?
    command_runner.output
  else
    raise command_runner.execution_error
  end
end
execute?(command, input = nil) click to toggle source
# File lib/foreman_maintain/concerns/system_helpers.rb, line 69
def execute?(command, input = nil)
  execute(command, :stdin => input)
  $CHILD_STATUS.success?
end
file_exists?(filename) click to toggle source
# File lib/foreman_maintain/concerns/system_helpers.rb, line 22
def file_exists?(filename)
  File.exist?(filename)
end
hostname() click to toggle source
# File lib/foreman_maintain/concerns/system_helpers.rb, line 18
def hostname
  execute('hostname -f')
end
install_packages(packages, options = {}) click to toggle source
# File lib/foreman_maintain/concerns/system_helpers.rb, line 30
def install_packages(packages, options = {})
  options.validate_options!(:assumeyes)
  yum_options = []
  yum_options << '-y' if options[:assumeyes]
  execute!("yum #{yum_options.join(' ')} install #{packages.join(' ')}", :interactive => true)
end
package_version(name) click to toggle source
# File lib/foreman_maintain/concerns/system_helpers.rb, line 49
def package_version(name)
  # space for extension to support non-rpm distributions
  rpm_version(name)
end
parse_csv(data) click to toggle source
# File lib/foreman_maintain/concerns/system_helpers.rb, line 61
def parse_csv(data)
  parsed_data = CSV.parse(data)
  header = parsed_data.first
  parsed_data[1..-1].map do |row|
    Hash[*header.zip(row).flatten(1)]
  end
end
rpm_version(name) click to toggle source
# File lib/foreman_maintain/concerns/system_helpers.rb, line 54
def rpm_version(name)
  rpm_version = execute(%Q(rpm -q '#{name}' --queryformat="%{VERSION}"))
  if $CHILD_STATUS.success?
    version(rpm_version)
  end
end
shellescape(string) click to toggle source
# File lib/foreman_maintain/concerns/system_helpers.rb, line 92
def shellescape(string)
  Shellwords.escape(string)
end
version(value) click to toggle source
# File lib/foreman_maintain/concerns/system_helpers.rb, line 26
def version(value)
  Version.new(value)
end