Sha256: b5901d80f7bacceb5bbccd18e1f6d9e55a7cd693c2bbe25526eb636411ecff3a

Contents?: true

Size: 1.25 KB

Versions: 112

Compression:

Stored size: 1.25 KB

Contents

require 'yaml'
require 'rake/file_utils_ext'
require 'bosh/stemcell/aws/region'

module Bosh::Stemcell
  class Archive
    attr_reader :path

    def initialize(path = '')
      @path = path
      validate_stemcell
    end

    def manifest
      @manifest ||= Psych.load(`tar -Oxzf #{path} stemcell.MF`)
    end

    def name
      manifest.fetch('name')
    end

    def infrastructure
      cloud_properties.fetch('infrastructure')
    end

    def version
      cloud_properties.fetch('version')
    end

    def sha1
      sha1 = manifest.fetch('sha1')
      raise 'sha1 must not be nil' unless sha1
      sha1.to_s
    end

    def light?
      infrastructure == 'aws' && has_ami?
    end

    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

    private

    def has_ami?
      cloud_properties.has_key? 'ami'
    end

    def cloud_properties
      manifest.fetch('cloud_properties')
    end

    def validate_stemcell
      raise "Cannot find file `#{path}'" unless File.exists?(path)
    end
  end
end

Version data entries

112 entries across 112 versions & 1 rubygems

Version Path
bosh-stemcell-1.3215.4.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3215.3.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3215.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3146.10.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3213.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3202.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3200.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3146.9.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3197.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3196.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3146.8.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3192.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3146.7.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3191.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3189.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3146.6.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3184.1.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3184.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3146.5.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.3181.0 lib/bosh/stemcell/archive.rb