Class: Rivet::AwsAutoscaleWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/rivet/aws_autoscale_wrapper.rb

Constant Summary collapse

OPTIONS =
[
  :availability_zones,
  :default_cooldown,
  :desired_capacity,
  :health_check_grace_period,
  :health_check_type,
  :launch_configuration,
  :load_balancers,
  :max_size,
  :min_size,
  :placement_group,
  :subnets,
  :tags,
  :termination_policies
].each { |a| attr_reader a }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ AwsAutoscaleWrapper

Returns a new instance of AwsAutoscaleWrapper.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rivet/aws_autoscale_wrapper.rb', line 24

def initialize(name)
  Rivet::Log.debug "Initializing AWS Autoscale Wrapper for #{name}"
  @name = name
  @group = AWS::AutoScaling.new.groups[@name]

  if @group.exists?
    OPTIONS.each do |o|
      normalize_method = "normalize_#{o}".to_sym
      if respond_to?(normalize_method)
        Rivet::Log.debug "Calling #{normalize_method} in AWS autoscale wrapper"
        value = send(normalize_method)
      else
        value = @group.send(o)
      end
      instance_variable_set("@#{o}", value)
    end
  end

end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/rivet/aws_autoscale_wrapper.rb', line 22

def name
  @name
end

Instance Method Details

#normalize_availability_zonesObject



52
53
54
# File 'lib/rivet/aws_autoscale_wrapper.rb', line 52

def normalize_availability_zones
  @group.availability_zone_names.to_a.sort
end

#normalize_launch_configurationObject



44
45
46
# File 'lib/rivet/aws_autoscale_wrapper.rb', line 44

def normalize_launch_configuration
  @group.launch_configuration_name
end

#normalize_load_balancersObject



48
49
50
# File 'lib/rivet/aws_autoscale_wrapper.rb', line 48

def normalize_load_balancers
  @group.load_balancer_names.to_a.sort
end

#normalize_subnetsObject



62
63
64
# File 'lib/rivet/aws_autoscale_wrapper.rb', line 62

def normalize_subnets
  @group.subnets.empty? ? nil : @group.subnets.map(&:id).sort
end

#normalize_tagsObject



56
57
58
59
60
# File 'lib/rivet/aws_autoscale_wrapper.rb', line 56

def normalize_tags
  @group.tags.to_a.inject([]) do |normalized_tags, current|
    normalized_tags << normalize_tag(current)
  end
end

#normalize_termination_policiesObject



66
67
68
# File 'lib/rivet/aws_autoscale_wrapper.rb', line 66

def normalize_termination_policies
  @group.termination_policies.to_a.sort
end