aerosol 0.5.1 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e6cf29a31c88ffb04c424c3bcbbcb0645d74e071
4
- data.tar.gz: 4e9f58b45fd64a4875e09ec9c3ce0645f82d6ecf
3
+ metadata.gz: b5404b6b9a731bb233826885c52ebf9f6c5cf108
4
+ data.tar.gz: 27a5a1de8fd53f6eff006e359c0d150a89d46b30
5
5
  SHA512:
6
- metadata.gz: 25cb41164e46803c1abe915dd809c12fdf050b3427d6ded99353b1e7ca3a434eb3a74d60f24f1ef66896b3510ea1905483f66bb8c279d59bfce7588026ecc234
7
- data.tar.gz: 525852da882273707a57af5161075dd36a9c1f1ad3abaa032ba8dcc80ed4697c20c7e67a9c4e713f497461e187e876cd481d1ff669e0be043d4fe0465eede0bf
6
+ metadata.gz: d0301f02c37e044904ac243048a66197c2c9b70787540c8957c1a179a4cdd5d0470129b9fd5635d1ea357a8e5cf7bb1de3bb02cfbd2428f94311c6f001b366b6
7
+ data.tar.gz: a8bf540a1255e40d080806250fb07294b98ac568bf773d1c3610fbd5c14b9a9cb3bc05d3795294b62c88fb379e67136184f6d1af5376eb0309dde81798d9c9fe
data/aerosol.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.add_dependency 'activerecord', '>= 3.2.0'
19
19
  gem.add_dependency 'clamp', '~> 0.6'
20
20
  gem.add_dependency 'excon'
21
- gem.add_dependency 'fog', '~> 1.21'
21
+ gem.add_dependency 'aws-sdk', '~> 2.0'
22
22
  gem.add_dependency 'grit'
23
23
  gem.add_dependency 'net-ssh'
24
24
  gem.add_dependency 'net-ssh-gateway'
@@ -3,21 +3,11 @@ class Aerosol::AutoScaling
3
3
  include Dockly::Util::Logger::Mixin
4
4
 
5
5
  logger_prefix '[aerosol auto_scaling]'
6
- aws_attribute :aws_identifier => 'AutoScalingGroupName',
7
- :availability_zones => 'AvailabilityZones',
8
- :min_size => 'MinSize',
9
- :max_size => 'MaxSize',
10
- :default_cooldown => 'DefaultCooldown',
11
- :desired_capacity => 'DesiredCapacity',
12
- :health_check_grace_period => 'HealthCheckGracePeriod',
13
- :health_check_type => 'HealthCheckType',
14
- :load_balancer_names => 'LoadBalancerNames',
15
- :placement_group => 'PlacementGroup',
16
- :tag_from_array => 'Tags',
17
- :created_time => 'CreatedTime',
18
- :vpc_zone_identifier => 'VPCZoneIdentifier'
6
+ aws_attribute :auto_scaling_group_name, :availability_zones, :min_size, :max_size, :default_cooldown,
7
+ :desired_capacity, :health_check_grace_period, :health_check_type, :load_balancer_names,
8
+ :placement_group, :tags, :created_time, :vpc_zone_identifier
19
9
  aws_class_attribute :launch_configuration, Aerosol::LaunchConfiguration
20
- primary_key :aws_identifier
10
+ primary_key :auto_scaling_group_name
21
11
 
22
12
  def initialize(options={}, &block)
23
13
  tag = options.delete(:tag)
@@ -29,21 +19,21 @@ class Aerosol::AutoScaling
29
19
  tags["Deploy"] ||= namespaced_name
30
20
  end
31
21
 
32
- def aws_identifier(arg = nil)
22
+ def auto_scaling_group_name(arg = nil)
33
23
  if arg
34
- raise "You cannot set the aws_identifer directly" unless from_aws
35
- @aws_identifier = arg
24
+ raise "You cannot set the auto_scaling_group_name directly" unless from_aws
25
+ @auto_scaling_group_name = arg
36
26
  else
37
- @aws_identifier || default_identifier
27
+ @auto_scaling_group_name || default_identifier
38
28
  end
39
29
  end
40
30
 
41
31
  def exists?
42
32
  info "auto_scaling: needed?: #{namespaced_name}: " +
43
- "checking for auto scaling group: #{aws_identifier}"
33
+ "checking for auto scaling group: #{auto_scaling_group_name}"
44
34
  exists = super
45
35
  info "auto scaling: needed?: #{namespaced_name}: " +
46
- "#{exists ? 'found' : 'did not find'} auto scaling group: #{aws_identifier}"
36
+ "#{exists ? 'found' : 'did not find'} auto scaling group: #{auto_scaling_group_name}"
47
37
  exists
48
38
  end
49
39
 
@@ -55,62 +45,65 @@ class Aerosol::AutoScaling
55
45
  launch_configuration.create
56
46
  info self.inspect
57
47
 
58
- conn.create_auto_scaling_group(aws_identifier, availability_zones,
59
- launch_configuration.aws_identifier,
60
- max_size, min_size,
61
- create_options)
62
- make_fake_instances
63
- sleep 10 # TODO: switch to fog models and .wait_for { ready? }
48
+ conn.create_auto_scaling_group({
49
+ auto_scaling_group_name: auto_scaling_group_name,
50
+ availability_zones: [*availability_zones],
51
+ launch_configuration_name: launch_configuration.launch_configuration_name,
52
+ max_size: max_size,
53
+ min_size: min_size
54
+ }.merge(create_options))
55
+ sleep 10
64
56
  end
65
57
 
66
58
  def destroy!
67
59
  info self.inspect
68
- conn.delete_auto_scaling_group(aws_identifier, 'ForceDelete' => true)
60
+ conn.delete_auto_scaling_group(auto_scaling_group_name: auto_scaling_group_name, force_delete: true)
69
61
  begin
70
62
  (0..2).each { break if deleting?; sleep 1 }
71
63
  launch_configuration.destroy
72
64
  rescue => ex
73
- info "Launch Config: #{launch_configuration} for #{aws_identifier} was not deleted."
65
+ info "Launch Config: #{launch_configuration} for #{auto_scaling_group_name} was not deleted."
74
66
  info ex.message
75
67
  end
76
68
  end
77
69
 
78
70
  def deleting?
79
- asgs = conn.describe_auto_scaling_groups("AutoScalingGroupNames" => self.aws_identifier)
80
- .body
81
- .[]('DescribeAutoScalingGroupsResult')
82
- .[]('AutoScalingGroups')
71
+ asgs = conn.describe_auto_scaling_groups(auto_scaling_group_names: auto_scaling_group_name).auto_scaling_groups
83
72
 
84
73
  return true if asgs.empty?
85
74
 
86
- asgs.first['Status'].to_s.include?('Delete')
75
+ asgs.first.status.to_s.include?('Delete')
87
76
  end
88
77
 
89
78
  def all_instances
90
- Aerosol::AWS.auto_scaling
91
- .describe_auto_scaling_groups('AutoScalingGroupNames' => self.aws_identifier)
92
- .body
93
- .[]('DescribeAutoScalingGroupsResult')
94
- .[]('AutoScalingGroups')
95
- .first
96
- .[]('Instances')
97
- .map { |instance| Aerosol::Instance.from_hash(instance) }
79
+ conn.describe_auto_scaling_groups(auto_scaling_group_names: [*auto_scaling_group_name])
80
+ .auto_scaling_groups.first
81
+ .instances.map { |instance| Aerosol::Instance.from_hash(instance) }
98
82
  end
99
83
 
100
84
  def tag(val)
101
85
  tags.merge!(val)
102
86
  end
103
87
 
104
- def tags
105
- @tags ||= {}
88
+ def tags(ary=nil)
89
+ if !ary.nil?
90
+ if ary.is_a? Hash
91
+ ary.each do |key, value|
92
+ tag key => value
93
+ end
94
+ else
95
+ ary.each do |struct|
96
+ tag struct[:key] => struct[:value]
97
+ end
98
+ end
99
+ else
100
+ @tags ||= {}
101
+ end
106
102
  end
107
103
 
108
104
  def self.request_all_for_token(next_token)
109
- options = next_token.nil? ? {} : { 'NexToken' => '' }
110
- Aerosol::AWS.auto_scaling
111
- .describe_auto_scaling_groups(options)
112
- .body
113
- .[]('DescribeAutoScalingGroupsResult')
105
+ options = next_token.nil? ? {} : { next_token: next_token }
106
+ Aerosol::AWS.auto_scaling.describe_auto_scaling_groups(options)
114
107
  end
115
108
 
116
109
  def self.request_all
@@ -119,9 +112,9 @@ class Aerosol::AutoScaling
119
112
 
120
113
  begin
121
114
  new_asgs = request_all_for_token(next_token)
122
- asgs.concat(new_asgs['AutoScalingGroups'])
123
- next_token = new_asgs['NextToken']
124
- end while !next_token.nil?
115
+ asgs.concat(new_asgs.auto_scaling_groups)
116
+ next_token = new_asgs.next_token
117
+ end until next_token.nil?
125
118
 
126
119
  asgs
127
120
  end
@@ -133,7 +126,7 @@ class Aerosol::AutoScaling
133
126
 
134
127
  def to_s
135
128
  %{Aerosol::AutoScaling { \
136
- "aws_identifier" => "#{aws_identifier}", \
129
+ "auto_scaling_group_name" => "#{auto_scaling_group_name}", \
137
130
  "availability_zones" => "#{availability_zones}", \
138
131
  "min_size" => "#{min_size}", \
139
132
  "max_size" => "#{max_size}", \
@@ -155,86 +148,20 @@ private
155
148
 
156
149
  def create_options
157
150
  {
158
- 'DefaultCooldown' => default_cooldown,
159
- 'DesiredCapacity' => desired_capacity,
160
- 'HealthCheckGracePeriod' => health_check_grace_period,
161
- 'HealthCheckType' => health_check_type,
162
- 'LoadBalancerNames' => load_balancer_names,
163
- 'PlacementGroup' => placement_group,
164
- 'Tags' => tags,
165
- 'VPCZoneIdentifier' => vpc_zone_identifier
151
+ default_cooldown: default_cooldown,
152
+ desired_capacity: desired_capacity,
153
+ health_check_grace_period: health_check_grace_period,
154
+ health_check_type: health_check_type,
155
+ load_balancer_names: load_balancer_names,
156
+ placement_group: placement_group,
157
+ tags: tags_to_array,
158
+ vpc_zone_identifier: vpc_zone_identifier
166
159
  }.reject { |k, v| v.nil? }
167
160
  end
168
161
 
169
- def tag_from_array(ary)
170
- if ary.is_a? Hash
171
- ary.each do |key, value|
172
- tag key => value
173
- end
174
- else
175
- ary.each do |hash|
176
- tag hash['Key'] => hash['Value']
177
- end
178
- end
179
- end
180
-
181
- # Unfortunately, Fog does not create fake instances after an auto scaling
182
- # group is created.
183
- def make_fake_instances
184
- return unless Fog.mock?
185
-
186
- asg_instances = []
187
- all_instances = []
188
- min_size.times do |n|
189
- instance_id = Fog::AWS::Mock.instance_id
190
- asg_instances << {
191
- 'AvailabilityZone' => availability_zones,
192
- 'HealthStatus' => 'Good',
193
- 'InstanceId' => instance_id,
194
- 'LifecycleState' => 'Pending',
195
- 'LaunchConfigurationName' => launch_configuration.aws_identifier
196
- }
197
-
198
- all_instances << {
199
- 'amiLaunchIndex' => n,
200
- 'architecture' => 'i386',
201
- 'blockDeviceMapping' => [],
202
- 'clientToken' => 'FAKE_CLIENT_TOKEN',
203
- 'dnsName' => 'not-a-real-hostname',
204
- 'ebsOptimized' => false,
205
- 'hypervisor' => 'xen',
206
- 'imageId' => launch_configuration.ami,
207
- 'instanceId' => instance_id,
208
- 'instanceState' => { 'code' => 0, 'name' => 'not pending?' },
209
- 'instanceType' => launch_configuration.instance_type,
210
- 'kernelId' => launch_configuration.kernel_id || Fog::AWS::Mock.kernel_id,
211
- 'keyName' => launch_configuration.key_name,
212
- 'launchTime' => Time.now,
213
- 'monitoring' => { 'state' => false },
214
- 'placement' => { 'availabilityZone' => availability_zones,
215
- 'groupName' => self.aws_identifier,
216
- 'tenancy' => 'default' },
217
- 'privateDnsName' => nil,
218
- 'productCodes' => [],
219
- 'reason' => nil,
220
- 'rootDeviceType' => 'instance-store',
221
- 'virtualizationType' => 'paravirtual',
222
- 'groupIds' => [],
223
- 'groupSet' => launch_configuration.security_groups,
224
- 'iamInstanceProfile' => launch_configuration.iam_role,
225
- 'networkInterfaces' => [],
226
- 'ownerId' => nil,
227
- 'privateIpAddress' => nil,
228
- 'reservationId' => Fog::AWS::Mock.reservation_id,
229
- 'stateReason' => {},
230
- 'ipAddress' => Fog::AWS::Mock.ip_address,
231
- 'privateIpAddress' => Fog::AWS::Mock.private_ip_address
232
- }
233
- end
234
- Aerosol::AWS.auto_scaling.data[:auto_scaling_groups][aws_identifier]
235
- .merge!('Instances' => asg_instances)
236
- all_instances.each do |instance|
237
- Aerosol::AWS.compute.data[:instances][instance['instanceId']] = instance
162
+ def tags_to_array
163
+ tags.map do |key, value|
164
+ { key: key, value: value }
238
165
  end
239
166
  end
240
167
  end
data/lib/aerosol/aws.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'fog/aws'
2
-
3
1
  # This module holds the connections for all AWS services used by the gem.
4
2
  module Aerosol::AWS
5
3
  extend self
@@ -40,23 +38,16 @@ module Aerosol::AWS
40
38
  end
41
39
 
42
40
  def creds
43
- attrs = Hash[env_attrs.map { |attr| [attr, public_send(attr)] }].reject { |k, v| v.nil? }
44
- if attrs.empty?
45
- if ENV['FOG_CREDENTIAL']
46
- attrs = {} # let Fog use the env var
47
- else
48
- attrs = { :use_iam_profile => true }
49
- end
50
- end
51
- attrs
41
+ Hash[env_attrs.map { |attr| [attr, public_send(attr)] }].reject { |k, v| v.nil? }
52
42
  end
53
43
 
54
44
  def reset_cache!
55
45
  services.each { |service| instance_variable_set(:"@#{service}", nil) }
56
46
  end
57
47
 
58
- service :s3, Fog::Storage::AWS
59
- service :compute, Fog::Compute::AWS
60
- service :auto_scaling, Fog::AWS::AutoScaling
61
- env_attr :aws_access_key_id, :aws_secret_access_key
48
+ service :sts, Aws::STS::Client
49
+ service :s3, Aws::S3::Client
50
+ service :compute, Aws::EC2::Client
51
+ service :auto_scaling, Aws::AutoScaling::Client
52
+ env_attr :credentials, :stub_responses
62
53
  end
@@ -42,9 +42,9 @@ module Aerosol::AWSModel
42
42
  @primary_key
43
43
  end
44
44
 
45
- def aws_attribute(hash)
46
- dsl_attribute(*hash.keys)
47
- aws_attributes.merge!(hash)
45
+ def aws_attribute(*attrs)
46
+ dsl_attribute(*attrs)
47
+ aws_attributes.merge(attrs)
48
48
  end
49
49
 
50
50
  def aws_class_attribute(name, klass)
@@ -62,28 +62,28 @@ module Aerosol::AWSModel
62
62
 
63
63
  def all
64
64
  raise 'Please define .request_all to use .all' unless respond_to?(:request_all)
65
- request_all.map { |hash| from_hash(hash) }
65
+ request_all.map { |struct| from_hash(struct.to_hash) }
66
66
  end
67
67
 
68
68
  def from_hash(hash)
69
69
  raise 'To use .from_hash, you must specify a primary_key' if primary_key.nil?
70
70
  refs = Hash[aws_class_attributes.map do |name, klass|
71
- [name, klass.instances.values.find do |inst|
72
- inst.send(klass.primary_key) &&
73
- (inst.send(klass.primary_key) == hash[klass.aws_attributes[klass.primary_key]])
74
- end]
71
+ value = klass.instances.values.find do |inst|
72
+ inst.send(klass.primary_key).to_s == hash[klass.primary_key].to_s unless inst.send(klass.primary_key).nil?
73
+ end
74
+ [name, value]
75
75
  end].reject { |k, v| v.nil? }
76
76
 
77
77
  instance = new!
78
78
  instance.from_aws = true
79
79
 
80
- aws_attributes.each { |k, v| instance.send(k, hash[v]) unless hash[v].nil? }
80
+ aws_attributes.each { |attr| instance.send(attr, hash[attr]) unless hash[attr].nil? }
81
81
  refs.each { |name, inst| instance.send(name, inst.name) }
82
82
  instance
83
83
  end
84
84
 
85
85
  def aws_attributes
86
- @aws_attributes ||= {}
86
+ @aws_attributes ||= Set.new
87
87
  end
88
88
 
89
89
  def aws_class_attributes
@@ -11,7 +11,7 @@ class Aerosol::Connection
11
11
  def with_connection(overridden_host=nil, &block)
12
12
  actual_host = overridden_host || host
13
13
  unless actual_host.is_a?(String)
14
- actual_host = (actual_host.public_hostname || actual_host.private_ip_address)
14
+ actual_host = actual_host.address
15
15
  end
16
16
 
17
17
  if jump
@@ -7,7 +7,7 @@ class Aerosol::Deploy
7
7
  :instance_live_grace_period, :app_port,
8
8
  :continue_if_stop_app_fails, :stop_app_retries,
9
9
  :sleep_before_termination, :post_deploy_command,
10
- :ssl, :log_files, :tail_logs
10
+ :ssl, :log_files, :tail_logs, :assume_role
11
11
 
12
12
  dsl_class_attribute :ssh, Aerosol::Connection
13
13
  dsl_class_attribute :migration_ssh, Aerosol::Connection
@@ -22,6 +22,7 @@ class Aerosol::Deploy
22
22
  default_value :ssl, false
23
23
  default_value :tail_logs, false
24
24
  default_value :log_files, ['/var/log/syslog']
25
+ default_value :assume_role, nil
25
26
 
26
27
  def live_check(arg = nil)
27
28
  case
@@ -60,6 +61,19 @@ class Aerosol::Deploy
60
61
  local_ssh || ssh
61
62
  end
62
63
 
64
+ def perform_role_assumption
65
+ return if assume_role.nil?
66
+ Aws.config.update(
67
+ credentials: Aws::AssumeRoleCredentials.new(
68
+ role_arn: assume_role, role_session_name: 'aerosol'
69
+ )
70
+ )
71
+ end
72
+
73
+ def sts
74
+ Aerosol::AWS.sts
75
+ end
76
+
63
77
  def run_post_deploy
64
78
  return if post_deploy_command.nil?
65
79
  info "running post deploy: #{post_deploy_command}"
@@ -81,7 +95,7 @@ class Aerosol::Deploy
81
95
  end
82
96
  ssh_command << "#{local_ssh_ref.user}@" unless local_ssh_ref.user.nil?
83
97
  end
84
- ssh_command << "#{instance.public_hostname || instance.private_ip_address}"
98
+ ssh_command << "#{instance.address}"
85
99
  end
86
100
 
87
101
  def generate_ssh_commands
@@ -91,11 +105,11 @@ class Aerosol::Deploy
91
105
  ssh_commands = []
92
106
 
93
107
  with_prefix("[#{name}]") do |logger|
94
- logger.info "found group: #{group.aws_identifier}"
108
+ logger.info "found group: #{group.auto_scaling_group_name}"
95
109
  instances = group.all_instances
96
110
  raise "Could not find any instances for auto scaling group #{group.namespaced_name}" if instances.empty?
97
111
  instances.each do |instance|
98
- logger.info "printing ssh command for #{instance.public_hostname || instance.private_ip_address}"
112
+ logger.info "printing ssh command for #{instance.address}"
99
113
  ssh_commands << generate_ssh_command(instance)
100
114
  end
101
115
  end
@@ -1,12 +1,9 @@
1
1
  class Aerosol::Instance
2
2
  include Aerosol::AWSModel
3
3
 
4
- aws_attribute :availability_zone => 'AvailabilityZone',
5
- :health_status => 'HealthStatus',
6
- :id => 'InstanceId',
7
- :lifecycle_state => 'LifecycleState'
4
+ aws_attribute :availability_zone, :health_status, :instance_id, :lifecycle_state
8
5
  aws_class_attribute :launch_configuration, Aerosol::LaunchConfiguration
9
- primary_key :id
6
+ primary_key :instance_id
10
7
 
11
8
  def live?
12
9
  describe_again
@@ -14,19 +11,27 @@ class Aerosol::Instance
14
11
  end
15
12
 
16
13
  def instance_state_name
17
- description['instanceState']['name']
14
+ description[:state][:name]
18
15
  end
19
16
 
20
17
  def public_hostname
21
- description['dnsName']
18
+ description[:public_dns_name]
22
19
  end
23
20
 
24
21
  def private_ip_address
25
- description['privateIpAddress']
22
+ description[:private_ip_address]
26
23
  end
27
24
 
28
- def ami
29
- description['imageId']
25
+ def address
26
+ if public_hostname.blank?
27
+ private_ip_address
28
+ else
29
+ public_hostname
30
+ end
31
+ end
32
+
33
+ def image_id
34
+ description[:image_id]
30
35
  end
31
36
 
32
37
  def description
@@ -36,16 +41,14 @@ class Aerosol::Instance
36
41
  def self.request_all
37
42
  Aerosol::AWS.auto_scaling
38
43
  .describe_auto_scaling_instances
39
- .body
40
- .[]('DescribeAutoScalingInstancesResult')
41
- .[]('AutoScalingInstances')
44
+ .auto_scaling_instances
42
45
  end
43
46
 
44
47
  private
45
48
  def describe!
46
- ensure_present! :id
47
- result = Aerosol::AWS.compute.describe_instances('instance-id' => id).body
48
- result['reservationSet'].first['instancesSet'].first rescue nil
49
+ ensure_present! :instance_id
50
+ result = Aerosol::AWS.compute.describe_instances(instance_ids: [instance_id])
51
+ result.reservations.first.instances.first.to_h rescue nil
49
52
  end
50
53
 
51
54
  def describe_again
@@ -3,60 +3,63 @@ class Aerosol::LaunchConfiguration
3
3
  include Dockly::Util::Logger::Mixin
4
4
 
5
5
  logger_prefix '[aerosol launch_configuration]'
6
- aws_attribute :aws_identifier => 'LaunchConfigurationName',
7
- :ami => 'ImageId',
8
- :instance_type => 'InstanceType',
9
- :security_groups => 'SecurityGroups',
10
- :user_data => 'UserData',
11
- :iam_role => 'IamInstanceProfile',
12
- :kernel_id => 'KernelId',
13
- :key_name => 'KeyName',
14
- :spot_price => 'SpotPrice',
15
- :created_time => 'CreatedTime',
16
- :associate_public_ip_address => 'AssociatePublicIpAddress'
17
-
18
- primary_key :aws_identifier
6
+ aws_attribute :launch_configuration_name, :image_id, :instance_type, :security_groups, :user_data,
7
+ :iam_instance_profile, :kernel_id, :key_name, :spot_price, :created_time,
8
+ :associate_public_ip_address
9
+
10
+ primary_key :launch_configuration_name
19
11
  default_value(:security_groups) { [] }
20
12
 
21
- def aws_identifier(arg = nil)
13
+ def launch_configuration_name(arg = nil)
22
14
  if arg
23
- raise "You cannot set the aws_identifer directly" unless from_aws
24
- @aws_identifier = arg
15
+ raise "You cannot set the launch_configuration_name directly" unless from_aws
16
+ @launch_configuration_name = arg
25
17
  else
26
- @aws_identifier || default_identifier
18
+ @launch_configuration_name || default_identifier
27
19
  end
28
20
  end
29
21
 
22
+ def ami(name=nil)
23
+ warn 'Warning: Use `image_id` instead `ami` for a launch configuration'
24
+ image_id(name)
25
+ end
26
+
27
+ def iam_role(name=nil)
28
+ warn 'Warning: Use `iam_instance_profile` instead `iam_role` for a launch configuration'
29
+ iam_instance_profile(name)
30
+ end
31
+
30
32
  def security_group(group)
31
33
  security_groups << group
32
34
  end
33
35
 
34
36
  def create!
35
- ensure_present! :ami, :instance_type
37
+ ensure_present! :image_id, :instance_type
36
38
 
37
39
  info self.to_s
38
- conn.create_launch_configuration(ami, instance_type, aws_identifier, create_options)
40
+ conn.create_launch_configuration({
41
+ image_id: image_id,
42
+ instance_type: instance_type,
43
+ launch_configuration_name: launch_configuration_name,
44
+ }.merge(create_options))
39
45
  sleep 10 # TODO: switch to fog models and .wait_for { ready? }
40
46
  end
41
47
 
42
48
  def destroy!
43
49
  info self.to_s
44
- conn.delete_launch_configuration(aws_identifier)
50
+ conn.delete_launch_configuration(launch_configuration_name: launch_configuration_name)
45
51
  end
46
52
 
47
53
  def all_instances
48
54
  Aerosol::Instance.all.select { |instance|
49
55
  !instance.launch_configuration.nil? &&
50
- (instance.launch_configuration.aws_identifier == self.aws_identifier)
56
+ (instance.launch_configuration.launch_configuration_name == launch_configuration_name)
51
57
  }.each(&:description)
52
58
  end
53
59
 
54
60
  def self.request_all_for_token(next_token)
55
- options = next_token.nil? ? {} : { 'NextToken' => next_token }
56
- Aerosol::AWS.auto_scaling
57
- .describe_launch_configurations(options)
58
- .body
59
- .[]('DescribeLaunchConfigurationsResult')
61
+ options = next_token.nil? ? {} : { next_token: next_token }
62
+ Aerosol::AWS.auto_scaling.describe_launch_configurations(options)
60
63
  end
61
64
 
62
65
  def self.request_all
@@ -65,21 +68,21 @@ class Aerosol::LaunchConfiguration
65
68
 
66
69
  begin
67
70
  new_lcs = request_all_for_token(next_token)
68
- lcs.concat(new_lcs['LaunchConfigurations'])
69
- next_token = new_lcs['NextToken']
70
- end while !next_token.nil?
71
+ lcs.concat(new_lcs.launch_configurations)
72
+ next_token = new_lcs.next_token
73
+ end until next_token.nil?
71
74
 
72
75
  lcs
73
76
  end
74
77
 
75
78
  def to_s
76
79
  %{Aerosol::LaunchConfiguration { \
77
- "aws_identifier" => "#{aws_identifier}", \
78
- "ami" => "#{ami}", \
80
+ "launch_configuration_name" => "#{launch_configuration_name}", \
81
+ "image_id" => "#{image_id}", \
79
82
  "instance_type" => "#{instance_type}", \
80
83
  "security_groups" => #{security_groups.to_s}, \
81
84
  "user_data" => "#{user_data}", \
82
- "iam_role" => "#{iam_role}", \
85
+ "iam_instance_profile" => "#{iam_instance_profile}", \
83
86
  "kernel_id" => "#{kernel_id}", \
84
87
  "key_name" => "#{key_name}", \
85
88
  "spot_price" => "#{spot_price}", \
@@ -90,13 +93,13 @@ class Aerosol::LaunchConfiguration
90
93
  private
91
94
  def create_options
92
95
  { # TODO Add dsl so that 'BlockDeviceMappings' may be specified
93
- 'IamInstanceProfile' => iam_role,
94
- 'KernelId' => kernel_id,
95
- 'KeyName' => key_name,
96
- 'SecurityGroups' => security_groups,
97
- 'SpotPrice' => spot_price,
98
- 'UserData' => Aerosol::Util.strip_heredoc(user_data || ''),
99
- 'AssociatePublicIpAddress' => associate_public_ip_address
96
+ iam_instance_profile: iam_instance_profile,
97
+ kernel_id: kernel_id,
98
+ key_name: key_name,
99
+ security_groups: security_groups,
100
+ spot_price: spot_price,
101
+ user_data: Base64.encode64(Aerosol::Util.strip_heredoc(user_data || '')),
102
+ associate_public_ip_address: associate_public_ip_address
100
103
  }.reject { |k, v| v.nil? }
101
104
  end
102
105