module Cloudkeeper::Entities::ImageFormats::Ova

Constants

ARCHIVE_MAX_FILES
OVF_REGEX
VMDK_REGEX

Public Instance Methods

archive_files(archive) click to toggle source
# File lib/cloudkeeper/entities/image_formats/ova.rb, line 15
def archive_files(archive)
  Cloudkeeper::CommandExecutioner.list_archive archive
end
check_file_count!(files) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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