Class: EC2Launcher::DSL::Application
- Inherits:
-
Object
- Object
- EC2Launcher::DSL::Application
- Includes:
- EmailNotifications, SecurityGroupHandler
- Defined in:
- lib/ec2launcher/dsl/application.rb
Overview
Represents a single application stack.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes included from EmailNotifications
Class Method Summary collapse
Instance Method Summary collapse
- #application(name) {|_self| ... } ⇒ Object
- #block_device(&block) ⇒ Object
- #block_devices(*block_device_data) ⇒ Object
-
#elb(*elb) ⇒ Object
Indicates the Amazon Elastic Load Balancer to which new instances should be attached after launch.
-
#elb_for_environment(environment) ⇒ Object
Retrieves the ELB name for a given environment.
-
#environment_roles(*data) ⇒ Object
Defines an Array of Chef roles that should be applied to new instances for a specific environment.
- #has_provisioned_iops? ⇒ Boolean
-
#iam_profile(*data) ⇒ Object
IAM profile role name to use for new instances.
-
#iam_profile_for_environment(environment) ⇒ Object
Retrieves the IAM profile for a given environment.
-
#initialize(name) ⇒ Application
constructor
A new instance of Application.
- #load(dsl) ⇒ Object
-
#merge(other_server) ⇒ Object
Takes values from the other server type and merges them into this one.
- #roles_for_environment(environment) ⇒ Object
-
#security_groups_for_environment(environment) ⇒ Array
Retrieves the list of Security Group names for the specified environment.
Methods included from SecurityGroupHandler
Methods included from EmailNotifications
Constructor Details
#initialize(name) ⇒ Application
Returns a new instance of Application.
61 62 63 64 65 66 67 |
# File 'lib/ec2launcher/dsl/application.rb', line 61 def initialize(name) @name = name @email_notifications = nil @iam_profile = Hash.new @use_rvm = true end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
39 40 41 |
# File 'lib/ec2launcher/dsl/application.rb', line 39 def name @name end |
Class Method Details
.load(dsl) ⇒ Object
268 269 270 271 |
# File 'lib/ec2launcher/dsl/application.rb', line 268 def self.load(dsl) env = Application.new.instance_eval(dsl) env end |
Instance Method Details
#application(name) {|_self| ... } ⇒ Object
69 70 71 72 73 |
# File 'lib/ec2launcher/dsl/application.rb', line 69 def application(name) @name = name yield self self end |
#block_device(&block) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/ec2launcher/dsl/application.rb', line 83 def block_device(&block) @block_devices = [] if @block_devices.nil? device = EC2Launcher::DSL::BlockDevice.new device.instance_exec(&block) @block_devices << device end |
#block_devices(*block_device_data) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/ec2launcher/dsl/application.rb', line 75 def block_devices(*block_device_data) if block_device_data.empty? @block_devices else self end end |
#elb(*elb) ⇒ Object
Indicates the Amazon Elastic Load Balancer to which new instances should be attached after launch. Optional.
The value can be either a String, indicating the name of the ELB, or a Hash that maps environment names to ELB names.
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ec2launcher/dsl/application.rb', line 95 def elb(*elb) if elb.empty? @elb else @elb = Hash.new if @elb.nil? if elb[0].kind_of? Hash elb[0].keys.each {|key| @elb[key] = elb[0][key]} else @elb["default"] = elb[0].to_s end self end end |
#elb_for_environment(environment) ⇒ Object
Retrieves the ELB name for a given environment.
110 111 112 113 114 |
# File 'lib/ec2launcher/dsl/application.rb', line 110 def elb_for_environment(environment) elb_name = @elb[environment] elb_name ||= @elb["default"] elb_name end |
#environment_roles(*data) ⇒ Object
Defines an Array of Chef roles that should be applied to new instances for a specific environment. Can be specified multiple times.
Expects two parameters:
* Name of an environment
* Either the name of a single Chef role or an Array of Chef roles
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/ec2launcher/dsl/application.rb', line 122 def environment_roles(*data) if data.empty? @environment_roles else @environment_roles = Hash.new if @environment_roles.nil? env_name = data[0] env_roles = data[1] environment_data = @environment_roles[env_name] environment_data ||= [] if env_roles.kind_of? Array environment_data += env_roles else environment_data << env_roles end @environment_roles[env_name] = environment_data self end end |
#has_provisioned_iops? ⇒ Boolean
144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/ec2launcher/dsl/application.rb', line 144 def has_provisioned_iops?() return false unless @block_devices provisioned_iops = false @block_devices.each do |bd| if bd.provisioned_iops? provisioned_iops = true break end end provisioned_iops end |
#iam_profile(*data) ⇒ Object
IAM profile role name to use for new instances.
Expects one param in the form of either:
* A string containing the name of the IAM profile
* A Hash mapping environment names (as strings) to IAM profile names (as strings)
162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/ec2launcher/dsl/application.rb', line 162 def iam_profile(*data) if data.empty? @iam_profile else if data[0].kind_of? Hash @iam_profile = data[0] else @iam_profile["default"] = data[0] end end end |
#iam_profile_for_environment(environment) ⇒ Object
Retrieves the IAM profile for a given environment. Or returns the default profile name.
176 177 178 179 180 |
# File 'lib/ec2launcher/dsl/application.rb', line 176 def iam_profile_for_environment(environment) iam_profile = @iam_profile[environment] iam_profile ||= @iam_profile["default"] iam_profile end |
#load(dsl) ⇒ Object
263 264 265 266 |
# File 'lib/ec2launcher/dsl/application.rb', line 263 def load(dsl) self.instance_eval(dsl) self end |
#merge(other_server) ⇒ Object
Takes values from the other server type and merges them into this one
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/ec2launcher/dsl/application.rb', line 183 def merge(other_server) @name = other_server.name @ami_name = other_server.ami_name if other_server.ami_name @availability_zone = other_server.availability_zone if other_server.availability_zone @basename = other_server.basename if other_server.basename unless other_server.block_devices.nil? @block_devices = [] if @block_devices.nil? other_server.block_devices.each {|bd| @block_devices << bd } end unless other_server.elb.nil? @elb = {} if @elb.nil? other_server.elb.keys.each {|env_name| @elb[env_name] = other_server.elb[env_name] } end @iam_profile = other_server.iam_profile if other_server.iam_profile @instance_type = other_server.instance_type if other_server.instance_type @name_suffix = other_server.name_suffix if other_server.name_suffix if other_server.iam_profile @iam_profile = {} if @iam_profile.nil? other_server.iam_profile.keys.each do |env_name| @iam_profile[env_name] = other_server.iam_profile[env_name] end end unless other_server.roles.nil? @roles = [] if @roles.nil? other_server.roles.each {|role| @roles << role } end unless other_server.security_groups.nil? @security_groups = {} if @security_groups.nil? other_server.security_groups.keys.each do |env_name| unless @security_groups.has_key? env_name @security_groups[env_name] = [] end other_server.security_groups[env_name].each {|sg| @security_groups[env_name] << sg } end end unless other_server.environment_roles.nil? @environment_roles = Hash.new if @environment_roles.nil? other_server.environment_roles.keys.each do |env_name| if @environment_roles.has_key?(env_name) @environment_roles[env_name] = other_server.environment_roles[env_name] + @environment_roles[env_name] else @environment_roles[env_name] = other_server.environment_roles[env_name] end end end @use_rvm = other_server.use_rvm if other_server.use_rvm end |
#roles_for_environment(environment) ⇒ Object
239 240 241 242 243 244 245 246 247 |
# File 'lib/ec2launcher/dsl/application.rb', line 239 def roles_for_environment(environment) roles = [] roles += @roles unless @roles.nil? if @environment_roles && @environment_roles[environment] roles += @environment_roles[environment] end roles end |
#security_groups_for_environment(environment) ⇒ Array
Retrieves the list of Security Group names for the specified environment.
255 256 257 258 259 260 261 |
# File 'lib/ec2launcher/dsl/application.rb', line 255 def security_groups_for_environment(environment) groups = @security_groups[environment] groups ||= @security_groups[:default] groups ||= @security_groups["default"] groups ||= [] groups end |