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 134 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 126 def available_checks(*args) detector.available_checks(*args) end
available_features(*args)
click to toggle source
# File lib/foreman_maintain.rb, line 118 def available_features(*args) detector.available_features(*args) end
available_procedures(*args)
click to toggle source
# File lib/foreman_maintain.rb, line 130 def available_procedures(*args) detector.available_procedures(*args) end
available_scenarios(*args)
click to toggle source
# File lib/foreman_maintain.rb, line 122 def available_scenarios(*args) detector.available_scenarios(*args) end
cache()
click to toggle source
# File lib/foreman_maintain.rb, line 102 def cache ObjectCache.instance end
config_file()
click to toggle source
# File lib/foreman_maintain.rb, line 88 def config_file config.config_file end
detector()
click to toggle source
# File lib/foreman_maintain.rb, line 106 def detector @detector ||= Detector.new end
init_logger()
click to toggle source
# File lib/foreman_maintain.rb, line 139 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 92 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 188 def main_package_name 'rubygem-foreman_maintain' end
package_manager()
click to toggle source
# File lib/foreman_maintain/package_manager.rb, line 7 def self.package_manager @package_manager ||= if el7? ForemanMaintain::PackageManager::Yum.new elsif el? ForemanMaintain::PackageManager::Dnf.new elsif debian_or_ubuntu? ForemanMaintain::PackageManager::Apt.new else raise 'No supported package manager was found' end end
perform_self_upgrade()
click to toggle source
# File lib/foreman_maintain.rb, line 174 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 149 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 165 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 110 def refresh_features @detector = Detector.new end
reporter()
click to toggle source
# File lib/foreman_maintain.rb, line 114 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_or_ubuntu? 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 73 def set_home_environment ENV['HOME'] ||= '/root' end
setup(options = {})
click to toggle source
# File lib/foreman_maintain.rb, line 63 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 155 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 78 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 161 def upgrade_in_progress storage[:upgrade_target_version] end