Class: Feefi::AWS::Beanstalk

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/feefi/aws/beanstalk.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#app_config, #preamble

Constructor Details

#initialize(aws, config) ⇒ Beanstalk

Returns a new instance of Beanstalk.



6
7
8
9
10
11
# File 'lib/feefi/aws/beanstalk.rb', line 6

def initialize(aws,config)
  @aws = aws
  @beanstalk_connection = aws.beanstalk_connection
  @ec2_connection = aws.ec2_connection
  @config = config
end

Instance Attribute Details

#awsObject

Returns the value of attribute aws.



5
6
7
# File 'lib/feefi/aws/beanstalk.rb', line 5

def aws
  @aws
end

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/feefi/aws/beanstalk.rb', line 5

def config
  @config
end

Instance Method Details

#delete_template(name) ⇒ Object



18
19
20
# File 'lib/feefi/aws/beanstalk.rb', line 18

def delete_template(name)
    @beanstalk_connection.templates.get( @config.name, name).destroy
end

#eb_environmentsObject

List it out all environments for an application



38
39
40
41
# File 'lib/feefi/aws/beanstalk.rb', line 38

def eb_environments
  @aws.beanstalk_connectoin
  binding.pry 
end

#list_templatesObject

Obtains a list of configuration templates for the current beanstalk app



14
15
16
# File 'lib/feefi/aws/beanstalk.rb', line 14

def list_templates
  @beanstalk_connection.templates.map(&:name)
end

#list_variables(eb_env_name) ⇒ Object

gets the current EB OS Environment variables for the deployed app on a current eb environment, overloaded term. eb environments are arbitrary and are loosely similar to a Rails env.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/feefi/aws/beanstalk.rb', line 25

def list_variables(eb_env_name)
  begin
    body = @aws.beanstalk_connection.describe_configuration_settings("ApplicationName" => @config.name, "EnvironmentName" => eb_env_name).body
    current_env_variables = body['DescribeConfigurationSettingsResult']['ConfigurationSettings'].first['OptionSettings'].select \
      {|ea| ea['Namespace'] == ENV_NAMESPACE}
  rescue Fog::AWS::ElasticBeanstalk::InvalidParameterError => e
    puts "An error occurred connecting to Beanstalk. Check your options!"
    puts e
    exit
  end
end

#servers(eb_env) ⇒ Object

Uses EC2 and the tags to get a list of EC2 instances associated with this app and Beanstalk environment Technically the eb_env is merely a filter and will match using Array#include? in the env_env varianble.



45
46
47
48
49
50
51
52
53
# File 'lib/feefi/aws/beanstalk.rb', line 45

def servers(eb_env)
  @aws.ec2_connection.servers.select do |server|
    if server.tags && server.tags["elasticbeanstalk:environment-name"]
      server.tags["elasticbeanstalk:environment-name"].include? eb_env
    else
      nil
    end
  end
end