Class: Itchy::ImageTransformer
- Inherits:
-
Object
- Object
- Itchy::ImageTransformer
- Defined in:
- lib/itchy/image_transformer.rb
Overview
Wraps image format conversion methods and helpers.
Constant Summary collapse
- KNOWN_IMAGE_ARCHIVES =
Registered image formats and archives
%w(ova tar).freeze
- KNOWN_IMAGE_FORMATS =
%w(cow dmg parallels qcow qcow2 raw vdi vmdk vhd).freeze
- ARCHIVE_STRING =
Archive format string msg
'POSIX tar archive'
- FORMAT_PATTERN =
REGEX pattern for getting image format
/format:\s(.*?)$/
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ImageTransformer
constructor
Creates a class instance.
-
#transform!(metadata, vmcatcher_configuration) ⇒ String
Transforms image(s) associated with the given event to formats preferred by the underlying image datastore.
Constructor Details
#initialize(options = {}) ⇒ ImageTransformer
Creates a class instance.
17 18 19 20 21 22 23 24 25 |
# File 'lib/itchy/image_transformer.rb', line 17 def initialize( = {}) = @inputs = ([] << KNOWN_IMAGE_FORMATS << KNOWN_IMAGE_ARCHIVES).flatten #fail ArgumentError, 'Unsupported input image format enabled in configuration! ' # "#{@inputs.inspect}" unless (@options.input_image_formats - @inputs).empty? # fail "Unsupported output image format enabled in configuration! " # "#{KNOWN_IMAGE_FORMATS.inspect}" unless (@options.required_format - KNOWN_IMAGE_FORMATS).empty? end |
Instance Method Details
#transform!(metadata, vmcatcher_configuration) ⇒ String
Transforms image(s) associated with the given event to formats preferred by the underlying image datastore. This process includes unpacking of archive & conversion of image files.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/itchy/image_transformer.rb', line 34 def transform!(, vmcatcher_configuration) Itchy::Log.info "[#{self.class.name}] Transforming image format " \ "for #{metadata.dc_identifier.inspect}" begin if archived?(.dc_identifier.inspect) unpacking_dir = unpack_archived!(, vmcatcher_configuration) file_format = inspect_unpacked_dir(unpacking_dir, ) else file_format = format(orig_image_file(, vmcatcher_configuration)) unpacking_dir = copy_unpacked!(, vmcatcher_configuration) end if file_format == .required_format new_file_name = copy_same_format(unpacking_dir, ) else converter = Itchy::FormatConverter.new(unpacking_dir, , vmcatcher_configuration) new_file_name = converter.convert!(file_format, .required_format, .output_dir) end remove_dir(unpacking_dir) rescue Itchy::Errors::FileInspectError, Itchy::Errors::FormatConversionError, Itchy::Errors::PrepareEnvError => ex fail Itchy::Errors::ImageTransformationError, ex end new_file_name end |