Sha256: 5bd3c2c12b7d51a79271e448a86ccf613cb2648a897f0a4cef230777e543c898

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

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

  identity :id, type: :integer

  attribute :provisioned_id
  attribute :provisioner_id
  attribute :type
  attribute :name
  attribute :configuration
  attribute :auto_scaling_group_id

  has_one :auto_scaling_group

  def save!
    requires :auto_scaling_group_id, :type
    params = {
      "url"                 => self.collection.url,
      "auto_scaling_policy" => {
        "name" => self.name
      }.merge(policy_params),
      "auto_scaling_group_id"  => self.auto_scaling_group_id
    }

    if new_record?
      policy_requires
      requires :name
      connection.requests.new(connection.create_auto_scaling_policy(params).body["request"])
    else
      requires :identity
      params.merge("id" => identity)
      connection.requests.new(connection.update_auto_scaling_policy(params).body["request"])
    end
  end

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

  def alarm
    requires :identity

    data = self.connection.get_auto_scaling_alarms(
      "auto_scaling_policy_id" => identity
    ).body["auto_scaling_alarms"]

    self.connection.auto_scaling_alarms.load(data).first
  end

  private

  def policy_params
    raise NotImplementedError
  end

  def policy_requires
    raise NotImplementedError
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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