Sha256: 3e6949d1402c621a4090d4bf1581fdde8e2bf143c84c94549d987d8d393732be

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

require 'rake/file_utils'
require 'yaml'
require 'common/deep_copy'
require 'bosh/stemcell/aws/region'
require 'bosh/stemcell/aws/ami'

module Bosh::Stemcell::Aws
  HVM_VIRTUALIZATION = 'hvm'

  class LightStemcell
    def initialize(stemcell, virtualization_type)
      @stemcell = stemcell
      @virtualization_type = virtualization_type
    end

    def write_archive
      stemcell.extract(exclude: 'image') do |extracted_stemcell_dir|
        Dir.chdir(extracted_stemcell_dir) do
          FileUtils.touch('image', verbose: true)

          File.open('stemcell.MF', 'w') do |out|
            Psych.dump(manifest, out)
          end

          Rake::FileUtilsExt.sh("sudo tar cvzf #{path} *")
        end
      end
    end

    def path
      stemcell_name = File.basename(stemcell.path)
      stemcell_name = stemcell_name.gsub("xen", "xen-hvm") if virtualization_type == HVM_VIRTUALIZATION
      File.join(File.dirname(stemcell.path), "light-#{stemcell_name}")
    end

    private

    attr_reader :stemcell, :virtualization_type

    def manifest
      region = Region.new
      ami = Ami.new(stemcell, region, virtualization_type)
      ami_id = ami.publish
      manifest = Bosh::Common::DeepCopy.copy(stemcell.manifest)
      manifest['name'] = manifest['name'].gsub("xen", "xen-hvm") if virtualization_type == HVM_VIRTUALIZATION
      manifest['cloud_properties']['ami'] = { region.name => ami_id }
      manifest
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bosh-stemcell-1.2748.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2745.0 lib/bosh/stemcell/aws/light_stemcell.rb