Class: Bosh::Bootstrap::MicroboshProviders::AWS

Inherits:
Base
  • Object
show all
Defined in:
lib/bosh-bootstrap/microbosh_providers/aws.rb

Instance Attribute Summary

Attributes inherited from Base

#fog_compute, #manifest_path, #settings

Instance Method Summary collapse

Methods inherited from Base

#create_microbosh_yml, #default_apply_spec, #download_stemcell, #initialize, #jenkins_bucket, #microbosh_name, #private_key_path, #public_ip, #public_ip?, #recent_stemcells, #salted_password, #stemcell_dir, #stemcell_path

Constructor Details

This class inherits a constructor from Bosh::Bootstrap::MicroboshProviders::Base

Instance Method Details

#aws_regionObject



84
85
86
# File 'lib/bosh-bootstrap/microbosh_providers/aws.rb', line 84

def aws_region
  settings.provider.region
end

#cloud_propertiesObject



62
63
64
65
66
67
68
69
70
# File 'lib/bosh-bootstrap/microbosh_providers/aws.rb', line 62

def cloud_properties
  {"access_key_id"=>settings.provider.credentials.aws_access_key_id,
   "secret_access_key"=>settings.provider.credentials.aws_secret_access_key,
   "region"=>settings.provider.region,
   "ec2_endpoint"=>"ec2.#{settings.provider.region}.amazonaws.com",
   "default_security_groups"=>security_groups,
   "default_key_name"=>microbosh_name,
   "ec2_private_key"=>private_key_path}
end

#discover_if_stemcell_image_already_uploadedObject



156
157
158
# File 'lib/bosh-bootstrap/microbosh_providers/aws.rb', line 156

def discover_if_stemcell_image_already_uploaded
  find_ami_for_stemcell(latest_stemcell.stemcell_name, latest_stemcell.version)
end

#find_ami_for_stemcell(name, version) ⇒ String

Usage: find_ami_for_stemcell(“bosh-aws-xen-ubuntu-trusty-go_agent”, “2732”)

Returns:

  • (String)

    Any AMI imageID, e.g. “ami-c19ed3f1” for given BOSH stemcell name/version



149
150
151
152
153
154
# File 'lib/bosh-bootstrap/microbosh_providers/aws.rb', line 149

def find_ami_for_stemcell(name, version)
  image = owned_images.find do |image|
    image["description"] == "#{name} #{version}"
  end
  image["imageId"] if image
end

#latest_stemcellObject

If us-east-1 region, then return light stemcell

Returns:

  • Bosh::Cli::PublicStemcell latest stemcell for aws/trusty



90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/bosh-bootstrap/microbosh_providers/aws.rb', line 90

def latest_stemcell
  @latest_stemcell ||= begin
    trusty_stemcells = if light_stemcell?
      recent_stemcells.select do |s|
        s.name =~ /aws/ && s.name =~ /trusty/ && s.name =~ /^light/
      end
    else
      recent_stemcells.select do |s|
        s.name =~ /aws/ && s.name =~ /trusty/ && s.name =~ /^bosh/
      end
    end
    trusty_stemcells.sort {|s1, s2| s2.version <=> s1.version}.first
  end
end

#light_stemcell?Boolean

only us-east-1 has light stemcells published

Returns:

  • (Boolean)


106
107
108
# File 'lib/bosh-bootstrap/microbosh_providers/aws.rb', line 106

def light_stemcell?
  aws_region == "us-east-1"
end

#network_configurationObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/bosh-bootstrap/microbosh_providers/aws.rb', line 35

def network_configuration
  if vpc?
    {
      "type" =>"manual",
      "ip"   => public_ip,
      "dns"  => [vpc_dns(public_ip)],
      "cloud_properties" => {
        "subnet" => settings.address.subnet_id
      }
    }

  else
    {
      "type"=>"dynamic",
      "vip"=>public_ip
    }
  end
end

#owned_imagesHash

[{"deviceName"=>"/dev/sda",
  "snapshotId"=>"snap-56c7089e",
  "volumeSize"=>2,
  "deleteOnTermination"=>"true",
 "virtualName"=>"ephemeral0"],

“productCodes”=>[], “stateReason”=>{}, “tagSet”=>{“Name”=>“bosh-aws-xen-ubuntu-trusty-go_agent 2732”}, “imageId”=>“ami-c19ed3f1”, “imageLocation”=>“357913607455/BOSH-64a71269-18a2-450b-9e61-713ed70fa62a”, “imageState”=>“available”, “imageOwnerId”=>“357913607455”, “isPublic”=>false, “architecture”=>“x86_64”, “imageType”=>“machine”, “kernelId”=>“aki-94e26fa4”, “name”=>“BOSH-64a71269-18a2-450b-9e61-713ed70fa62a”, “description”=>“bosh-aws-xen-ubuntu-trusty-go_agent 2732”, “rootDeviceType”=>“ebs”, “rootDeviceName”=>“/dev/sda1”, “virtualizationType”=>“paravirtual”, “hypervisor”=>“xen”}

Returns:

  • (Hash)

    description of each self-owned AMI



142
143
144
145
# File 'lib/bosh-bootstrap/microbosh_providers/aws.rb', line 142

def owned_images
  my_images_raw = fog_compute.describe_images('Owner' => 'self')
  my_images_raw.body["imagesSet"]
end

#persistent_diskObject



54
55
56
# File 'lib/bosh-bootstrap/microbosh_providers/aws.rb', line 54

def persistent_disk
  settings.bosh.persistent_disk
end

#resources_cloud_propertiesObject



58
59
60
# File 'lib/bosh-bootstrap/microbosh_providers/aws.rb', line 58

def resources_cloud_properties
  {"instance_type"=>"m1.medium"}
end

#security_groupsObject



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/bosh-bootstrap/microbosh_providers/aws.rb', line 72

def security_groups
  sg_suffix=""
  if vpc?
    sg_suffix="-#{settings.address.vpc_id}"
  end
  [
    "ssh#{sg_suffix}",
    "dns-server#{sg_suffix}",
    "bosh#{sg_suffix}"
  ]
end

#to_hashObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bosh-bootstrap/microbosh_providers/aws.rb', line 6

def to_hash
  data = super.merge({
  "network"=>network_configuration,
   "resources"=>
    {"persistent_disk"=>persistent_disk,
     "cloud_properties"=>resources_cloud_properties},
   "cloud"=>
    {"plugin"=>"aws",
     "properties"=>
      {"aws"=>cloud_properties}},
   "apply_spec"=>
    {"agent"=>
      {"blobstore"=>{"address"=>public_ip},
       "nats"=>{"address"=>public_ip}},
      "properties"=>
        {"aws_registry"=>{"address"=>public_ip},
        "hm"=>{"resurrector_enabled" => true}}},
  })
  if az = settings.exists?("provider.az")
    data["resources"]["cloud_properties"]["availability_zone"] = az
  end
  if vpc?
    dns = settings.exists?("recursor") ? settings.recursor : vpc_dns(public_ip)
    data["apply_spec"]["properties"]["dns"] = {}
    data["apply_spec"]["properties"]["dns"]["recursor"] = dns
  end
  data
end

#vpc?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/bosh-bootstrap/microbosh_providers/aws.rb', line 110

def vpc?
  settings.address["subnet_id"]
end

#vpc_dns(ip_address) ⇒ Object

Note: this should work for all /16 vpcs and may run into issues with other blocks



114
115
116
# File 'lib/bosh-bootstrap/microbosh_providers/aws.rb', line 114

def vpc_dns(ip_address)
  ip_address.gsub(/^(\d+)\.(\d+)\..*/, '\1.\2.0.2')
end