ec2launcher 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -105,6 +105,14 @@ module EC2Launcher
105
105
  end
106
106
  end
107
107
 
108
+ def inherit(*inherit_type)
109
+ if inherit_type.empty?
110
+ @inherit_type
111
+ else
112
+ @inherit_type = inherit_type[0]
113
+ end
114
+ end
115
+
108
116
  def key_name(*key)
109
117
  if key.empty?
110
118
  @key_name
@@ -178,6 +186,28 @@ module EC2Launcher
178
186
  end
179
187
  end
180
188
 
189
+ # Takes values from the other environment and merges them into this one
190
+ def merge(other_env)
191
+ @name =other_env.name
192
+
193
+ @aliases = other_env.aliases.nil? ? nil : other_env.aliases
194
+
195
+ @aws_keyfile = other_env.aws_keyfile unless other_env.aws_keyfile.nil?
196
+ @availability_zone = other_env.availability_zone unless other_env.availability_zone.nil?
197
+ @chef_server_url = other_env.chef_server_url unless other_env.chef_server_url.nil?
198
+ @chef_validation_pem_url = other_env.chef_validation_pem_url unless other_env.chef_validation_pem_url.nil?
199
+ @domain_name = other_env.domain_name unless other_env.domain_name
200
+ @email_notifications = other_env.email_notifications unless other_env.email_notifications.nil?
201
+ @gems = other_env.gems unless other_env.gems.nil?
202
+ @key_name = other_env.key_name unless other_env.key_name.nil?
203
+ @packages = other_env.packages unless other_env.packages.nil?
204
+ @precommands = other_env.precommands unless other_env.precommands.nil?
205
+ @postcommands = other_env.postcommands unless other_env.postcommands.nil?
206
+ @roles = other_env.roles unless other_env.roles.nil?
207
+ @security_groups = other_env.security_groups unless other_env.security_groups.nil?
208
+ @subnet = other_env.subnet unless other_env.subnet.nil?
209
+ end
210
+
181
211
  def load(dsl)
182
212
  self.instance_eval(dsl)
183
213
  self
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2012 Sean Laurent
3
3
  #
4
4
  module Ec2launcher
5
- VERSION = "1.0.2"
5
+ VERSION = "1.0.3"
6
6
  end
data/lib/ec2launcher.rb CHANGED
@@ -100,17 +100,19 @@ module EC2Launcher
100
100
  end
101
101
  end
102
102
 
103
+ # Process inheritance rules for environments
104
+ @environments.values.each do |env|
105
+ next if env.inherit.nil?
106
+
107
+ new_env = process_environment_inheritance(env)
108
+ @environments[new_env.name] = new_env
109
+ end
110
+
103
111
  # Process inheritance rules for applications
104
112
  @applications.values.each do |app|
105
113
  next if app.inherit.nil?
106
114
 
107
- # Find base application
108
- base_app = @applications[app.inherit]
109
- abort("Invalid inheritance '#{app.inherit}' in #{app.name}") if base_app.nil?
110
-
111
- # Clone base application
112
- new_app = Marshal::load(Marshal.dump(base_app))
113
- new_app.merge(app)
115
+ new_app = process_application_inheritance(app)
114
116
  @applications[new_app.name] = new_app
115
117
  end
116
118
 
@@ -306,7 +308,7 @@ export HOME=/root
306
308
  echo '#{setup_json.to_json}' > /tmp/setup.json"
307
309
 
308
310
  # pre-commands, if necessary
309
- unless @environment.precommands.nil?
311
+ unless @environment.precommands.nil? || @environment.precommands.empty?
310
312
  precommands = @environment.precommands.join("\n")
311
313
  user_data += "\n" + precommands
312
314
  end
@@ -322,7 +324,7 @@ rm -f /tmp/runurl"
322
324
  options.commands.each {|extra_cmd| user_data += "\n#{extra_cmd}" }
323
325
 
324
326
  # Post commands
325
- unless @environment.postcommands.nil?
327
+ unless @environment.postcommands.nil? || @environment.postcommands.empty?
326
328
  postcommands = @environment.postcommands.join("\n")
327
329
  user_data += "\n" + postcommands
328
330
  end
@@ -682,7 +684,7 @@ rm -f /tmp/runurl"
682
684
  return nil
683
685
  end
684
686
 
685
- new_env = default_environment.clone unless default_environment.nil?
687
+ new_env = Marshal::load(Marshal.dump(default_environment)) unless default_environment.nil?
686
688
  new_env ||= EC2Launcher::Environment.new
687
689
 
688
690
  new_env.load(File.read(name))
@@ -719,6 +721,42 @@ rm -f /tmp/runurl"
719
721
  valid_directories
720
722
  end
721
723
 
724
+ def process_application_inheritance(app)
725
+ return app if app.inherit.nil?
726
+
727
+ # Find base application
728
+ base_app = @applications[app.inherit]
729
+ abort("Invalid inheritance '#{app.inherit}' in #{app.name}") if base_app.nil?
730
+
731
+ new_app = nil
732
+ if base_app.inherit.nil?
733
+ # Clone base application
734
+ new_app = Marshal::load(Marshal.dump(base_app))
735
+ else
736
+ new_app = process_application_inheritance(base_app)
737
+ end
738
+ new_app.merge(app)
739
+ new_app
740
+ end
741
+
742
+ def process_environment_inheritance(env)
743
+ return env if env.inherit.nil?
744
+
745
+ # Find base environment
746
+ base_env = @environments[env.inherit]
747
+ abort("Invalid inheritance '#{env.inherit}' in #{env.name}") if base_env.nil?
748
+
749
+ new_env = nil
750
+ if base_env.inherit.nil?
751
+ # Clone base environment
752
+ new_env = Marshal::load(Marshal.dump(base_env))
753
+ else
754
+ new_env = process_environment_inheritance(base_env)
755
+ end
756
+ new_env.merge(env)
757
+ new_env
758
+ end
759
+
722
760
  # Validates all settings in an application file
723
761
  #
724
762
  # @param [String] filename name of the application file
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.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: