class Berta::CLI
CLI
for berta
Public Class Methods
safe_fetch(keys)
click to toggle source
# File lib/berta/cli.rb, line 8 def self.safe_fetch(keys) current = Berta::Settings keys.each do |key| current = current[key] break unless current end current end
Public Instance Methods
cleanup()
click to toggle source
# File lib/berta/cli.rb, line 79 def cleanup initialize_configuration(options) initialize_logger(options) initialize_email Berta::CommandExecutor.new.cleanup end
config()
click to toggle source
# File lib/berta/cli.rb, line 92 def config initialize_configuration(options) Berta::Settings.each { |key, val| $stdout.puts "#{key}\t=\t#{val}" } end
version()
click to toggle source
# File lib/berta/cli.rb, line 87 def version $stdout.puts Berta::VERSION end
Private Instance Methods
initialize_configuration(options)
click to toggle source
# File lib/berta/cli.rb, line 101 def initialize_configuration(options) settings = Hash.new { |hash, key| hash[key] = {} } settings['opennebula']['secret'] = options['opennebula-secret'] settings['opennebula']['endpoint'] = options['opennebula-endpoint'] settings['expiration']['offset'] = options['expiration-offset'] settings['expiration']['action'] = options['expiration-action'] settings['notification']['deadline'] = options['notification-deadline'] settings['filter']['type'] = options['filter-type'] settings['filter']['ids'] = options['filter-ids'] settings['filter']['users'] = options['filter-users'] settings['filter']['groups'] = options['filter-groups'] settings['filter']['clusters'] = options['filter-clusters'] settings['dry-run'] = options['dry-run'] settings['debug'] = options['debug'] settings['logging']['file'] = options['logging-file'] settings['logging']['level'] = options['logging-level'] settings['email-template'] = options['email-template'] settings['email-type'] = options['email-type'] settings['smtp']['address'] = options['smtp-address'] settings['smtp']['port'] = options['smtp-port'] Berta::Settings.merge!(settings) end
initialize_email()
click to toggle source
# File lib/berta/cli.rb, line 144 def initialize_email email_type = Berta::Settings['email-type'] params = {} params = Berta::Settings[email_type].each_with_object({}) { |(k, v), h| h[k.to_sym] = v } if Berta::Settings[email_type] Mail.defaults { delivery_method email_type.to_sym, params } end
initialize_logger(options)
click to toggle source
# File lib/berta/cli.rb, line 124 def initialize_logger(options) logging_level = options['logging-level'] logging_level = 'debug' if options['debug'] || options['dry-run'] Yell.new :stdout, name: Object, level: logging_level, format: Yell::DefaultFormat Object.send :include, Yell::Loggable setup_file_logger(options['logging-file']) if options['logging-file'] logger.debug { 'Running in debug mode...' } end
setup_file_logger(logging_file)
click to toggle source
# File lib/berta/cli.rb, line 136 def setup_file_logger(logging_file) unless (File.exist?(logging_file) && File.writable?(logging_file)) || File.writable?(File.dirname(logging_file)) logger.error "File #{logging_file} isn't writable" return end logger.adapter :file, logging_file end