Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/harp-runtime/models/autoscale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ class AutoScalingGroup < HarpResource
end

class LaunchConfiguration < HarpResource
end

class ScalingPolicy < HarpResource
end
51 changes: 51 additions & 0 deletions lib/harp-runtime/resources/autoscaling/scaling_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'set'
require 'fog/core/model'
require 'harp-runtime/models/autoscale'
require 'json'

module Harp
module Resources

class ScalingPolicy < AvailableResource

include Harp::Resources

identity :id, :aliases => 'PolicyName'
attribute :arn, :aliases => 'PolicyARN'
attribute :adjustment_type, :aliases => 'AdjustmentType'
attribute :alarms, :aliases => 'Alarms'
attribute :auto_scaling_group_name, :aliases => 'AutoScalingGroupName'
attribute :cooldown, :aliases => 'Cooldown'
attribute :min_adjustment_step, :aliases => 'MinAdjustmentStep'
attribute :scaling_adjustment, :aliases => 'ScalingAdjustment'

register_resource :scaling_policy, RESOURCES_AUTOSCALE

# Only keeping a few properties, simplest define keeps.
@keeps = /^id$/


def self.persistent_type()
::ScalingPolicy
end

def create(service)
create_attribs=self.attribs[:attributes]
policy = service.policies.create(create_attribs)
return policy
end

def destroy(service)
destroy_attribs = self.attribs
if @id
group = service.groups.destroy(destroy_attribs)
else
puts "No ID set, cannot delete."
end
return group
end

end
end
end

2 changes: 2 additions & 0 deletions lib/harp-runtime/resources/autoscaling/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

require 'harp-runtime/resources/autoscaling/launch_configuration'
require 'harp-runtime/resources/autoscaling/autoscaling_group'
require 'harp-runtime/resources/autoscaling/scaling_policy'


module Harp
module Resources
Expand Down
22 changes: 22 additions & 0 deletions spec/autoscaling_cloud_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
"min_size" => "1"
}

autoscaling_policy_resource = {
"type" => "Std::ScalingPolicy",
"id" => "testScalingPolicy",
"adjustment_type" => "PercentChangeInCapacity",
"auto_scaling_group_name" => "testASG",
"scaling_adjustment" => "0"
}

describe Harp::Cloud::CloudMutator, "#create" do
it "creates a launch configuration" do
context = {}
Expand Down Expand Up @@ -47,4 +55,18 @@
expect(result.class).to eq(AutoScalingGroup)
expect(result.name).to eq("test_as_group1")
end

it "creates AutoScaling Policy" do
context = {}
context[:cloud_type] = :aws # for the moment, ainstancessume AWS cloud
context[:mock] = true
context[:debug] = true
context[:access] = "test"
context[:secret] = "test"
mutator = Harp::Cloud::CloudMutator.new(context)

result = mutator.create("test_as_policy1", autoscaling_policy_resource)
expect(result.class).to eq(ScalingPolicy)
expect(result.name).to eq("test_as_policy1")
end
end