module ForemanMaintain

Constants

LOGGER_LEVEL_MAPPING
VERSION

Attributes

config[RW]
logger[RW]

Public Class Methods

allowed_available_procedures(*args) click to toggle source
# File lib/foreman_maintain.rb, line 131
def allowed_available_procedures(*args)
  procedures = detector.available_procedures(*args)
  procedures.select(&:advanced_run?)
end
available_checks(*args) click to toggle source
# File lib/foreman_maintain.rb, line 123
def available_checks(*args)
  detector.available_checks(*args)
end
available_features(*args) click to toggle source
# File lib/foreman_maintain.rb, line 115
def available_features(*args)
  detector.available_features(*args)
end
available_procedures(*args) click to toggle source
# File lib/foreman_maintain.rb, line 127
def available_procedures(*args)
  detector.available_procedures(*args)
end
available_scenarios(*args) click to toggle source
# File lib/foreman_maintain.rb, line 119
def available_scenarios(*args)
  detector.available_scenarios(*args)
end
cache() click to toggle source
# File lib/foreman_maintain.rb, line 99
def cache
  ObjectCache.instance
end
config_file() click to toggle source
# File lib/foreman_maintain.rb, line 85
def config_file
  config.config_file
end
detector() click to toggle source
# File lib/foreman_maintain.rb, line 103
def detector
  @detector ||= Detector.new
end
init_logger() click to toggle source
# File lib/foreman_maintain.rb, line 136
def init_logger
  # convert size in KB to Bytes
  log_fsize = config.log_file_size.to_i * 1024
  @logger = Logger.new(config.log_filename, 10, log_fsize).tap do |logger|
    logger.level = LOGGER_LEVEL_MAPPING[config.log_level] || Logger::DEBUG
    logger.datetime_format = '%Y-%m-%d %H:%M:%S%z '
  end
  pickup_log_messages
end
load_definitions() click to toggle source
# File lib/foreman_maintain.rb, line 89
def load_definitions
  # we need to add the load paths first, in case there is crossreferencing
  # between the definitions directories
  $LOAD_PATH.concat(config.definitions_dirs)
  config.definitions_dirs.each do |definitions_dir|
    file_paths = File.expand_path(File.join(definitions_dir, '**', '*.rb'))
    Dir.glob(file_paths).each { |f| require f }
  end
end
main_package_name() click to toggle source
# File lib/foreman_maintain.rb, line 185
def main_package_name
  'rubygem-foreman_maintain'
end
package_manager() click to toggle source
# File lib/foreman_maintain/package_manager.rb, line 6
def self.package_manager
  @package_manager ||= case (%w[dnf yum apt].find { |manager| !`command -v #{manager}`.empty? })
                       when 'dnf'
                         ForemanMaintain::PackageManager::Dnf.new
                       when 'yum'
                         ForemanMaintain::PackageManager::Yum.new
                       else
                         raise 'No supported package manager was found'
                       end
end
perform_self_upgrade() click to toggle source
# File lib/foreman_maintain.rb, line 171
def perform_self_upgrade
  package_name, command = pkg_and_cmd_name

  puts "Checking for new version of #{package_name}..."
  if ForemanMaintain.package_manager.update_available?(main_package_name)
    puts "\nUpdating #{package_name} package."
    ForemanMaintain.package_manager.update(main_package_name, :assumeyes => true)
    puts "\nThe #{package_name} package successfully updated."\
         "\nRe-run #{command} with required options!"
    exit 75
  end
  puts "Nothing to update, can't find new version of #{package_name}."
end
pickup_log_messages() click to toggle source
# File lib/foreman_maintain.rb, line 146
def pickup_log_messages
  return if config.pre_setup_log_messages.empty?
  config.pre_setup_log_messages.each { |msg| logger.info msg }
  config.pre_setup_log_messages.clear
end
pkg_and_cmd_name() click to toggle source
# File lib/foreman_maintain.rb, line 162
def pkg_and_cmd_name
  instance_feature = ForemanMaintain.available_features(:label => :instance).first
  if instance_feature.downstream
    return instance_feature.downstream.fm_pkg_and_cmd_name
  end

  [main_package_name, 'foreman-maintain']
end
refresh_features() click to toggle source
# File lib/foreman_maintain.rb, line 107
def refresh_features
  @detector = Detector.new
end
reporter() click to toggle source
# File lib/foreman_maintain.rb, line 111
def reporter
  @reporter ||= ForemanMaintain::Reporter::CLIReporter.new
end
repository_manager() click to toggle source
# File lib/foreman_maintain/repository_manager.rb, line 4
def self.repository_manager
  @repository_manager ||= if el?
                            ForemanMaintain::RepositoryManager::El.new
                          elsif debian?
                            raise 'Not implemented!'
                          else
                            raise 'No supported repository manager was found'
                          end
end
set_home_environment() click to toggle source
# File lib/foreman_maintain.rb, line 70
def set_home_environment
  ENV['HOME'] ||= '/root'
end
setup(options = {}) click to toggle source
# File lib/foreman_maintain.rb, line 60
def setup(options = {})
  set_home_environment

  # using a queue, we can log the messages which are generated before initializing logger
  self.config = Config.new(options)
  load_definitions
  init_logger
  update_path
end
storage(label = :default) click to toggle source
# File lib/foreman_maintain.rb, line 152
def storage(label = :default)
  ForemanMaintain::YamlStorage.load(label)
rescue StandardError => e
  logger.error "Invalid Storage label i.e #{label}. Error - #{e.message}"
end
update_path() click to toggle source

Appending PATH with expected paths needed for commands we run

# File lib/foreman_maintain.rb, line 75
def update_path
  paths = ['/sbin']
  existing_paths = ENV['PATH'].split(':')
  paths -= existing_paths
  if paths.any?
    paths = paths.join(':').chomp(':')
    ENV['PATH'] = "#{ENV['PATH']}:#{paths}"
  end
end
upgrade_in_progress() click to toggle source
# File lib/foreman_maintain.rb, line 158
def upgrade_in_progress
  storage[:upgrade_target_version]
end