Sha256: f96ab3084bbd8233df6050ac32d99309b311ec031428bcf054f497fcb9d940f5

Contents?: true

Size: 1.53 KB

Versions: 46

Compression:

Stored size: 1.53 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)
      if virtualization_type == HVM_VIRTUALIZATION
        manifest['name'] = manifest['name'].gsub("xen", "xen-hvm")
        manifest['cloud_properties']['name'] = manifest['cloud_properties']['name'].gsub("xen", "xen-hvm")
      end
      manifest['cloud_properties']['ami'] = { region.name => ami_id }
      manifest
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
bosh-stemcell-1.2922.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2915.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2905.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2902.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2891.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2889.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2881.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2865.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2862.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2859.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2858.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2855.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2852.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2849.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2847.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2840.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2839.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2831.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2830.0 lib/bosh/stemcell/aws/light_stemcell.rb
bosh-stemcell-1.2829.0 lib/bosh/stemcell/aws/light_stemcell.rb