ec2launcher 1.0.27 → 1.0.28

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,7 @@
1
+ ## 1.0.28
2
+
3
+ * Fixed problem with pre/post command inheritance.
4
+
1
5
  ## 1.0.27
2
6
 
3
7
  * Fixed DSL accessor method access.
@@ -38,6 +38,7 @@ module EC2Launcher
38
38
 
39
39
  attr_reader :name
40
40
 
41
+ dsl_accessor :availability_zone
41
42
  dsl_accessor :basename
42
43
  dsl_accessor :inherit
43
44
  dsl_accessor :instance_type
@@ -48,6 +49,12 @@ module EC2Launcher
48
49
  dsl_array_accessor :packages
49
50
  dsl_array_accessor :roles
50
51
 
52
+ # Name of the AMI to use for new instances. Optional.
53
+ # Can be either a string or a regular expression.
54
+ #
55
+ # @param [Array, nil] Either an array of parameters or nil to return the AMI name.
56
+ dsl_regex_accessor :ami_name
57
+
51
58
  def initialize(name)
52
59
  @name = name
53
60
  @email_notifications = nil
@@ -59,34 +66,6 @@ module EC2Launcher
59
66
  self
60
67
  end
61
68
 
62
- # Name of the AMI to use for new instances. Optional.
63
- # Can be either a string or a regular expression.
64
- #
65
- # @param [Array, nil] Either an array of parameters or nil to return the AMI name.
66
- def ami_name(*ami_name)
67
- if ami_name.empty?
68
- @ami_name
69
- else
70
- if ami_name[0].kind_of? String
71
- @ami_name = /#{ami_name[0]}/
72
- else
73
- @ami_name = ami_name[0]
74
- end
75
- self
76
- end
77
- end
78
-
79
- # Name of the availability zone to use for new instances. Optional.
80
- # Must be one of EC2Launcher::AVAILABILITY_ZONES.
81
- def availability_zone(*zone)
82
- if zone.empty?
83
- @availability_zone
84
- else
85
- @availability_zone = zone[0].to_s
86
- self
87
- end
88
- end
89
-
90
69
  def block_devices(*block_device_data)
91
70
  if block_device_data.empty?
92
71
  @block_devices
@@ -156,26 +135,6 @@ module EC2Launcher
156
135
  end
157
136
  end
158
137
 
159
- # Gems to install. Optional.
160
- #
161
- # Expects either a single String naming a gem to install or
162
- # an Array of gems.
163
- #
164
- # Can be specified multiple times.
165
- def gems(*gems)
166
- if gems.empty?
167
- @gems
168
- else
169
- @gems = [] if @gems.nil?
170
- if gems[0].kind_of? Array
171
- @gems += gems[0]
172
- else
173
- @gems << gems[0]
174
- end
175
- self
176
- end
177
- end
178
-
179
138
  # Takes values from the other server type and merges them into this one
180
139
  def merge(other_server)
181
140
  @name = other_server.name
@@ -1,6 +1,8 @@
1
1
  #
2
2
  # Copyright (c) 2012 Sean Laurent
3
3
  #
4
+ require 'ec2launcher/dsl/helper'
5
+
4
6
  module EC2Launcher
5
7
  module DSL
6
8
  class ConfigDSL
@@ -31,53 +33,17 @@ config do
31
33
  config_manager "chef"
32
34
  end
33
35
  }.gsub(/^ /, '')
36
+
37
+ dsl_accessor :package_manager
38
+ dsl_accessor :config_manager
39
+
40
+ dsl_array_accessor :applications
41
+ dsl_array_accessor :environments
34
42
 
35
43
  def initialize()
36
44
  @environments = []
37
45
  @applications = []
38
46
  end
39
-
40
- def environments(*environments)
41
- if environments.empty?
42
- @environments
43
- else
44
- if environments[0].kind_of? Array
45
- @environments = @environments[0]
46
- else
47
- @environments = [ environments[0] ]
48
- end
49
- self
50
- end
51
- end
52
-
53
- def applications(*applications)
54
- if applications.empty?
55
- @applications
56
- else
57
- if applications[0].kind_of? Array
58
- @applications = @applications[0]
59
- else
60
- @applications = [ applications[0] ]
61
- end
62
- self
63
- end
64
- end
65
-
66
- def package_manager(*package_manager)
67
- if package_manager.empty?
68
- @package_manager
69
- else
70
- @package_manager = package_manager[0]
71
- end
72
- end
73
-
74
- def config_manager(*config_manager)
75
- if config_manager.empty?
76
- @config_manager
77
- else
78
- @config_manager = config_manager[0]
79
- end
80
- end
81
47
  end
82
48
  end
83
49
  end
@@ -15,6 +15,7 @@ module EC2Launcher
15
15
  attr_reader :precommands
16
16
  attr_reader :postcommands
17
17
 
18
+ dsl_accessor :availability_zone
18
19
  dsl_accessor :aws_keyfile
19
20
  dsl_accessor :chef_path
20
21
  dsl_accessor :chef_server_url
@@ -28,19 +29,26 @@ module EC2Launcher
28
29
  dsl_accessor :short_name
29
30
  dsl_accessor :subnet
30
31
 
32
+ dsl_array_accessor :aliases
31
33
  dsl_array_accessor :gems
32
34
  dsl_array_accessor :packages
33
35
  dsl_array_accessor :precommand
34
36
  dsl_array_accessor :postcommand
35
37
  dsl_array_accessor :roles
36
38
 
39
+ # Name of the AMI to use for new instances. Optional.
40
+ # Can be either a string or a regular expression.
41
+ #
42
+ # @param [Array, nil] Either an array of parameters or nil to return the AMI name.
43
+ dsl_regex_accessor :ami_name
44
+
37
45
  def initialize()
38
46
  @aliases = []
39
47
  @email_notifications = nil
40
48
  @gems = []
41
49
  @packages = []
42
- @precommands = []
43
- @postcommands = []
50
+ @precommand = []
51
+ @postcommand = []
44
52
  @roles = []
45
53
  @security_groups = {}
46
54
  end
@@ -51,40 +59,6 @@ module EC2Launcher
51
59
  self
52
60
  end
53
61
 
54
- def aliases(*aliases)
55
- if aliases.empty?
56
- @aliases
57
- else
58
- if aliases[0].kind_of? String
59
- @aliases = [ aliases[0] ]
60
- else
61
- @aliases = aliases[0]
62
- end
63
- end
64
- end
65
-
66
- def ami_name(*ami_name)
67
- if ami_name.empty?
68
- @ami_name
69
- else
70
- if ami_name[0].kind_of? String
71
- @ami_name = /#{ami_name[0]}/
72
- else
73
- @ami_name = ami_name[0]
74
- end
75
- self
76
- end
77
- end
78
-
79
- def availability_zone(*zone)
80
- if zone.empty?
81
- @availability_zone
82
- else
83
- @availability_zone = zone[0].to_s
84
- self
85
- end
86
- end
87
-
88
62
  # Takes values from the other environment and merges them into this one
89
63
  def merge(other_env)
90
64
  @name =other_env.name
@@ -92,8 +66,8 @@ module EC2Launcher
92
66
  @gems += other_env.gems unless other_env.gems.nil?
93
67
  @packages += other_env.packages unless other_env.packages.nil?
94
68
  @roles += other_env.roles unless other_env.roles.nil?
95
- @precommands += other_env.precommands unless other_env.precommands.nil?
96
- @postcommands += other_env.postcommands unless other_env.postcommands.nil?
69
+ @precommand += other_env.precommand unless other_env.precommand.nil?
70
+ @postcommand += other_env.postcommand unless other_env.postcommand.nil?
97
71
  unless other_env.security_groups.nil?
98
72
  other_env.security_groups.keys.each do |key|
99
73
  @security_groups[key] = [] if @security_groups[key].nil?
@@ -36,4 +36,23 @@ class Module
36
36
  }
37
37
  }
38
38
  end
39
+
40
+ def dsl_regex_accessor(*symbols)
41
+ symbols.each { |sym|
42
+ class_eval %{
43
+ def #{sym}(*val)
44
+ if val.empty?
45
+ @#{sym}
46
+ else
47
+ if val[0].kind_of? String
48
+ @#{sym} = Regexp.new(val[0])
49
+ else
50
+ @#{sym} = val[0]
51
+ end
52
+ self
53
+ end
54
+ end
55
+ }
56
+ }
57
+ end
39
58
  end
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2012 Sean Laurent
3
3
  #
4
4
  module EC2Launcher
5
- VERSION = "1.0.27"
5
+ VERSION = "1.0.28"
6
6
  end
data/lib/ec2launcher.rb CHANGED
@@ -381,15 +381,15 @@ module EC2Launcher
381
381
  instance = launch_instance(fqdn_names[i], ami.ami_id, availability_zone, key_name, security_group_ids, instance_type, user_data, block_device_mappings, block_device_tags, subnet)
382
382
  instances << instance
383
383
 
384
- public_dns_name = instance.public_dns_name.nil? ? "no public dns" : instance.public_dns_name
385
- private_dns_name = instance.private_dns_name.nil? ? "no private dns" : instance.private_dns_name
384
+ public_dns_name = get_instance_dns(instance, true)
385
+ private_dns_name = get_instance_dns(instance, false)
386
386
  @log.info "Launched #{fqdn_names[i]} (#{instance.id}) [#{public_dns_name} / #{private_dns_name} / #{instance.private_ip_address} ]"
387
387
  end
388
388
 
389
389
  @log.info "********************"
390
390
  fqdn_names.each_index do |i|
391
- public_dns_name = instances[i].public_dns_name.nil? ? "n/a" : instances[i].public_dns_name
392
- private_dns_name = instances[i].private_dns_name.nil? ? "n/a" : instances[i].private_dns_name
391
+ public_dns_name = get_instance_dns(instances[i], true)
392
+ private_dns_name = get_instance_dns(instances[i], false)
393
393
  @log.warn "** New instance: #{fqdn_names[i]} | #{instances[i].id} | #{public_dns_name} | #{private_dns_name} | #{instances[i].private_ip_address}"
394
394
  end
395
395
 
@@ -464,19 +464,6 @@ module EC2Launcher
464
464
  dirs
465
465
  end
466
466
 
467
- # Builds the path to an executable.
468
- def build_path(instance_path, executable, default_path)
469
- app_path = default_path
470
- unless instance_path.nil?
471
- if instance_path =~ /#{executable}$/
472
- app_path = instance_path
473
- else
474
- app_path = File.join(instance_path, executable)
475
- end
476
- end
477
- app_path
478
- end
479
-
480
467
  # Searches for the most recent AMI matching the criteria.
481
468
  #
482
469
  # @param [String] arch system archicture, `i386` or `x86_64`
@@ -530,6 +517,19 @@ module EC2Launcher
530
517
  AmiDetails.new(ami_name, ami_id)
531
518
  end
532
519
 
520
+ # Retrieves either the public or private DNS entry for an EC2 Instance. Returns "n/a" if the
521
+ # request DNS entry is undefined.
522
+ #
523
+ # @param [AWS::EC2::Instance] ec2 instance
524
+ # @param [Boolean] True for public DNS or False for private DNS
525
+ #
526
+ # @return [String] DNS for the instance or "n/a" if undefined.
527
+ #
528
+ def get_instance_dns(ec2_instance, public = true)
529
+ dns_name = public ? instance.public_dns_name : instance.private_dns_name
530
+ dns_name.nil? ? "n/a" : dns_name
531
+ end
532
+
533
533
  # Initializes connections to the AWS SDK
534
534
  #
535
535
  def initialize_aws()
@@ -827,8 +827,9 @@ module EC2Launcher
827
827
  user_data += "\necho '#{setup_json.to_json}' > /tmp/setup.json"
828
828
 
829
829
  # pre-commands, if necessary
830
- unless @environment.precommands.nil? || @environment.precommands.empty?
831
- commands = @environment.precommands.collect {|cmd| substitute_command_variables(cmd) }
830
+ puts "Precommands: #{@environment.precommands}"
831
+ unless @environment.precommand.nil? || @environment.precommand.empty?
832
+ commands = @environment.precommand.collect {|cmd| substitute_command_variables(cmd) }
832
833
  user_data += "\n" + commands.join("\n")
833
834
  end
834
835
 
@@ -875,8 +876,8 @@ module EC2Launcher
875
876
  end
876
877
 
877
878
  # Post commands
878
- unless @environment.postcommands.nil? || @environment.postcommands.empty?
879
- commands = @environment.postcommands.collect {|cmd| substitute_command_variables(cmd) }
879
+ unless @environment.postcommand.nil? || @environment.postcommand.empty?
880
+ commands = @environment.postcommand.collect {|cmd| substitute_command_variables(cmd) }
880
881
  user_data += "\n" + commands.join("\n")
881
882
  end
882
883
  user_data
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.27
4
+ version: 1.0.28
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: