Class: EC2Launcher::DSL::Application

Inherits:
Object
  • Object
show all
Includes:
EmailNotifications, SecurityGroupHandler
Defined in:
lib/ec2launcher/dsl/application.rb

Overview

Represents a single application stack.

Instance Attribute Summary collapse

Attributes included from EmailNotifications

#email_notifications

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SecurityGroupHandler

#security_groups

Methods included from EmailNotifications

#email_notification

Constructor Details

#initialize(name) ⇒ Application

Returns a new instance of Application.



61
62
63
64
65
66
# File 'lib/ec2launcher/dsl/application.rb', line 61

def initialize(name)
	@name = name
	@email_notifications = nil

	@use_rvm = true
end

Instance Attribute Details

#nameObject (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



209
210
211
212
# File 'lib/ec2launcher/dsl/application.rb', line 209

def self.load(dsl)
	env = Application.new.instance_eval(dsl)
	env
end

Instance Method Details

#application(name) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



68
69
70
71
72
# File 'lib/ec2launcher/dsl/application.rb', line 68

def application(name)
	@name = name
	yield self
	self
end

#block_device(&block) ⇒ Object



82
83
84
85
86
87
# File 'lib/ec2launcher/dsl/application.rb', line 82

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



74
75
76
77
78
79
80
# File 'lib/ec2launcher/dsl/application.rb', line 74

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.



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/ec2launcher/dsl/application.rb', line 94

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.



109
110
111
112
113
# File 'lib/ec2launcher/dsl/application.rb', line 109

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


121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/ec2launcher/dsl/application.rb', line 121

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

#load(dsl) ⇒ Object



204
205
206
207
# File 'lib/ec2launcher/dsl/application.rb', line 204

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



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/ec2launcher/dsl/application.rb', line 144

def merge(other_server)
	@name = other_server.name
	@ami_name = other_server.ami_name unless other_server.ami_name.nil?
	@availability_zone = other_server.availability_zone unless other_server.availability_zone.nil?
	@basename = other_server.basename unless other_server.basename.nil?
	
	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
	
	@instance_type = other_server.instance_type unless other_server.instance_type.nil?
	@name_suffix = other_server.name_suffix unless other_server.name_suffix.nil?
	
	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

	@use_rvm = other_server.use_rvm unless other_server.use_rvm.nil?
end

#roles_for_environment(environment) ⇒ Object



181
182
183
184
185
186
187
188
189
# File 'lib/ec2launcher/dsl/application.rb', line 181

def roles_for_environment(environment)
	roles = []
	roles += @roles unless @roles.nil?

	unless @environment_roles.nil? || @environment_roles[environment].nil?
		roles += @environment_roles[environment]
	end
	roles
end

#security_groups_for_environment(environment) ⇒ Array

Retrieves the list of Security Group names for the specified environment.

Returns:

  • (Array)

    Returns the list of security groups for the environment. Returns the security groups for the “defaukt” environment if the requested environment is undefined. Returns an empty Array if both the requested environment and “default” environment are undefined.



197
198
199
200
201
202
# File 'lib/ec2launcher/dsl/application.rb', line 197

def security_groups_for_environment(environment)
	groups = @security_groups[environment]
	groups ||= @security_groups[:default]
	groups ||= []
	groups
end