class Comfy::CommandExecutioner
Public Class Methods
available_distributions()
click to toggle source
Method listing available distributions from template directory.
@return [Hash] distributions structure containing info about them
# File lib/comfy/command_executioner.rb, line 12 def available_distributions dir = Comfy::TEMPLATE_DIR return {} unless File.exist? dir description_files = Dir.glob(File.join(dir, '*', '*.description')).sort distributions = {} description_files.each do |description_file| unless JSON::Validator.validate(Comfy::DESCRIPTION_SCHEMA_FILE, description_file) puts "Invalid distribution description #{description_file.inspect}, skipping." next end description = File.read(description_file) json = JSON.parse(description) name = json['name'] distributions[name] = [] json['versions'].each do |version| version_string = [] version_string << version['major_version'] version_string << version['minor_version'] version_string << version['patch_version'] distributions[name] << version_string.compact.join('.') distributions[name].sort!.reverse! end end distributions end
Public Instance Methods
clean_cache()
click to toggle source
# File lib/comfy/command_executioner.rb, line 92 def clean_cache dir = options['cache-dir'] FileUtils.rm_r Dir.glob(File.join(dir, '*')) puts 'Cache cleaned successfully.' end
distributions()
click to toggle source
# File lib/comfy/command_executioner.rb, line 63 def distributions self.class.available_distributions.each do |distribution, versions| versions.each { |version| $stdout.puts "#{distribution} #{version}" } end end
export()
click to toggle source
# File lib/comfy/command_executioner.rb, line 75 def export dir = options['destination'] FileUtils.mkdir_p dir unless File.exist?(dir) && File.directory?(dir) FileUtils.cp_r(File.join(Comfy::TEMPLATE_DIR, '.'), dir) $stdout.puts 'Template files copied successfully.' $stdout.puts "In order to use the new template directory change setting 'vm_templates_dir' in your configuration file to:" $stdout.puts "template-dir: #{File.absolute_path(dir)}" end
version()
click to toggle source
# File lib/comfy/command_executioner.rb, line 58 def version $stdout.puts Comfy::VERSION end
Private Instance Methods
check_distribution_files(distribution_name)
click to toggle source
# File lib/comfy/command_executioner.rb, line 217 def check_distribution_files(distribution_name) distribution_cfg = File.join(Comfy::TEMPLATE_DIR, distribution_name, "#{distribution_name}.cfg.erb") unless File.exist?(distribution_cfg) logger.error "Missing distribution configuration #{distribution_cfg.inspect}, cannot build VM" exit end distribution_desc = File.join(Comfy::TEMPLATE_DIR, distribution_name, "#{distribution_name}.description") unless File.exist?(distribution_desc) logger.error "Missing distribution description #{distribution_desc.inspect}, cannot build VM" exit end end
init_log(parameters)
click to toggle source
Inits logging according to the settings
@param [Hash] parameters @option parameters [String] logging-level @option parameters [String] logging-file file to log to @option parameters [TrueClass, FalseClass] debug debug mode @return [Type] description of returned object
# File lib/comfy/command_executioner.rb, line 198 def init_log(parameters) if parameters[:debug] parameters[:'logging-level'] = 'DEBUG' ENV['PACKER_LOG'] = '1' end Yell.new :stdout, :name => Object, :level => parameters[:'logging-level'].downcase, :format => Yell::DefaultFormat Object.send :include, Yell::Loggable if parameters[:'logging-file'] unless (File.exist?(parameters[:'logging-file']) && File.writable?(parameters[:'logging-file'])) || (File.writable?(File.dirname(parameters[:'logging-file']))) logger.error "File #{parameters[:'logging-file']} isn't writable" return end logger.adapter :file, parameters[:'logging-file'] end end
start(distribution_name, options)
click to toggle source
# File lib/comfy/command_executioner.rb, line 172 def start(distribution_name, options) parameters = options.to_hash.deep_symbolize_keys parameters[:distribution] = distribution_name parameters[:headless] = !parameters[:debug] ENV['PACKER_CACHE_DIR'] = parameters[:'cache-dir'] init_log parameters check_distribution_files distribution_name logger.debug "Parameters: #{parameters}" begin creator = Comfy::Creator.new(parameters) creator.create ensure creator.clean end end