module Cumulus::ELB

Public Class Methods

default_policies() click to toggle source

Public: Provide the default available policies

Returns a Hash of Aws::ElasticLoadBalancing::Types::PolicyDescription to a policy's name

# File lib/elb/ELB.rb, line 60
def default_policies
  @default_policies ||= Hash[init_default_policies.map { |policy| [policy.policy_name, policy] }]
end
elb_attributes(elb_name) click to toggle source

Public: Provide the attributes for an ELB by name, lazily loaded

Returns an array of Aws::ElasticLoadBalancing::Types::LoadBalancerAttributes

# File lib/elb/ELB.rb, line 52
def elb_attributes(elb_name)
  @elb_attributes ||= {}
  @elb_attributes[elb_name] ||= init_elb_attributes(elb_name)
end
elb_policies(elb_name) click to toggle source

Public: Provide the policies already created on a load balancer

Returns a Hash of Aws::ElasticLoadBalancing::Types::PolicyDescription to a policy's name

# File lib/elb/ELB.rb, line 67
def elb_policies(elb_name)
  @elb_policies ||= {}
  @elb_policies[elb_name] ||= Hash[init_elb_policies(elb_name).map { |policy| [policy.policy_name, policy] }]
end
elb_tags(elb_name) click to toggle source

Public: Provide the tags for an ELB by name

Returns an array of Aws::ElasticLoadBalancing::Types::Tag

# File lib/elb/ELB.rb, line 43
def elb_tags(elb_name)
  @elb_tags ||= init_elb_tags

  @elb_tags[elb_name]
end
elbs() click to toggle source

Public: Provide a mapping of ELBs to their names. Lazily loads resources.

Returns the ELBs mapped to their names

# File lib/elb/ELB.rb, line 36
def elbs
  @elbs ||= init_elbs
end
get_aws(name) click to toggle source

Public: Static method that will get an ELB from AWS by its name.

name - the name of the ELB to get

Returns the Aws::ElasticLoadBalancing::Types::LoadBalancerDescription by that name

# File lib/elb/ELB.rb, line 15
def get_aws(name)
  if elbs[name].nil?
    puts "No ELB named #{name}"
    exit
  else
    elbs[name]
  end
end
get_aws_by_dns_name(dns_name) click to toggle source

Public: Static method that will get an ELB from AWS by its dns name.

dns_name - the dns name of the ELB to get

Returns the Aws::ElasticLoadBalancing::Types::LoadBalancerDescription with that dns name

# File lib/elb/ELB.rb, line 29
def get_aws_by_dns_name(dns_name)
  elbs_to_dns_names[dns_name]
end

Private Class Methods

elbs_to_dns_names() click to toggle source

Internal: Provide a mapping of ELBs to their dns names. Lazily loads resources.

Returns the ELBs mapped to their dns names

# File lib/elb/ELB.rb, line 77
def elbs_to_dns_names
  @elbs_to_dns_names ||= Hash[elbs.map { |_, elb| [elb.dns_name, elb] }]
end
init_default_policies() click to toggle source

Internal: Load the default ELB policies

Returns an array of Aws::ElasticLoadBalancing::Types::PolicyDescription

# File lib/elb/ELB.rb, line 133
def init_default_policies
  @@client.describe_load_balancer_policies.policy_descriptions
end
init_elb_attributes(elb_name) click to toggle source

Internal: Load ELB attributes for an ELB

elb_name - the name of the ELB to get attributes for

Returns the ELB attributes

# File lib/elb/ELB.rb, line 124
def init_elb_attributes(elb_name)
  @@client.describe_load_balancer_attributes({
    load_balancer_name: elb_name
  }).load_balancer_attributes
end
init_elb_policies(elb_name) click to toggle source

Internal: Load the policies for a load balancer

Returns an array of Aws::ElasticLoadBalancing::Types::PolicyDescription

# File lib/elb/ELB.rb, line 140
def init_elb_policies(elb_name)
  @@client.describe_load_balancer_policies({
    load_balancer_name: elb_name
  }).policy_descriptions
end
init_elb_tags() click to toggle source

Internal: Load ELB tags and map them to their names

Returns the ELB tags mapped to ELB name

# File lib/elb/ELB.rb, line 108
def init_elb_tags
  tags = []
  elbs.keys.each_slice(20) do |names|
    tags << @@client.describe_tags({
      load_balancer_names: names
    }).tag_descriptions
  end

  Hash[tags.flatten.map { |td| [td.load_balancer_name, td.tags] }]
end
init_elbs() click to toggle source

Internal: Load ELBs and map them to their names.

Returns the ELBs mapped to their names

# File lib/elb/ELB.rb, line 84
def init_elbs
  elbs = []
  all_records_retrieved = false
  next_marker = nil

  until all_records_retrieved
    response = @@client.describe_load_balancers({
      marker: next_marker
    }.reject { |k, v| v.nil? })

    elbs << response.load_balancer_descriptions
    next_marker = response.next_marker

    if next_marker == nil
      all_records_retrieved = true
    end
  end

  Hash[elbs.flatten.map { |elb| [elb.load_balancer_name, elb] }]
end