Sha256: cacf8ffd4860e259ac944398d4e3c5a8d2c8e6ca779cf0bd9535f09579a5fbb0

Contents?: true

Size: 1.91 KB

Versions: 2

Compression:

Stored size: 1.91 KB

Contents

class Ey::Core::Client::AutoScalingGroup < Ey::Core::Model
  extend Ey::Core::Associations

  identity :id

  attribute :created_at, type: :time
  attribute :deleted_at, type: :time
  attribute :location_id
  attribute :provisioned_id
  attribute :minimum_size
  attribute :maximum_size
  attribute :desired_capacity
  attribute :default_cooldown
  attribute :grace_period

  has_one :environment

  def destroy
    connection.requests.new(connection.destroy_auto_scaling_group("id" => self.identity).body["request"])
  end

  def save!
    if new_record?
      requires :maximum_size, :minimum_size, :environment

      params = {
        "url"                => self.collection.url,
        "environment"        => self.environment_id,
        "auto_scaling_group" => {
          "maximum_size" => self.maximum_size,
          "minimum_size" => self.minimum_size,
        }
      }

      connection.requests.new(connection.create_auto_scaling_group(params).body["request"])
    else
      requires :identity

      params = {
        "id" => self.identity,
        "auto_scaling_group" => {
          "maximum_size" => self.maximum_size,
          "minimum_size" => self.minimum_size,
          "desired_capacity" => self.desired_capacity
        }
      }

      connection.requests.new(connection.update_auto_scaling_group(params).body["request"])
    end
  end

  def simple_auto_scaling_policies
    auto_scaling_policies("simple")
  end

  def step_auto_scaling_policies
    auto_scaling_policies("step")
  end

  def target_auto_scaling_policies
    auto_scaling_policies("target")
  end

  private

  def auto_scaling_policies(types = nil)
    requires :identity
    data = connection.get_auto_scaling_policies(
      "auto_scaling_group" => identity,
      "types" => [*types]
    ).body["auto_scaling_policies"]

    connection.auto_scaling_policies.load(data)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ey-core-3.6.6 lib/ey-core/models/auto_scaling_group.rb
ey-core-3.6.5 lib/ey-core/models/auto_scaling_group.rb