# File lib/foreman_maintain.rb, line 170 def main_package_name 'rubygem-foreman_maintain' end
# File lib/foreman_maintain.rb, line 116 def allowed_available_procedures(*args) procedures = detector.available_procedures(*args) procedures.select(&:advanced_run?) end
# File lib/foreman_maintain.rb, line 108 def available_checks(*args) detector.available_checks(*args) end
# File lib/foreman_maintain.rb, line 100 def available_features(*args) detector.available_features(*args) end
# File lib/foreman_maintain.rb, line 112 def available_procedures(*args) detector.available_procedures(*args) end
# File lib/foreman_maintain.rb, line 104 def available_scenarios(*args) detector.available_scenarios(*args) end
# File lib/foreman_maintain.rb, line 88 def cache ObjectCache.instance end
# File lib/foreman_maintain.rb, line 74 def config_file config.config_file end
# File lib/foreman_maintain.rb, line 92 def detector @detector ||= Detector.new end
# File lib/foreman_maintain.rb, line 121 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
# File lib/foreman_maintain.rb, line 78 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
# File lib/foreman_maintain.rb, line 170 def main_package_name 'rubygem-foreman_maintain' end
# File lib/foreman_maintain/package_manager.rb, line 6 def self.package_manager @package_manager ||= case (%w[dnf yum apt].find { |manager| !%xcommand -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
# File lib/foreman_maintain.rb, line 156 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 0 end puts "Nothing to update, can't find new version of #{package_name}." end
# File lib/foreman_maintain.rb, line 131 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
# File lib/foreman_maintain.rb, line 147 def pkg_and_cmd_name instance_feature = ForemanMaintain.available_features(:label => :instance).first if instance_feature.downstream return %w[satellite-maintain satellite-maintain] end [main_package_name, 'foreman-maintain'] end
# File lib/foreman_maintain.rb, line 96 def reporter @reporter ||= ForemanMaintain::Reporter::CLIReporter.new end
# File lib/foreman_maintain.rb, line 55 def setup(options = {}) # 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
# File lib/foreman_maintain.rb, line 137 def storage(label = :default) ForemanMaintain::YamlStorage.load(label) rescue StandardError => e logger.error "Invalid Storage label i.e #{label}. Error - #{e.message}" end
Appending PATH with expected paths needed for commands we run
# File lib/foreman_maintain.rb, line 64 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
# File lib/foreman_maintain.rb, line 143 def upgrade_in_progress storage[:upgrade_target_version] end