Class: Racker::Template
Overview
This class handles the bulk of the legwork working with Racker templates
Instance Method Summary collapse
- #get_builder(type) ⇒ Object
-
#to_packer ⇒ Object
This formats the template into packer format hash.
Methods inherited from Smash
#[], #compact, #convert_value, #deep_merge!, #dup, #method_missing
Methods inherited from Mash
#[]=, #default, #delete, #except, #fetch, from_hash, #initialize, #initialize_copy, #key?, #merge, #regular_update, #regular_writer, #stringify_keys!, #symbolize_keys, #to_hash, #update, #values_at
Constructor Details
This class inherits a constructor from Mash
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Smash
Instance Method Details
#get_builder(type) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/racker/template.rb', line 61 def get_builder(type) case type when /amazon/ Racker::Builders::Amazon.new when /digitalocean/ Racker::Builders::DigitalOcean.new when /docker/ Racker::Builders::Docker.new when /googlecompute/ Racker::Builders::Google.new when /openstack/ Racker::Builders::OpenStack.new when /qemu/ Racker::Builders::QEMU.new when /virtualbox/ Racker::Builders::Virtualbox.new when /vmware/ Racker::Builders::VMware.new else Racker::Builders::Builder.new end end |
#to_packer ⇒ Object
This formats the template into packer format hash
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/racker/template.rb', line 17 def to_packer # Get the global logger log = Log4r::Logger['racker'] # Create the new smash packer = Smash.new # Variables packer['variables'] = self['variables'].dup unless self['variables'].nil? || self['variables'].empty? # Builders packer['builders'] = [] unless self['builders'].nil? || self['builders'].empty? log.info("Processing builders...") self['builders'].each do |name,config| log.info("Processing builder: #{name} with type: #{config['type']}") # Get the builder for this config builder = get_builder(config['type']) # Have the builder convert the config to packer format packer['builders'] << builder.to_packer(name, config.dup) end # Provisioners packer['provisioners'] = [] unless self['provisioners'].nil? || self['provisioners'].empty? log.info("Processing provisioners...") self['provisioners'].sort.map do |index, provisioners| provisioners.each do |name,config| log.debug("Processing provisioner: #{name}") packer['provisioners'] << config.dup end end # Post-Processors packer['post-processors'] = [] unless self['postprocessors'].nil? || self['postprocessors'].empty? log.info("Processing post-processors...") self['postprocessors'].each do |name,config| log.debug("Processing post-processor: #{name}") packer['post-processors'] << config.dup unless config.nil? end packer end |