Sha256: 9ca66285168c51bd839f6515ea6642dcf5f42129ced33cfecd3e581cfcf2a880

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 KB

Contents

module OpenStax::Aws
  class AutoScalingGroup
    attr_reader :raw_asg, :region

    delegate_missing_to :@raw_asg

    def self.physical_resource_id_attribute
      :name
    end

    def initialize(name:, region:)
      @raw_asg = Aws::AutoScaling::AutoScalingGroup.new(
        name: name,
        client: Aws::AutoScaling::Client.new(region: region)
      )
      @region = region
    end

    def increase_desired_capacity(by:)
      # take the smaller of max size or desired+by (or this call raises an exception)
      increase_to = [raw_asg.max_size, raw_asg.desired_capacity + by].min

      raw_asg.set_desired_capacity(
        {
          desired_capacity: increase_to
        })
    end

    def desired_capacity
      raw_asg.desired_capacity
    end

    def alarms
      client.describe_policies(
        auto_scaling_group_name: raw_asg.name
      ).flat_map(&:scaling_policies).flat_map(&:alarms).map do |alarm|
        OpenStax::Aws::Alarm.new region: region, name: alarm.alarm_name
      end
    end

    def add_tags_not_handled_by_cloudformation(stack_tags)
      alarms.each { |alarm| alarm.add_tags_not_handled_by_cloudformation stack_tags }
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
openstax_aws-2.1.0 lib/openstax/aws/auto_scaling_group.rb
openstax_aws-2.0.1 lib/openstax/aws/auto_scaling_group.rb
openstax_aws-2.0.0 lib/openstax/aws/auto_scaling_group.rb
openstax_aws-1.6.1 lib/openstax/aws/auto_scaling_group.rb
openstax_aws-1.6.0 lib/openstax/aws/auto_scaling_group.rb
openstax_aws-1.5.0 lib/openstax/aws/auto_scaling_group.rb