class EC2Launcher::DSL::Application

Represents a single application stack.

Attributes

name[R]

Public Class Methods

load(dsl) click to toggle source
# File lib/ec2launcher/dsl/application.rb, line 268
def self.load(dsl)
        env = Application.new.instance_eval(dsl)
        env
end
new(name) click to toggle source
# File lib/ec2launcher/dsl/application.rb, line 61
def initialize(name)
        @name = name
        
        @email_notifications = nil
        @iam_profile = Hash.new
        @use_rvm = true
end

Public Instance Methods

application(name) { |self| ... } click to toggle source
# File lib/ec2launcher/dsl/application.rb, line 69
def application(name)
        @name = name
        yield self
        self
end
block_device(&block) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

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.

# 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) click to toggle source

Retrieves the ELB name for a given environment.

# 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) click to toggle source

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
# 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?() click to toggle source
# 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) click to toggle source

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)
# 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) click to toggle source

Retrieves the IAM profile for a given environment. Or returns the default profile name.

# 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) click to toggle source
# File lib/ec2launcher/dsl/application.rb, line 263
def load(dsl)
        self.instance_eval(dsl)
        self
end
merge(other_server) click to toggle source

Takes values from the other server type and merges them into this one

# 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) click to toggle source
# 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) click to toggle source

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

@return [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.
# 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