Sha256: 1b57dd7325f9e1be3a45df678dc3ee5e31f7aac0deb790eb6ad7b28dada95b6f

Contents?: true

Size: 1.4 KB

Versions: 8

Compression:

Stored size: 1.4 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

8 entries across 8 versions & 2 rubygems

Version Path
ey-core-3.6.0.autoscaling1 lib/ey-core/models/base_auto_scaling_policy.rb
ey-core-3.6.4 lib/ey-core/models/base_auto_scaling_policy.rb
ey-core-3.6.3 lib/ey-core/models/base_auto_scaling_policy.rb
ey-core-3.6.1 lib/ey-core/models/base_auto_scaling_policy.rb
groove-ey-core-3.6.3 lib/ey-core/models/base_auto_scaling_policy.rb
groove-ey-core-3.6.2 lib/ey-core/models/base_auto_scaling_policy.rb
groove-ey-core-3.6.1 lib/ey-core/models/base_auto_scaling_policy.rb
ey-core-3.5.0 lib/ey-core/models/base_auto_scaling_policy.rb