Class: Comfy::Creator
- Inherits:
-
Object
- Object
- Comfy::Creator
- Defined in:
- lib/comfy/creator.rb
Overview
Creates given virtual machine images.
Constant Summary collapse
- TIMESTAMP_FORMAT =
'%Y%m%d%H%M'
- NEEDLE_REPLACEMENTS =
{ :$v => lambda { |instance| instance.send(:version_string) }, :$t => lambda { |instance| Time.new.strftime(TIMESTAMP_FORMAT) }, :$n => lambda { |instance| instance.data[:distro]['name'] }, :$g => lambda { |instance| instance.data[:groups].join(',') } }
- REPLACEMENT_REGEX =
/\$[a-zA-Z]/
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
-
#clean ⇒ Object
Cleans everything from temporary directory.
-
#create ⇒ Object
Method representing the whole creation process.
-
#initialize(options) ⇒ Creator
constructor
Creates a creator instance.
Constructor Details
#initialize(options) ⇒ Creator
Creates a creator instance.
25 26 27 |
# File 'lib/comfy/creator.rb', line 25 def initialize() @data = .clone end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
10 11 12 |
# File 'lib/comfy/creator.rb', line 10 def data @data end |
Instance Method Details
#clean ⇒ Object
Cleans everything from temporary directory
55 56 57 58 59 60 |
# File 'lib/comfy/creator.rb', line 55 def clean if data[:server_dir] logger.debug("Cleaning temporary directory #{data[:server_dir]}.") FileUtils.remove_dir(data[:server_dir]) end end |
#create ⇒ Object
Method representing the whole creation process. Prepares enviroment, prepare files and starts packer job.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/comfy/creator.rb', line 31 def create logger.info('Preparing for image creation...') data[:server_dir] = Dir.mktmpdir('comfy') logger.debug("Server root directory: #{data[:server_dir]}") prepare_data logger.debug("Prepared data: #{data}") templater = Comfy::Templater.new data templater.prepare_files packer_file = "#{data[:server_dir]}/#{data[:distribution]}.packer" run_packer(packer_file) # let's create cloud appliance descriptor files if data[:description] data[:formats].each do |format| File.write(File.join(data[:'output-dir'], "#{data[:identifier]}.json"), description(format)) end end end |