class Bosh::Stemcell::Archive

Attributes

path[R]

Public Class Methods

new(path = '') click to toggle source
# File lib/bosh/stemcell/archive.rb, line 9
def initialize(path = '')
  @path = path
  validate_stemcell
end

Public Instance Methods

extract(tar_options = {}, &block) click to toggle source
# File lib/bosh/stemcell/archive.rb, line 40
def extract(tar_options = {}, &block)
  Dir.mktmpdir do |tmp_dir|
    tar_cmd = "tar xzf #{path} --directory #{tmp_dir}"
    tar_cmd << " --exclude=#{tar_options[:exclude]}" if tar_options.has_key?(:exclude)

    Rake::FileUtilsExt.sh(tar_cmd)

    block.call(tmp_dir, manifest)
  end
end
infrastructure() click to toggle source
# File lib/bosh/stemcell/archive.rb, line 22
def infrastructure
  cloud_properties.fetch('infrastructure')
end
light?() click to toggle source
# File lib/bosh/stemcell/archive.rb, line 36
def light?
  infrastructure == 'aws' && has_ami?
end
manifest() click to toggle source
# File lib/bosh/stemcell/archive.rb, line 14
def manifest
  @manifest ||= Psych.load(`tar -Oxzf #{path} stemcell.MF`)
end
name() click to toggle source
# File lib/bosh/stemcell/archive.rb, line 18
def name
  manifest.fetch('name')
end
sha1() click to toggle source
# File lib/bosh/stemcell/archive.rb, line 30
def sha1
  sha1 = manifest.fetch('sha1')
  raise 'sha1 must not be nil' unless sha1
  sha1.to_s
end
version() click to toggle source
# File lib/bosh/stemcell/archive.rb, line 26
def version
  cloud_properties.fetch('version')
end

Private Instance Methods

cloud_properties() click to toggle source
# File lib/bosh/stemcell/archive.rb, line 57
def cloud_properties
  manifest.fetch('cloud_properties')
end
has_ami?() click to toggle source
# File lib/bosh/stemcell/archive.rb, line 53
def has_ami?
  cloud_properties.has_key? 'ami'
end
validate_stemcell() click to toggle source
# File lib/bosh/stemcell/archive.rb, line 61
def validate_stemcell
  raise "Cannot find file '#{path}'" unless File.exists?(path)
end