ec2launcher 1.0.22 → 1.0.23

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,3 +1,9 @@
1
+ ## 1.0.23
2
+
3
+ * Display subnet CIDR block when launching instances into VPCs.
4
+ * Revamped output to use log4r.
5
+ * Added command line flags to control output verbosity.
6
+
1
7
  ## 1.0.22
2
8
 
3
9
  * Fixed additional bug with merging applications.
data/ec2launcher.gemspec CHANGED
@@ -15,4 +15,5 @@ Gem::Specification.new do |gem|
15
15
  gem.version = EC2Launcher::VERSION
16
16
 
17
17
  gem.add_runtime_dependency "aws-sdk", [">= 1.5.0"]
18
+ gem.add_runtime_dependency "log4r"
18
19
  end
@@ -98,7 +98,7 @@ module EC2Launcher
98
98
  @options.instance_type = instance_type
99
99
  end
100
100
 
101
- opts.on("-v", "--volume-size SIZE", Integer, "EBS volume size in GB. Defaults to #{EC2Launcher::DEFAULT_VOLUME_SIZE} GB") do |volume_size|
101
+ opts.on("--volume-size SIZE", Integer, "EBS volume size in GB. Defaults to #{EC2Launcher::DEFAULT_VOLUME_SIZE} GB") do |volume_size|
102
102
  @options.volume_size = volume_size
103
103
  end
104
104
 
@@ -116,6 +116,14 @@ module EC2Launcher
116
116
  opts.separator ""
117
117
  opts.separator "Common options:"
118
118
 
119
+ opts.on_tail("-q", "--quiet", "Display as little information as possible.") do
120
+ @options.verbosity = :quiet
121
+ end
122
+
123
+ opts.on_tail("-v", "--verbose", "Display as much information as possible.") do
124
+ @options.verbosity = :verbose
125
+ end
126
+
119
127
  # No argument, shows at tail. This will print an options summary.
120
128
  # Try it and see!
121
129
  opts.on_tail("-?", "--help", "Show this message") do
@@ -152,6 +160,8 @@ module EC2Launcher
152
160
  @options.instance_type = nil
153
161
  @options.volume_size = nil
154
162
 
163
+ @options.verbosity = :normal
164
+
155
165
  @options.directory = "./"
156
166
 
157
167
  if @command == "init"
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2012 Sean Laurent
3
3
  #
4
4
  module EC2Launcher
5
- VERSION = "1.0.22"
5
+ VERSION = "1.0.23"
6
6
  end
data/lib/ec2launcher.rb CHANGED
@@ -5,6 +5,7 @@ require 'rubygems'
5
5
  require 'optparse'
6
6
  require 'ostruct'
7
7
  require 'aws-sdk'
8
+ require 'log4r'
8
9
 
9
10
  require 'ec2launcher/version'
10
11
  require 'ec2launcher/defaults'
@@ -18,6 +19,8 @@ require 'ec2launcher/instance_paths_config'
18
19
  require 'ec2launcher/block_device_builder'
19
20
  require 'ec2launcher/hostname_generator'
20
21
 
22
+ include Log4r
23
+
21
24
  module EC2Launcher
22
25
 
23
26
  class AmiDetails
@@ -35,10 +38,21 @@ module EC2Launcher
35
38
  def initialize()
36
39
  @run_url_script_cache = nil
37
40
  @setup_script_cache = nil
41
+
42
+ @log = Logger.new 'mylog'
43
+ log_output = Outputter.stdout
44
+ log_output.formatter = PatternFormatter.new :pattern => "%m"
45
+ @log.outputters = log_output
38
46
  end
39
47
 
40
48
  def launch(options)
41
49
  @options = options
50
+
51
+ @log.level = case @options.verbosity
52
+ when :quiet then WARN
53
+ when :verbose then DEBUG
54
+ else INFO
55
+ end
42
56
 
43
57
  # Load configuration data
44
58
  @config = load_config_file
@@ -104,7 +118,7 @@ module EC2Launcher
104
118
  # ENVIRONMENT
105
119
  ##############################
106
120
  unless @environments.has_key? options.environ
107
- puts "Environment not found: #{options.environ}"
121
+ @log.fatal "Environment not found: #{options.environ}"
108
122
  exit 2
109
123
  end
110
124
  @environment = @environments[options.environ]
@@ -113,7 +127,7 @@ module EC2Launcher
113
127
  # APPLICATION
114
128
  ##############################
115
129
  unless @applications.has_key? options.application
116
- puts "Application not found: #{options.application}"
130
+ @log.fatal "Application not found: #{options.application}"
117
131
  exit 3
118
132
  end
119
133
  @application = @applications[options.application]
@@ -157,7 +171,7 @@ module EC2Launcher
157
171
  ##############################
158
172
  key_name = @environment.key_name
159
173
  if key_name.nil?
160
- puts "Unable to determine SSH key name."
174
+ @log.fatal "Unable to determine SSH key name."
161
175
  exit 4
162
176
  end
163
177
 
@@ -190,7 +204,7 @@ module EC2Launcher
190
204
  end
191
205
 
192
206
  if missing_security_groups.length > 0
193
- puts "ERROR: Missing security groups: #{missing_security_groups.join(', ')}"
207
+ @log.fatal "ERROR: Missing security groups: #{missing_security_groups.join(', ')}"
194
208
  exit 3
195
209
  end
196
210
 
@@ -301,34 +315,37 @@ module EC2Launcher
301
315
  aws_keyfile = @environment.aws_keyfile
302
316
 
303
317
  ##############################
304
- puts
305
- puts "Availability zone: #{availability_zone}"
306
- puts "Key name : #{key_name}"
307
- puts "Security groups : " + security_groups.collect {|name| "#{name} (#{sg_map[name].security_group_id})"}.join(", ")
308
- puts "Instance type : #{instance_type}"
309
- puts "Architecture : #{instance_architecture}"
310
- puts "AMI name : #{ami.ami_name}"
311
- puts "AMI id : #{ami.ami_id}"
312
- puts "ELB : #{elb_name}" if elb_name
313
- puts "Chef PEM : #{chef_validation_pem_url}"
314
- puts "AWS key file : #{aws_keyfile}"
315
- puts "Roles : #{roles.join(', ')}"
316
- puts "Gems : #{gems.join(', ')}"
317
- puts "Packages : #{packages.join(', ')}"
318
- puts "VPC Subnet : #{subnet}" if subnet
319
- puts ""
318
+ @log.info
319
+ @log.info "Availability zone: #{availability_zone}"
320
+ @log.info "Key name : #{key_name}"
321
+ @log.info "Security groups : " + security_groups.collect {|name| "#{name} (#{sg_map[name].security_group_id})"}.join(", ")
322
+ @log.info "Instance type : #{instance_type}"
323
+ @log.info "Architecture : #{instance_architecture}"
324
+ @log.info "AMI name : #{ami.ami_name}"
325
+ @log.info "AMI id : #{ami.ami_id}"
326
+ @log.info "ELB : #{elb_name}" if elb_name
327
+ @log.info "Chef PEM : #{chef_validation_pem_url}"
328
+ @log.info "AWS key file : #{aws_keyfile}"
329
+ @log.info "Roles : #{roles.join(', ')}"
330
+ @log.info "Gems : #{gems.join(', ')}"
331
+ @log.info "Packages : #{packages.join(', ')}"
332
+ if subnet
333
+ cidr_block = ec2.subnets[subnet].cidr_block
334
+ @log.info "VPC Subnet : #{subnet} (#{cidr_block})"
335
+ end
336
+ @log.info ""
320
337
  fqdn_names.each do |fqdn|
321
- puts "Name : #{fqdn}"
338
+ @log.info "Name : #{fqdn}"
322
339
  end
323
340
 
324
341
  unless block_device_mappings.empty?
325
- puts ""
326
- puts "Block devices :"
342
+ @log.info ""
343
+ @log.info "Block devices :"
327
344
  block_device_mappings.keys.sort.each do |key|
328
345
  if block_device_mappings[key] =~ /^ephemeral/
329
- puts " Block device : #{key}, #{block_device_mappings[key]}"
346
+ @log.info " Block device : #{key}, #{block_device_mappings[key]}"
330
347
  else
331
- puts " Block device : #{key}, #{block_device_mappings[key][:volume_size]}GB, " +
348
+ @log.info " Block device : #{key}, #{block_device_mappings[key][:volume_size]}GB, " +
332
349
  "#{block_device_mappings[key][:snapshot_id]}, " +
333
350
  "(#{block_device_mappings[key][:delete_on_termination] ? 'auto-delete' : 'no delete'})"
334
351
  end
@@ -336,7 +353,7 @@ module EC2Launcher
336
353
  end
337
354
 
338
355
  if chef_validation_pem_url.nil?
339
- puts "***ERROR*** Missing the URL For the Chef Validation PEM file."
356
+ @log.fatal "***ERROR*** Missing the URL For the Chef Validation PEM file."
340
357
  exit 3
341
358
  end
342
359
 
@@ -344,10 +361,10 @@ module EC2Launcher
344
361
  if @options.show_defaults || @options.show_user_data
345
362
  if @options.show_user_data
346
363
  user_data = build_launch_command(fqdn_names[0], short_hostnames[0], roles, chef_validation_pem_url, aws_keyfile, gems, packages, email_notifications)
347
- puts ""
348
- puts "---user-data---"
349
- puts user_data
350
- puts "---user-data---"
364
+ @log.info ""
365
+ @log.info "---user-data---"
366
+ @log.info user_data
367
+ @log.info "---user-data---"
351
368
  end
352
369
  exit 0
353
370
  end
@@ -355,7 +372,7 @@ module EC2Launcher
355
372
  ##############################
356
373
  # Launch the new intance
357
374
  ##############################
358
- puts ""
375
+ @log.warn ""
359
376
  instances = []
360
377
  fqdn_names.each_index do |i|
361
378
  block_device_tags = block_device_builder.generate_device_tags(fqdn_names[i], short_hostnames[i], @environment.name, @application.block_devices)
@@ -366,14 +383,14 @@ module EC2Launcher
366
383
 
367
384
  public_dns_name = instance.public_dns_name.nil? ? "no public dns" : instance.public_dns_name
368
385
  private_dns_name = instance.private_dns_name.nil? ? "no private dns" : instance.private_dns_name
369
- puts "Launched #{fqdn_names[i]} (#{instance.id}) [#{public_dns_name} / #{private_dns_name} / #{instance.private_ip_address} ]"
386
+ @log.warn "Launched #{fqdn_names[i]} (#{instance.id}) [#{public_dns_name} / #{private_dns_name} / #{instance.private_ip_address} ]"
370
387
  end
371
388
 
372
- puts "********************"
389
+ @log.warn "********************"
373
390
  fqdn_names.each_index do |i|
374
391
  public_dns_name = instances[i].public_dns_name.nil? ? "n/a" : instances[i].public_dns_name
375
392
  private_dns_name = instances[i].private_dns_name.nil? ? "n/a" : instances[i].private_dns_name
376
- puts "** New instance: #{fqdn_names[i]} | #{instances[i].id} | #{public_dns_name} | #{private_dns_name} | #{instances[i].private_ip_address}"
393
+ @log.warn "** New instance: #{fqdn_names[i]} | #{instances[i].id} | #{public_dns_name} | #{private_dns_name} | #{instances[i].private_ip_address}"
377
394
  end
378
395
 
379
396
  ##############################
@@ -386,7 +403,7 @@ module EC2Launcher
386
403
  ##############################
387
404
  # COMPLETED
388
405
  ##############################
389
- puts "********************"
406
+ @log.warn "********************"
390
407
  end
391
408
 
392
409
  # Attaches an instance to the specified ELB.
@@ -396,8 +413,8 @@ module EC2Launcher
396
413
  #
397
414
  def attach_to_elb(instance, elb_name)
398
415
  begin
399
- puts ""
400
- puts "Adding to ELB: #{elb_name}"
416
+ @log.info ""
417
+ @log.info "Adding to ELB: #{elb_name}"
401
418
  elb = AWS::ELB.new
402
419
  AWS.memoize do
403
420
  # Build list of availability zones for any existing instances
@@ -426,7 +443,7 @@ module EC2Launcher
426
443
  elb.load_balancers[elb_name].instances.register(instance)
427
444
  end
428
445
  rescue StandardError => bang
429
- puts "Error adding to load balancers: " + bang.to_s
446
+ @log.error "Error adding to load balancers: " + bang.to_s
430
447
  end
431
448
  end
432
449
 
@@ -469,7 +486,7 @@ module EC2Launcher
469
486
  #
470
487
  # @return [AmiDetails] AMI name and id.
471
488
  def find_ami(arch, virtualization, ami_name_match, id = nil)
472
- puts "Searching for AMI..."
489
+ @log.info "Searching for AMI..."
473
490
  ami_name = ""
474
491
  ami_id = ""
475
492
 
@@ -526,7 +543,7 @@ module EC2Launcher
526
543
  abort("You MUST either set the AWS_ACCESS_KEY and AWS_SECRET_ACCESS_KEY environment variables or use the command line options.")
527
544
  end
528
545
 
529
- puts "Initializing AWS connection..."
546
+ @log.info "Initializing AWS connection..."
530
547
  AWS.config({
531
548
  :access_key_id => aws_access_key,
532
549
  :secret_access_key => aws_secret_access_key
@@ -548,7 +565,7 @@ module EC2Launcher
548
565
  #
549
566
  # @return [AWS::EC2::Instance] newly created EC2 instance or nil if the launch failed.
550
567
  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)
551
- puts "Launching instance... #{hostname}"
568
+ @log.warn "Launching instance... #{hostname}"
552
569
  new_instance = nil
553
570
  run_with_backoff(30, 1, "launching instance") do
554
571
  if block_device_mappings.nil? || block_device_mappings.keys.empty?
@@ -576,7 +593,7 @@ module EC2Launcher
576
593
  end
577
594
  sleep 5
578
595
 
579
- puts " Waiting for instance to start up..."
596
+ @log.info " Waiting for instance to start up..."
580
597
  sleep 2
581
598
  instance_ready = false
582
599
  until instance_ready
@@ -588,13 +605,13 @@ module EC2Launcher
588
605
  end
589
606
 
590
607
  unless new_instance.status == :running
591
- puts "Instance launch failed. Aborting."
608
+ @log.fatal "Instance launch failed. Aborting."
592
609
  exit 5
593
610
  end
594
611
 
595
612
  ##############################
596
613
  # Tag instance
597
- puts "Tagging instance..."
614
+ @log.info "Tagging instance..."
598
615
  run_with_backoff(30, 1, "tag #{new_instance.id}, tag: name, value: #{hostname}") { new_instance.add_tag("Name", :value => hostname) }
599
616
  run_with_backoff(30, 1, "tag #{new_instance.id}, tag: environment, value: #{@environment.name}") { new_instance.add_tag("environment", :value => @environment.name) }
600
617
  run_with_backoff(30, 1, "tag #{new_instance.id}, tag: application, value: #{@application.name}") { new_instance.add_tag("application", :value => @application.name) }
@@ -602,7 +619,7 @@ module EC2Launcher
602
619
  ##############################
603
620
  # Tag volumes
604
621
  unless block_device_tags.empty?
605
- puts "Tagging volumes..."
622
+ @log.info "Tagging volumes..."
606
623
  AWS.start_memoizing
607
624
  block_device_tags.keys.each do |device|
608
625
  v = new_instance.block_device_mappings[device].volume
@@ -672,7 +689,7 @@ module EC2Launcher
672
689
  if fail_on_error
673
690
  abort("ERROR - #{name} directories not found: #{temp_dirs}")
674
691
  else
675
- puts "WARNING - #{name} directories not found: #{temp_dirs}"
692
+ @log.warn "WARNING - #{name} directories not found: #{temp_dirs}"
676
693
  end
677
694
  end
678
695
 
@@ -361,9 +361,9 @@ end
361
361
  ##############################
362
362
  # EMAIL NOTIFICATION
363
363
  ##############################
364
-
365
- unless instance_data["email_notification"].nil?
364
+ if instance_data["email_notification"]
366
365
  # Email notification through SES
366
+ puts "Email notification through SES..."
367
367
  AWS.config({
368
368
  :access_key_id => instance_data["email_notification"]["ses_access_key"],
369
369
  :secret_access_key => instance_data["email_notification"]["ses_secret_key"]
@@ -376,4 +376,6 @@ unless instance_data["email_notification"].nil?
376
376
  :body_text => "Server setup is complete for Host: #{hostname}, Environment: #{options.environ}, Application: #{options.application}",
377
377
  :body_html => "<div>Server setup is complete for:</div><div><strong>Host:</strong> #{hostname}</div><div><strong>Environment:</strong> #{options.environ}</div><div><strong>Application:</strong> #{options.application}</div>"
378
378
  )
379
+ else
380
+ puts "Skipping email notification."
379
381
  end
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.22
4
+ version: 1.0.23
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-08 00:00:00.000000000 Z
12
+ date: 2012-08-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: 1.5.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: log4r
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  description: Tool to manage application configurations and launch new EC2 instances
31
47
  based on the configurations.
32
48
  email:
@@ -84,3 +100,4 @@ signing_key:
84
100
  specification_version: 3
85
101
  summary: Tool to launch EC2 instances.
86
102
  test_files: []
103
+ has_rdoc: