ec2launcher 1.0.7 → 1.0.8

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.
data/CHANGELOG.md CHANGED
@@ -1,11 +1,18 @@
1
- ## 1.0.7 (18-July-2012)
1
+ ## 1.0.8
2
+
3
+ * Create instance with security group ids, instead of security group names. Fixes problem when launching an instance into a VPC with a security group that exists with the same name in the public cloud and in the vpc.
4
+ * Automatically find security group ids from names, given a subnet.
5
+ * Display private ip adress after launching.
6
+ * Overhaul environment inheritance.
7
+
8
+ ## 1.0.7
2
9
 
3
10
  * Fixed problem with inheriting from default environment.
4
11
 
5
- ## 1.0.6 (18-July-2012)
12
+ ## 1.0.6
6
13
 
7
14
  * Update environment inheritence to merge (instead of replace) gems, packages, roles, commands and security groups.
8
15
 
9
- ## 1.0.5 (18-July-2012)
16
+ ## 1.0.5
10
17
 
11
18
  * Fixed bug with resolving environment names when using an environment alias.
@@ -20,6 +20,7 @@ module EC2Launcher
20
20
  @postcommands = []
21
21
  @roles = []
22
22
  @security_groups = []
23
+
23
24
  end
24
25
 
25
26
  def environment(name)
@@ -209,6 +210,7 @@ module EC2Launcher
209
210
  @email_notifications = other_env.email_notifications unless other_env.email_notifications.nil?
210
211
  @key_name = other_env.key_name unless other_env.key_name.nil?
211
212
  @subnet = other_env.subnet unless other_env.subnet.nil?
213
+ @shortname = other_env.short_name unless other_env.short_name.nil?
212
214
  end
213
215
 
214
216
  def load(dsl)
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2012 Sean Laurent
3
3
  #
4
4
  module Ec2launcher
5
- VERSION = "1.0.7"
5
+ VERSION = "1.0.8"
6
6
  end
data/lib/ec2launcher.rb CHANGED
@@ -68,6 +68,7 @@ module EC2Launcher
68
68
  end
69
69
  end
70
70
  @default_environment ||= EC2Launcher::Environment.new
71
+ @default_environment.inherit(nil)
71
72
 
72
73
  # Load other environments
73
74
  @environments = { }
@@ -102,8 +103,6 @@ module EC2Launcher
102
103
 
103
104
  # Process inheritance rules for environments
104
105
  @environments.values.each do |env|
105
- next if env.inherit.nil?
106
-
107
106
  new_env = process_environment_inheritance(env)
108
107
  @environments[new_env.name] = new_env
109
108
  end
@@ -147,7 +146,20 @@ module EC2Launcher
147
146
  # Initialize AWS and create EC2 connection
148
147
  initialize_aws()
149
148
  @ec2 = AWS::EC2.new
150
-
149
+
150
+ ##############################
151
+ # SUBNET
152
+ ##############################
153
+ subnet = nil
154
+ subnet = @application.subnet unless @application.subnet.nil?
155
+ subnet ||= @environment.subnet unless @environment.subnet.nil?
156
+
157
+ ec2_subnet = nil
158
+ unless subnet.nil?
159
+ # Find the matching EC2 subnet
160
+ ec2_subnet = @ec2.subnets[subnet]
161
+ end
162
+
151
163
  ##############################
152
164
  # AVAILABILITY ZONES
153
165
  ##############################
@@ -173,11 +185,26 @@ module EC2Launcher
173
185
  # SECURITY GROUPS
174
186
  ##############################
175
187
  security_groups = []
176
- puts "ENV: #{@environment.security_groups}"
177
- puts "APP: #{@application.security_groups_for_environment(@environment.name)}"
178
188
  security_groups += @environment.security_groups unless @environment.security_groups.nil?
179
189
  security_groups += @application.security_groups_for_environment(@environment.name)
180
190
 
191
+ # Build mapping of existing security group names to security group objects
192
+ sg_map = { }
193
+ AWS.start_memoizing
194
+ @ec2.security_groups.each do |sg|
195
+ unless ec2_subnet.nil?
196
+ next unless ec2_subnet.vpc_id == sg.vpc_id
197
+ end
198
+ sg_map[sg.name] = sg
199
+ end
200
+ AWS.stop_memoizing
201
+
202
+ # Convert security group names to security group ids
203
+ security_group_ids = []
204
+ security_groups.each do |sg_name|
205
+ security_group_ids << sg_map[sg_name].security_group_id
206
+ end
207
+
181
208
  ##############################
182
209
  # INSTANCE TYPE
183
210
  ##############################
@@ -243,13 +270,6 @@ module EC2Launcher
243
270
  roles += @environment.roles unless @environment.roles.nil?
244
271
  roles += @application.roles_for_environment(@environment.name)
245
272
 
246
- ##############################
247
- # Packages - preinstall
248
- ##############################
249
- subnet = nil
250
- subnet = @application.subnet unless @application.subnet.nil?
251
- subnet ||= @environment.subnet unless @environment.subnet.nil?
252
-
253
273
  ##############################
254
274
  # Gems - preinstall
255
275
  ##############################
@@ -334,20 +354,20 @@ rm -f /tmp/runurl"
334
354
  ##############################
335
355
  puts
336
356
  puts "Availability zone: #{availability_zone}"
337
- puts "Key name : #{key_name}"
338
- puts "Security groups : #{security_groups.join(", ")}"
339
- puts "Instance type : #{instance_type}"
340
- puts "Architecture : #{instance_architecture}"
341
- puts "AMI name : #{ami.ami_name}"
342
- puts "AMI id : #{ami.ami_id}"
343
- puts "Name : #{hostname}"
344
- puts "ELB : #{elb_name}" if elb_name
345
- puts "Chef PEM : #{chef_validation_pem_url}"
346
- puts "AWS key file : #{aws_keyfile}"
347
- puts "Roles : #{roles.join(', ')}"
348
- puts "Gems : #{gems.join(', ')}"
349
- puts "Packages : #{packages.join(', ')}"
350
- puts "VPC Subnet : #{subnet}" if subnet
357
+ puts "Key name : #{key_name}"
358
+ puts "Security groups : " + security_groups.collect {|name| "#{name} (#{sg_map[name].security_group_id})"}.join(", ")
359
+ puts "Instance type : #{instance_type}"
360
+ puts "Architecture : #{instance_architecture}"
361
+ puts "AMI name : #{ami.ami_name}"
362
+ puts "AMI id : #{ami.ami_id}"
363
+ puts "Name : #{hostname}"
364
+ puts "ELB : #{elb_name}" if elb_name
365
+ puts "Chef PEM : #{chef_validation_pem_url}"
366
+ puts "AWS key file : #{aws_keyfile}"
367
+ puts "Roles : #{roles.join(', ')}"
368
+ puts "Gems : #{gems.join(', ')}"
369
+ puts "Packages : #{packages.join(', ')}"
370
+ puts "VPC Subnet : #{subnet}" if subnet
351
371
 
352
372
  unless block_device_mappings.empty?
353
373
  block_device_mappings.keys.sort.each do |key|
@@ -376,7 +396,7 @@ rm -f /tmp/runurl"
376
396
  ##############################
377
397
  # Launch the new intance
378
398
  ##############################
379
- instance = launch_instance(hostname, ami.ami_id, availability_zone, key_name, security_groups, instance_type, user_data, block_device_mappings, block_device_tags, subnet)
399
+ instance = launch_instance(hostname, ami.ami_id, availability_zone, key_name, security_group_ids, instance_type, user_data, block_device_mappings, block_device_tags, subnet)
380
400
 
381
401
  ##############################
382
402
  # ELB
@@ -391,6 +411,7 @@ rm -f /tmp/runurl"
391
411
  puts "Instance id: #{instance.id}"
392
412
  puts "Public dns : #{instance.public_dns_name}"
393
413
  puts "Private dns: #{instance.private_dns_name}"
414
+ puts "Private ip : #{instance.private_ip_address}"
394
415
  puts "********************"
395
416
  end
396
417
 
@@ -593,7 +614,7 @@ rm -f /tmp/runurl"
593
614
  # @param [String] ami_id id for the AMI to use.
594
615
  # @param [String] availability_zone EC2 availability zone to use
595
616
  # @param [String] key_name EC2 SSH key to use.
596
- # @param [Array<String>] security_groups list of security groups.
617
+ # @param [Array<String>] security_group_ids list of security groups ids
597
618
  # @param [String] instance_type EC2 instance type.
598
619
  # @param [String] user_data command data to store pass to the instance in the EC2 user-data field.
599
620
  # @param [Hash<String,Hash<String, String>, nil] block_device_mappings mapping of device names to block device details.
@@ -601,7 +622,7 @@ rm -f /tmp/runurl"
601
622
  # @param [Hash<String,Hash<String, String>>, nil] block_device_tags mapping of device names to hash objects with tags for the new EBS block devices.
602
623
  #
603
624
  # @return [AWS::EC2::Instance] newly created EC2 instance or nil if the launch failed.
604
- def launch_instance(hostname, ami_id, availability_zone, key_name, security_groups, instance_type, user_data, block_device_mappings = nil, block_device_tags = nil, vpc_subnet = nil)
625
+ def launch_instance(hostname, ami_id, availability_zone, key_name, security_group_ids, instance_type, user_data, block_device_mappings = nil, block_device_tags = nil, vpc_subnet = nil)
605
626
  puts "Launching instance..."
606
627
  new_instance = nil
607
628
  run_with_backoff(30, 1, "launching instance") do
@@ -609,7 +630,7 @@ rm -f /tmp/runurl"
609
630
  :image_id => ami_id,
610
631
  :availability_zone => availability_zone,
611
632
  :key_name => key_name,
612
- :security_groups => security_groups,
633
+ :security_group_ids => security_group_ids,
613
634
  :user_data => user_data,
614
635
  :instance_type => instance_type,
615
636
  :block_device_mappings => block_device_mappings,
@@ -686,15 +707,9 @@ rm -f /tmp/runurl"
686
707
  return nil
687
708
  end
688
709
 
689
- new_env = Marshal::load(Marshal.dump(default_environment)) unless default_environment.nil?
690
- new_env ||= EC2Launcher::Environment.new
691
-
692
710
  load_env = EC2Launcher::Environment.new
693
711
  load_env.load(File.read(name))
694
-
695
- new_env.merge(load_env)
696
-
697
- new_env
712
+ load_env
698
713
  end
699
714
 
700
715
  # Attempts to build a list of valid directories.
@@ -746,10 +761,13 @@ rm -f /tmp/runurl"
746
761
  end
747
762
 
748
763
  def process_environment_inheritance(env)
749
- return env if env.inherit.nil?
750
-
751
764
  # Find base environment
752
- base_env = @environments[env.inherit]
765
+ base_env = nil
766
+ if env.inherit.nil?
767
+ base_env = @default_environment
768
+ else
769
+ base_env = @environments[env.inherit]
770
+ end
753
771
  abort("Invalid inheritance '#{env.inherit}' in #{env.name}") if base_env.nil?
754
772
 
755
773
  new_env = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2launcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: