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

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_count!(files) ⇒ Object



32
33
34
35
36
37
# File 'lib/cloudkeeper/entities/image_formats/ova.rb', line 32

def check_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

Returns:

  • (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

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cloudkeeper/entities/image_formats/ova.rb', line 19

def ova_structure?(files)
  check_count! files
  has_ovf = has_vmdk = false

  files.each do |file|
    has_ovf ||= OVF_REGEX =~ file
    has_vmdk ||= VMDK_REGEX =~ file
    break if has_ovf && has_vmdk
  end

  has_ovf && has_vmdk
end