diff --git a/lib/harp-runtime/models/autoscale.rb b/lib/harp-runtime/models/autoscale.rb index d9bd90f..8bb504c 100644 --- a/lib/harp-runtime/models/autoscale.rb +++ b/lib/harp-runtime/models/autoscale.rb @@ -5,4 +5,7 @@ class AutoScalingGroup < HarpResource end class LaunchConfiguration < HarpResource +end + +class ScalingPolicy < HarpResource end \ No newline at end of file diff --git a/lib/harp-runtime/resources/autoscaling/scaling_policy.rb b/lib/harp-runtime/resources/autoscaling/scaling_policy.rb new file mode 100644 index 0000000..6eb13b2 --- /dev/null +++ b/lib/harp-runtime/resources/autoscaling/scaling_policy.rb @@ -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 + diff --git a/lib/harp-runtime/resources/autoscaling/types.rb b/lib/harp-runtime/resources/autoscaling/types.rb index 42eee76..10bcdf9 100644 --- a/lib/harp-runtime/resources/autoscaling/types.rb +++ b/lib/harp-runtime/resources/autoscaling/types.rb @@ -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 diff --git a/spec/autoscaling_cloud_spec.rb b/spec/autoscaling_cloud_spec.rb index 3554a6d..322f23e 100644 --- a/spec/autoscaling_cloud_spec.rb +++ b/spec/autoscaling_cloud_spec.rb @@ -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 = {} @@ -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 \ No newline at end of file