Sha256: df727efbfe9c9c38bd0fd2e81691cdd3a4af2e7138da1fb1473875aef9301af2

Contents?: true

Size: 1.3 KB

Versions: 223

Compression:

Stored size: 1.3 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' && ami_id
    end

    def ami_id(region = Aws::Region::DEFAULT)
      cloud_properties.fetch('ami', {}).fetch(region, nil)
    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 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

223 entries across 223 versions & 1 rubygems

Version Path
bosh-stemcell-1.2776.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2768.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2765.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2754.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2751.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2749.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2748.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2745.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2744.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2743.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2739.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2690.4.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2732.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2719.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2717.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2710.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2707.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2682.1.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2697.0 lib/bosh/stemcell/archive.rb
bosh-stemcell-1.2693.0 lib/bosh/stemcell/archive.rb