Sha256: 24bc68ecba8d54cd255dad79649a56c549bec25a16ec5cd458a0fae34a8097da

Contents?: true

Size: 1.33 KB

Versions: 139

Compression:

Stored size: 1.33 KB

Contents

require 'cloud'
require 'bosh_aws_cpi'
require 'ostruct'
require 'yaml'
require 'rake'
require 'bosh/stemcell/aws/region'

module Bosh::Stemcell::Aws
  class Ami
    attr_reader :stemcell

    def initialize(stemcell, region)
      @stemcell = stemcell
      @region = region
    end

    def publish
      cloud_config = OpenStruct.new(logger: Logger.new('ami.log'), task_checkpoint: nil)
      Bosh::Clouds::Config.configure(cloud_config)

      cloud = Bosh::Clouds::Provider.create('aws', options)

      stemcell.extract do |tmp_dir, stemcell_manifest|
        ami_id = cloud.create_stemcell("#{tmp_dir}/image", stemcell_manifest['cloud_properties'])
        cloud.ec2.images[ami_id].public = true
        ami_id
      end
    end

    private

    attr_reader :region

    def options
      # just fake the registry struct, as we don't use it
      {
        'aws' => aws,
        'registry' => {
          'endpoint' => 'http://fake.registry',
          'user' => 'fake',
          'password' => 'fake'
        }
      }
    end

    def aws
      access_key_id = ENV['BOSH_AWS_ACCESS_KEY_ID']
      secret_access_key = ENV['BOSH_AWS_SECRET_ACCESS_KEY']

      {
        'default_key_name' => 'fake',
        'region' => region.name,
        'access_key_id' => access_key_id,
        'secret_access_key' => secret_access_key
      }
    end
  end
end

Version data entries

139 entries across 139 versions & 1 rubygems

Version Path
bosh-stemcell-1.2354.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.2347.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.2341.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.2334.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.2311.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.2291.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.2200.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.2175.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.2168.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.2131.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.2129.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.2124.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.2121.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.2089.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.2086.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.2068.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.2063.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.2005.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.1975.0 lib/bosh/stemcell/aws/ami.rb
bosh-stemcell-1.1868.0 lib/bosh/stemcell/aws/ami.rb