mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #1004 from trotter/aws-launch-configuration-parameters
AWS AutoScaling
This commit is contained in:
commit
2b366e7722
22 changed files with 314 additions and 30 deletions
|
@ -50,6 +50,8 @@ module Fog
|
||||||
collection :groups
|
collection :groups
|
||||||
model :instance
|
model :instance
|
||||||
collection :instances
|
collection :instances
|
||||||
|
model :policy
|
||||||
|
collection :policies
|
||||||
|
|
||||||
class Real
|
class Real
|
||||||
include Fog::AWS::CredentialFetcher::ConnectionMethods
|
include Fog::AWS::CredentialFetcher::ConnectionMethods
|
||||||
|
@ -165,6 +167,7 @@ module Fog
|
||||||
'PercentChangeInCapacity'
|
'PercentChangeInCapacity'
|
||||||
],
|
],
|
||||||
:auto_scaling_groups => {},
|
:auto_scaling_groups => {},
|
||||||
|
:scaling_policies => {},
|
||||||
:health_states => ['Healthy', 'Unhealthy'],
|
:health_states => ['Healthy', 'Unhealthy'],
|
||||||
:launch_configurations => {},
|
:launch_configurations => {},
|
||||||
:metric_collection_types => {
|
:metric_collection_types => {
|
||||||
|
|
|
@ -36,9 +36,37 @@ module Fog
|
||||||
|
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
def initialize(options={})
|
def self.data
|
||||||
|
@data ||= Hash.new do |hash, region|
|
||||||
|
hash[region] = Hash.new do |region_hash, key|
|
||||||
|
region_hash[key] = {
|
||||||
|
:metric_alarms => {}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.reset
|
||||||
|
@data = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def initialize(options={})
|
||||||
|
@aws_access_key_id = options[:aws_access_key_id]
|
||||||
|
|
||||||
|
@region = options[:region] || 'us-east-1'
|
||||||
|
|
||||||
|
unless ['ap-northeast-1', 'ap-southeast-1', 'eu-west-1', 'sa-east-1', 'us-east-1', 'us-west-1', 'us-west-2'].include?(@region)
|
||||||
|
raise ArgumentError, "Unknown region: #{@region.inspect}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def data
|
||||||
|
self.class.data[@region][@aws_access_key_id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def reset_data
|
||||||
|
self.class.data[@region].delete(@aws_access_key_id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Real
|
class Real
|
||||||
|
|
|
@ -39,7 +39,9 @@ module Fog
|
||||||
requires :image_id
|
requires :image_id
|
||||||
requires :instance_type
|
requires :instance_type
|
||||||
|
|
||||||
connection.create_launch_configuration(image_id, instance_type, id) #, listeners.map{|l| l.to_params})
|
options = Hash[self.class.aliases.map { |key, value| [key, send(value)] }]
|
||||||
|
options.delete_if { |key, value| value.nil? }
|
||||||
|
connection.create_launch_configuration(image_id, instance_type, id, options) #, listeners.map{|l| l.to_params})
|
||||||
|
|
||||||
# reload instead of merge attributes b/c some attrs (like HealthCheck)
|
# reload instead of merge attributes b/c some attrs (like HealthCheck)
|
||||||
# may be set, but only the DNS name is returned in the create_load_balance
|
# may be set, but only the DNS name is returned in the create_load_balance
|
||||||
|
|
|
@ -4,7 +4,6 @@ module Fog
|
||||||
module AWS
|
module AWS
|
||||||
class AutoScaling
|
class AutoScaling
|
||||||
class Group < Fog::Model
|
class Group < Fog::Model
|
||||||
|
|
||||||
identity :id, :aliases => 'AutoScalingGroupName'
|
identity :id, :aliases => 'AutoScalingGroupName'
|
||||||
attribute :arn, :aliases => 'AutoScalingGroupARN'
|
attribute :arn, :aliases => 'AutoScalingGroupARN'
|
||||||
attribute :availability_zones, :aliases => 'AvailabilityZones'
|
attribute :availability_zones, :aliases => 'AvailabilityZones'
|
||||||
|
@ -22,6 +21,7 @@ module Fog
|
||||||
attribute :placement_group, :aliases => 'PlacementGroup'
|
attribute :placement_group, :aliases => 'PlacementGroup'
|
||||||
attribute :suspended_processes, :aliases => 'SuspendedProcesses'
|
attribute :suspended_processes, :aliases => 'SuspendedProcesses'
|
||||||
attribute :vpc_zone_identifier, :aliases => 'VPCZoneIdentifier'
|
attribute :vpc_zone_identifier, :aliases => 'VPCZoneIdentifier'
|
||||||
|
attribute :tags, :aliases => 'Tags'
|
||||||
|
|
||||||
def initialize(attributes={})
|
def initialize(attributes={})
|
||||||
attributes['DefaultCooldown'] ||= 0
|
attributes['DefaultCooldown'] ||= 0
|
||||||
|
@ -34,6 +34,7 @@ module Fog
|
||||||
attributes['MaxSize'] ||= 0
|
attributes['MaxSize'] ||= 0
|
||||||
attributes['MinSize'] ||= 0
|
attributes['MinSize'] ||= 0
|
||||||
attributes['SuspendedProcesses'] ||= []
|
attributes['SuspendedProcesses'] ||= []
|
||||||
|
attributes['Tags'] ||= []
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -112,7 +113,7 @@ module Fog
|
||||||
requires :max_size
|
requires :max_size
|
||||||
requires :min_size
|
requires :min_size
|
||||||
|
|
||||||
connection.create_auto_scaling_group(id, availability_zones, launch_configuration_name, max_size, min_size)
|
connection.create_auto_scaling_group(id, availability_zones, launch_configuration_name, max_size, min_size, options)
|
||||||
reload
|
reload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -126,14 +127,17 @@ module Fog
|
||||||
connection.delete_auto_scaling_group(id)
|
connection.delete_auto_scaling_group(id)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def update
|
||||||
|
|
||||||
def update(options)
|
|
||||||
requires :id
|
requires :id
|
||||||
connection.update_auto_scaling_group(id, options)
|
connection.update_auto_scaling_group(id, options)
|
||||||
reload
|
reload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def options
|
||||||
|
ret = Hash[self.class.aliases.map { |key, value| [key, send(value)] }]
|
||||||
|
ret.delete_if { |key, value| value.nil? }
|
||||||
|
ret
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
33
lib/fog/aws/models/auto_scaling/policies.rb
Normal file
33
lib/fog/aws/models/auto_scaling/policies.rb
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
require 'fog/aws/models/auto_scaling/policy'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module AWS
|
||||||
|
class AutoScaling
|
||||||
|
class Policies < Fog::Collection
|
||||||
|
model Fog::AWS::AutoScaling::Policy
|
||||||
|
|
||||||
|
# Creates a new scaling policy.
|
||||||
|
def initialize(attributes={})
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def all
|
||||||
|
data = []
|
||||||
|
next_token = nil
|
||||||
|
loop do
|
||||||
|
result = connection.describe_policies('NextToken' => next_token).body['DescribePoliciesResult']
|
||||||
|
data += result['ScalingPolicies']
|
||||||
|
next_token = result['NextToken']
|
||||||
|
break if next_token.nil?
|
||||||
|
end
|
||||||
|
load(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(identity, auto_scaling_group = nil)
|
||||||
|
data = connection.describe_policies('PolicyNames' => identity, 'AutoScalingGroupName' => auto_scaling_group).body['DescribePoliciesResult']['ScalingPolicies'].first
|
||||||
|
new(data) unless data.nil?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
46
lib/fog/aws/models/auto_scaling/policy.rb
Normal file
46
lib/fog/aws/models/auto_scaling/policy.rb
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
require 'fog/core/model'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module AWS
|
||||||
|
class AutoScaling
|
||||||
|
class Policy < Fog::Model
|
||||||
|
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'
|
||||||
|
|
||||||
|
def initialize(attributes)
|
||||||
|
attributes['AdjustmentType'] ||= 'ChangeInCapacity'
|
||||||
|
attributes['ScalingAdjustment'] ||= 1
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
# TODO: implement #alarms
|
||||||
|
# TODO: implement #auto_scaling_group
|
||||||
|
|
||||||
|
def save
|
||||||
|
requires :id
|
||||||
|
requires :adjustment_type
|
||||||
|
requires :auto_scaling_group_name
|
||||||
|
requires :scaling_adjustment
|
||||||
|
|
||||||
|
options = Hash[self.class.aliases.map { |key, value| [key, send(value)] }]
|
||||||
|
options.delete_if { |key, value| value.nil? }
|
||||||
|
|
||||||
|
connection.put_scaling_policy(adjustment_type, auto_scaling_group_name, id, scaling_adjustment, options)
|
||||||
|
reload
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
requires :id
|
||||||
|
requires :auto_scaling_group_name
|
||||||
|
connection.delete_policy(auto_scaling_group_name, id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,9 +3,57 @@ require 'fog/core/model'
|
||||||
module Fog
|
module Fog
|
||||||
module AWS
|
module AWS
|
||||||
class CloudWatch
|
class CloudWatch
|
||||||
|
|
||||||
class Alarm < Fog::Model
|
class Alarm < Fog::Model
|
||||||
attribute :alarm_names, :aliases => 'AlarmNames'
|
identity :id, :aliases => 'AlarmName'
|
||||||
|
|
||||||
|
attribute :actions_enabled, :aliases => 'ActionsEnabled'
|
||||||
|
attribute :alarm_actions, :aliases => 'AlarmActions'
|
||||||
|
attribute :arn, :aliases => 'AlarmArn'
|
||||||
|
attribute :alarm_configuration_updated_timestamp, :aliases => 'AlarmConfigurationUpdatedTimestamp'
|
||||||
|
attribute :alarm_description, :aliases => 'AlarmDescription'
|
||||||
|
attribute :comparison_operator, :aliases => 'ComparisonOperator'
|
||||||
|
attribute :dimensions, :aliases => 'Dimensions'
|
||||||
|
attribute :evaluation_periods, :aliases => 'EvaluationPeriods'
|
||||||
|
attribute :insufficient_data_actions, :aliases => 'InsufficientDataActions'
|
||||||
|
attribute :metric_name, :aliases => 'MetricName'
|
||||||
|
attribute :namespace, :aliases => 'Namespace'
|
||||||
|
attribute :ok_actions, :aliases => 'OKActions'
|
||||||
|
attribute :period, :aliases => 'Period'
|
||||||
|
attribute :state_reason, :aliases => 'StateReason'
|
||||||
|
attribute :state_reason_data, :aliases => 'StateReasonData'
|
||||||
|
attribute :state_updated_timestamp, :aliases => 'StateUpdatedTimestamp'
|
||||||
|
attribute :state_value, :aliases => 'StateValue'
|
||||||
|
attribute :statistic, :aliases => 'Statistic'
|
||||||
|
attribute :threshold, :aliases => 'Threshold'
|
||||||
|
attribute :unit, :aliases => 'Unit'
|
||||||
|
|
||||||
|
def initialize(attributes)
|
||||||
|
attributes['EvaluationPeriods'] ||= 1
|
||||||
|
attributes['Namespace'] ||= 'AWS/EC2'
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def save
|
||||||
|
requires :id
|
||||||
|
requires :comparison_operator
|
||||||
|
requires :evaluation_periods
|
||||||
|
requires :metric_name
|
||||||
|
requires :namespace
|
||||||
|
requires :period
|
||||||
|
requires :statistic
|
||||||
|
requires :threshold
|
||||||
|
|
||||||
|
options = Hash[self.class.aliases.map { |key, value| [key, send(value)] }]
|
||||||
|
options.delete_if { |key, value| value.nil? }
|
||||||
|
|
||||||
|
connection.put_metric_alarm(options)
|
||||||
|
reload
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
requires :id
|
||||||
|
connection.delete_alarms(id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,6 +8,23 @@ module Fog
|
||||||
class Alarms < Fog::Collection
|
class Alarms < Fog::Collection
|
||||||
model Fog::AWS::CloudWatch::Alarm
|
model Fog::AWS::CloudWatch::Alarm
|
||||||
|
|
||||||
|
def all
|
||||||
|
data = []
|
||||||
|
next_token = nil
|
||||||
|
loop do
|
||||||
|
result = connection.describe_alarms('NextToken' => next_token).body['DescribeAlarmsResult']
|
||||||
|
data += result['MetricAlarms']
|
||||||
|
next_token = result['NextToken']
|
||||||
|
break if next_token.nil?
|
||||||
|
end
|
||||||
|
load(data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(identity)
|
||||||
|
data = connection.describe_alarms('AlarmNames' => identity).body['DescribeAlarmsResult']['MetricAlarms'].first
|
||||||
|
new(data) unless data.nil?
|
||||||
|
end
|
||||||
|
|
||||||
#alarm_names is an array of alarm names
|
#alarm_names is an array of alarm names
|
||||||
def delete(alarm_names)
|
def delete(alarm_names)
|
||||||
connection.delete_alarms(alarm_names)
|
connection.delete_alarms(alarm_names)
|
||||||
|
|
|
@ -49,13 +49,15 @@ module Fog
|
||||||
@response['DescribePoliciesResult'] = @results
|
@response['DescribePoliciesResult'] = @results
|
||||||
|
|
||||||
when 'Alarms'
|
when 'Alarms'
|
||||||
if @in_alarms == true
|
@in_alarms = false
|
||||||
|
when 'member'
|
||||||
|
if @in_alarms
|
||||||
@scaling_policy['Alarms'] << @alarm
|
@scaling_policy['Alarms'] << @alarm
|
||||||
reset_alarm
|
reset_alarm
|
||||||
|
else
|
||||||
|
@results['ScalingPolicies'] << @scaling_policy
|
||||||
|
reset_scaling_policy
|
||||||
end
|
end
|
||||||
when 'member'
|
|
||||||
@results['ScalingPolicies'] << @scaling_policy
|
|
||||||
reset_scaling_policy
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -49,9 +49,17 @@ module Fog
|
||||||
#
|
#
|
||||||
def create_auto_scaling_group(auto_scaling_group_name, availability_zones, launch_configuration_name, max_size, min_size, options = {})
|
def create_auto_scaling_group(auto_scaling_group_name, availability_zones, launch_configuration_name, max_size, min_size, options = {})
|
||||||
options.merge!(AWS.indexed_param('AvailabilityZones.member.%d', [*availability_zones]))
|
options.merge!(AWS.indexed_param('AvailabilityZones.member.%d', [*availability_zones]))
|
||||||
|
options.delete('AvailabilityZones')
|
||||||
if load_balancer_names = options.delete('LoadBalancerNames')
|
if load_balancer_names = options.delete('LoadBalancerNames')
|
||||||
options.merge!(AWS.indexed_param('LoadBalancerNames.member.%d', [*load_balancer_names]))
|
options.merge!(AWS.indexed_param('LoadBalancerNames.member.%d', [*load_balancer_names]))
|
||||||
end
|
end
|
||||||
|
if tags = options.delete('Tags')
|
||||||
|
tags.each_with_index do |tag, i|
|
||||||
|
tag.each do |key, value|
|
||||||
|
options["Tags.member.#{i + 1}.#{key.to_s.capitalize}"] = value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
request({
|
request({
|
||||||
'Action' => 'CreateAutoScalingGroup',
|
'Action' => 'CreateAutoScalingGroup',
|
||||||
'AutoScalingGroupName' => auto_scaling_group_name,
|
'AutoScalingGroupName' => auto_scaling_group_name,
|
||||||
|
|
|
@ -78,9 +78,8 @@ module Fog
|
||||||
data[:launch_configurations][launch_configuration_name] = {
|
data[:launch_configurations][launch_configuration_name] = {
|
||||||
'BlockDeviceMappings' => [],
|
'BlockDeviceMappings' => [],
|
||||||
'CreatedTime' => Time.now.utc,
|
'CreatedTime' => Time.now.utc,
|
||||||
'IamInstanceProfile' => nil,
|
|
||||||
'ImageId' => image_id,
|
'ImageId' => image_id,
|
||||||
'InstanceMonitoring.Enabled' => true,
|
'InstanceMonitoring' => {'Enabled' => true},
|
||||||
'InstanceType' => instance_type,
|
'InstanceType' => instance_type,
|
||||||
'KernelId' => nil,
|
'KernelId' => nil,
|
||||||
'KeyName' => nil,
|
'KeyName' => nil,
|
||||||
|
|
|
@ -35,9 +35,17 @@ module Fog
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
def delete_auto_scaling_group(auto_scaling_group_name)
|
def delete_auto_scaling_group(auto_scaling_group_name)
|
||||||
Fog::Mock.not_implemented
|
unless self.data[:auto_scaling_groups].delete(auto_scaling_group_name)
|
||||||
end
|
raise Fog::AWS::Autoscaling::NotFound, "The auto scaling group '#{auto_scaling_group_name}' does not exist."
|
||||||
|
end
|
||||||
|
|
||||||
|
response = Excon::Response.new
|
||||||
|
response.status = 200
|
||||||
|
response.body = {
|
||||||
|
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
|
||||||
|
}
|
||||||
|
response
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,7 +39,7 @@ module Fog
|
||||||
|
|
||||||
def delete_launch_configuration(launch_configuration_name)
|
def delete_launch_configuration(launch_configuration_name)
|
||||||
unless self.data[:launch_configurations].delete(launch_configuration_name)
|
unless self.data[:launch_configurations].delete(launch_configuration_name)
|
||||||
raise Fog::AWS::AutoScaling::ValidationError, "Launch configuration name not found - Launch configuration #{launch_configuration_name} not found"
|
raise Fog::AWS::AutoScaling::NotFound, "The launch configuration '#{launch_configuration_name}' does not exist."
|
||||||
end
|
end
|
||||||
|
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
|
|
|
@ -37,7 +37,16 @@ module Fog
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
def delete_policy(auto_scaling_group_name, policy_name)
|
def delete_policy(auto_scaling_group_name, policy_name)
|
||||||
Fog::Mock.not_implemented
|
unless data[:scaling_policies].delete(policy_name)
|
||||||
|
raise Fog::AWS::AutoScaling::NotFound, "The scaling policy '#{policy_name}' does not exist."
|
||||||
|
end
|
||||||
|
|
||||||
|
response = Excon::Response.new
|
||||||
|
response.status = 200
|
||||||
|
response.body = {
|
||||||
|
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
|
||||||
|
}
|
||||||
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -73,7 +73,6 @@ module Fog
|
||||||
def describe_auto_scaling_instances(options = {})
|
def describe_auto_scaling_instances(options = {})
|
||||||
results = { 'AutoScalingInstances' => [] }
|
results = { 'AutoScalingInstances' => [] }
|
||||||
data[:auto_scaling_groups].each do |asg_name, asg_data|
|
data[:auto_scaling_groups].each do |asg_name, asg_data|
|
||||||
lc_name = data[asg_data][lc_name]
|
|
||||||
asg_data['Instances'].each do |instance|
|
asg_data['Instances'].each do |instance|
|
||||||
results['AutoScalingInstances'] << {
|
results['AutoScalingInstances'] << {
|
||||||
'AutoScalingGroupName' => asg_name
|
'AutoScalingGroupName' => asg_name
|
||||||
|
|
|
@ -75,7 +75,19 @@ module Fog
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
def describe_policies(options = {})
|
def describe_policies(options = {})
|
||||||
Fog::Mock.not_implemented
|
results = { 'ScalingPolicies' => [] }
|
||||||
|
data[:scaling_policies].each do |asp_name, asp_data|
|
||||||
|
results['ScalingPolicies'] << {
|
||||||
|
'PolicyName' => asp_name
|
||||||
|
}.merge!(asp_data)
|
||||||
|
end
|
||||||
|
response = Excon::Response.new
|
||||||
|
response.status = 200
|
||||||
|
response.body = {
|
||||||
|
'DescribePoliciesResult' => results,
|
||||||
|
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
|
||||||
|
}
|
||||||
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,7 +56,26 @@ module Fog
|
||||||
class Mock
|
class Mock
|
||||||
|
|
||||||
def put_scaling_policy(adjustment_type, auto_scaling_group_name, policy_name, scaling_adjustment, options = {})
|
def put_scaling_policy(adjustment_type, auto_scaling_group_name, policy_name, scaling_adjustment, options = {})
|
||||||
Fog::Mock.not_implemented
|
unless data[:auto_scaling_groups].has_key?(auto_scaling_group_name)
|
||||||
|
raise Fog::AWS::AutoScaling::ValidationError.new('Auto Scaling Group name not found - null')
|
||||||
|
end
|
||||||
|
data[:scaling_policies][policy_name] = {
|
||||||
|
'AdjustmentType' => adjustment_type,
|
||||||
|
'Alarms' => [],
|
||||||
|
'AutoScalingGroupName' => auto_scaling_group_name,
|
||||||
|
'Cooldown' => 0,
|
||||||
|
'MinAdjustmentStep' => 0,
|
||||||
|
'PolicyARN' => "arn:aws:autoscaling:eu-west-1:000000000000:scalingPolicy:00000000-0000-0000-0000-000000000000:autoScalingGroupName/#{auto_scaling_group_name}:policyName/#{policy_name}",
|
||||||
|
'PolicyName' => policy_name,
|
||||||
|
'ScalingAdjustment' => scaling_adjustment
|
||||||
|
}.merge!(options)
|
||||||
|
|
||||||
|
response = Excon::Response.new
|
||||||
|
response.status = 200
|
||||||
|
response.body = {
|
||||||
|
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
|
||||||
|
}
|
||||||
|
response
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -62,7 +62,7 @@ module Fog
|
||||||
unless data[:auto_scaling_groups].has_key?(auto_scaling_group_name)
|
unless data[:auto_scaling_groups].has_key?(auto_scaling_group_name)
|
||||||
raise Fog::AWS::AutoScaling::ValidationError.new('AutoScalingGroup name not found - null')
|
raise Fog::AWS::AutoScaling::ValidationError.new('AutoScalingGroup name not found - null')
|
||||||
end
|
end
|
||||||
data[:auto_scaling_group_name][auto_scaling_group_name].merge!(options)
|
data[:auto_scaling_groups][auto_scaling_group_name].merge!(options)
|
||||||
|
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
response.status = 200
|
response.status = 200
|
||||||
|
|
|
@ -25,6 +25,24 @@ module Fog
|
||||||
}.merge(options))
|
}.merge(options))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
def delete_alarms(alarm_names)
|
||||||
|
[*alarm_names].each do |alarm_name|
|
||||||
|
unless data[:metric_alarms].has_key?(alarm_name)
|
||||||
|
raise Fog::AWS::AutoScaling::NotFound, "The alarm '#{alarm_name}' does not exist."
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
[*alarm_names].each { |alarm_name| data[:metric_alarms].delete(alarm_name) }
|
||||||
|
response = Excon::Response.new
|
||||||
|
response.status = 200
|
||||||
|
response.body = {
|
||||||
|
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
|
||||||
|
}
|
||||||
|
response
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,6 +33,24 @@ module Fog
|
||||||
}.merge(options))
|
}.merge(options))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
def describe_alarms(options={})
|
||||||
|
results = { 'MetricAlarms' => [] }
|
||||||
|
data[:metric_alarms].each do |alarm_name, alarm_data|
|
||||||
|
results['MetricAlarms'] << {
|
||||||
|
'AlarmName' => alarm_name
|
||||||
|
}.merge!(alarm_data)
|
||||||
|
end
|
||||||
|
response = Excon::Response.new
|
||||||
|
response.status = 200
|
||||||
|
response.body = {
|
||||||
|
'DescribeAlarmsResult' => results,
|
||||||
|
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
|
||||||
|
}
|
||||||
|
response
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -71,6 +71,15 @@ module Fog
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
data[:metric_alarms][options['AlarmName']] = {
|
||||||
|
'AlarmARN' => "arn:aws:cloudwatch:eu-west-1:000000000000:metricAlarm:00000000-0000-0000-0000-000000000000:alarmName/#{options['AlarmName']}",
|
||||||
|
'ActionsEnabled' => false,
|
||||||
|
'AlarmActions' => [],
|
||||||
|
'AlarmConfigurationUpdatedTimestamp' => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
|
||||||
|
'Dimensions' => [],
|
||||||
|
'OKActions' => [],
|
||||||
|
}.merge!(options)
|
||||||
|
|
||||||
response = Excon::Response.new
|
response = Excon::Response.new
|
||||||
response.status = 200
|
response.status = 200
|
||||||
response.body = {
|
response.body = {
|
||||||
|
|
|
@ -3,8 +3,6 @@ Shindo.tests('AWS::AutoScaling | auto_scaling_tests', ['aws', 'auto_scaling']) d
|
||||||
@lc_name = 'fog-test-lc'
|
@lc_name = 'fog-test-lc'
|
||||||
|
|
||||||
tests('success') do
|
tests('success') do
|
||||||
pending if Fog.mocking?
|
|
||||||
|
|
||||||
tests("#describe_adjustment_types").formats(AWS::AutoScaling::Formats::DESCRIBE_ADJUSTMENT_TYPES) do
|
tests("#describe_adjustment_types").formats(AWS::AutoScaling::Formats::DESCRIBE_ADJUSTMENT_TYPES) do
|
||||||
Fog::AWS[:auto_scaling].describe_adjustment_types.body
|
Fog::AWS[:auto_scaling].describe_adjustment_types.body
|
||||||
end
|
end
|
||||||
|
@ -54,15 +52,19 @@ Shindo.tests('AWS::AutoScaling | auto_scaling_tests', ['aws', 'auto_scaling']) d
|
||||||
end
|
end
|
||||||
|
|
||||||
tests("#describe_scaling_activities").formats(AWS::AutoScaling::Formats::DESCRIBE_SCALING_ACTIVITIES) do
|
tests("#describe_scaling_activities").formats(AWS::AutoScaling::Formats::DESCRIBE_SCALING_ACTIVITIES) do
|
||||||
|
pending if Fog.mocking?
|
||||||
Fog::AWS[:auto_scaling].describe_scaling_activities().body
|
Fog::AWS[:auto_scaling].describe_scaling_activities().body
|
||||||
end
|
end
|
||||||
tests("#describe_scaling_activities").formats(AWS::AutoScaling::Formats::DESCRIBE_SCALING_ACTIVITIES) do
|
tests("#describe_scaling_activities").formats(AWS::AutoScaling::Formats::DESCRIBE_SCALING_ACTIVITIES) do
|
||||||
|
pending if Fog.mocking?
|
||||||
Fog::AWS[:auto_scaling].describe_scaling_activities('ActivityIds' => '1').body
|
Fog::AWS[:auto_scaling].describe_scaling_activities('ActivityIds' => '1').body
|
||||||
end
|
end
|
||||||
tests("#describe_scaling_activities").formats(AWS::AutoScaling::Formats::DESCRIBE_SCALING_ACTIVITIES) do
|
tests("#describe_scaling_activities").formats(AWS::AutoScaling::Formats::DESCRIBE_SCALING_ACTIVITIES) do
|
||||||
|
pending if Fog.mocking?
|
||||||
Fog::AWS[:auto_scaling].describe_scaling_activities('ActivityIds' => ['1', '2']).body
|
Fog::AWS[:auto_scaling].describe_scaling_activities('ActivityIds' => ['1', '2']).body
|
||||||
end
|
end
|
||||||
tests("#describe_scaling_activities").formats(AWS::AutoScaling::Formats::DESCRIBE_SCALING_ACTIVITIES) do
|
tests("#describe_scaling_activities").formats(AWS::AutoScaling::Formats::DESCRIBE_SCALING_ACTIVITIES) do
|
||||||
|
pending if Fog.mocking?
|
||||||
Fog::AWS[:auto_scaling].describe_scaling_activities('AutoScalingGroupName' => @asg_name).body
|
Fog::AWS[:auto_scaling].describe_scaling_activities('AutoScalingGroupName' => @asg_name).body
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue