Module: Cloudkeeper::Entities::ImageFormats::Ova
- Included in:
- Managers::ImageManager
- Defined in:
- lib/cloudkeeper/entities/image_formats/ova.rb
Constant Summary collapse
- OVF_REGEX =
/^.+\.ovf$/i
- VMDK_REGEX =
/^.+\.vmdk$/i
- ARCHIVE_MAX_FILES =
100
Instance Method Summary collapse
- #archive_files(archive) ⇒ Object
- #check_file_count!(files) ⇒ Object
- #ova?(archive) ⇒ Boolean
- #ova_structure?(files) ⇒ Boolean
Instance Method Details
#archive_files(archive) ⇒ Object
15 16 17 |
# File 'lib/cloudkeeper/entities/image_formats/ova.rb', line 15 def archive_files(archive) Cloudkeeper::CommandExecutioner.list_archive archive end |
#check_file_count!(files) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/cloudkeeper/entities/image_formats/ova.rb', line 33 def check_file_count!(files) return unless files.count > ARCHIVE_MAX_FILES raise Cloudkeeper::Errors::Image::Format::Ova::InvalidArchiveError, "Too many files in archive: #{files.count}. "\ "Maximum is #{ARCHIVE_MAX_FILES}" end |
#ova?(archive) ⇒ Boolean
9 10 11 12 13 |
# File 'lib/cloudkeeper/entities/image_formats/ova.rb', line 9 def ova?(archive) ova_structure?(archive_files(archive)) rescue Cloudkeeper::Errors::CommandExecutionError, Cloudkeeper::Errors::Image::Format::Ova::InvalidArchiveError => ex raise Cloudkeeper::Errors::Image::Format::Ova::OvaFormatError, ex end |
#ova_structure?(files) ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cloudkeeper/entities/image_formats/ova.rb', line 19 def ova_structure?(files) check_file_count! files vmdk_count = files.select { |file| VMDK_REGEX =~ file }.count ovf_count = files.select { |file| OVF_REGEX =~ file }.count raise Cloudkeeper::Errors::Image::Format::Ova::InvalidArchiveError, 'Archive contains multiple drives (VMDK files)' \ if vmdk_count > 1 raise Cloudkeeper::Errors::Image::Format::Ova::InvalidArchiveError, 'Archive contains multiple descriptors (OVF files)' \ if ovf_count > 1 vmdk_count == 1 && ovf_count == 1 end |