1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[aws|auto_scaling] implement 2010-08-01 API

This commit is contained in:
Nick Osborn 2011-06-12 21:07:42 +01:00
parent 7402e8b04b
commit 9afb8c8460
56 changed files with 3648 additions and 0 deletions

225
lib/fog/aws/auto_scaling.rb Normal file
View file

@ -0,0 +1,225 @@
module Fog
module AWS
class AutoScaling < Fog::Service
class IdentifierTaken < Fog::Errors::Error; end
class ResourceInUse < Fog::Errors::Error; end
class ValidationError < Fog::Errors::Error; end
requires :aws_access_key_id, :aws_secret_access_key
recognizes :host, :path, :port, :scheme, :persistent, :region
request_path 'fog/aws/requests/auto_scaling'
request :create_auto_scaling_group
request :create_launch_configuration
request :delete_auto_scaling_group
request :delete_launch_configuration
request :delete_policy
request :delete_scheduled_action
request :describe_adjustment_types
request :describe_auto_scaling_groups
request :describe_auto_scaling_instances
request :describe_launch_configurations
request :describe_metric_collection_types
request :describe_policies
request :describe_scaling_activities
request :describe_scaling_process_types
request :describe_scheduled_actions
request :disable_metrics_collection
request :enable_metrics_collection
request :execute_policy
request :put_scaling_policy
request :put_scheduled_update_group_action
request :resume_processes
request :set_desired_capacity
request :set_instance_health
request :suspend_processes
request :terminate_instance_in_auto_scaling_group
request :update_auto_scaling_group
model_path 'fog/aws/models/auto_scaling'
model :activity
collection :activities
model :adjustment_type
collection :adjustment_types
model :configuration
collection :configurations
model :group
collection :groups
model :instance
collection :instances
model :process_type
collection :process_types
class Real
# Initialize connection to AutoScaling
#
# ==== Notes
# options parameter must include values for :aws_access_key_id and
# :aws_secret_access_key in order to create a connection
#
# ==== Examples
# as = AutoScaling.new(
# :aws_access_key_id => your_aws_access_key_id,
# :aws_secret_access_key => your_aws_secret_access_key
# )
#
# ==== Parameters
# * options<~Hash> - config arguments for connection. Defaults to {}.
#
# ==== Returns
# * AutoScaling object with connection to AWS.
def initialize(options={})
require 'fog/core/parser'
@aws_access_key_id = options[:aws_access_key_id]
@aws_secret_access_key = options[:aws_secret_access_key]
@hmac = Fog::HMAC.new('sha256', @aws_secret_access_key)
options[:region] ||= 'us-east-1'
@host = options[:host] || case options[:region]
when 'ap-northeast-1'
'autoscaling.ap-northeast-1.amazonaws.com'
when 'ap-southeast-1'
'autoscaling.ap-southeast-1.amazonaws.com'
when 'eu-west-1'
'autoscaling.eu-west-1.amazonaws.com'
when 'us-east-1'
'autoscaling.us-east-1.amazonaws.com'
when 'us-west-1'
'autoscaling.us-west-1.amazonaws.com'
else
raise ArgumentError, "Unknown region: #{options[:region].inspect}"
end
@path = options[:path] || '/'
@port = options[:port] || 443
@scheme = options[:scheme] || 'https'
@connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", options[:persistent])
end
def reload
@connection.reset
end
private
def request(params)
idempotent = params.delete(:idempotent)
parser = params.delete(:parser)
body = AWS.signed_params(
params,
{
:aws_access_key_id => @aws_access_key_id,
:hmac => @hmac,
:host => @host,
:path => @path,
:port => @port,
:version => '2010-08-01'
}
)
begin
response = @connection.request({
:body => body,
:expects => 200,
:idempotent => idempotent,
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded' },
:host => @host,
:method => 'POST',
:parser => parser
})
rescue Excon::Errors::HTTPStatusError => error
if match = error.message.match(/<Code>(.*)<\/Code>.*<Message>(.*)<\/Message>/)
case match[1]
when 'AlreadyExists'
#raise Fog::AWS::AutoScaling::IdentifierTaken.new(match[2])
raise Fog::AWS::AutoScaling::IdentifierTaken.slurp(error, match[2])
when 'ResourceInUse'
raise Fog::AWS::AutoScaling::ResourceInUse.slurp(error, match[2])
when 'ValidationError'
raise Fog::AWS::AutoScaling::ValidationError.slurp(error, match[2])
else
raise Fog::AWS::Compute::Error.slurp(error, "#{match[1]} => #{match[2]}")
end
else
raise
end
end
response
end
end
class Mock
def self.data
@data ||= Hash.new do |hash, region|
owner_id = Fog::AWS::Mock.owner_id
hash[region] = Hash.new do |region_hash, key|
region_hash[key] = {
:adjustment_types => [
'ChangeInCapacity',
'ExactCapacity',
'PercentChangeInCapacity'
],
:auto_scaling_groups => {},
:health_states => ['Healthy', 'Unhealthy'],
:launch_configurations => {},
:metric_collection_types => {
:granularities => [ '1Minute' ],
:metrics => [
'GroupMinSize',
'GroupMaxSize',
'GroupDesiredCapacity',
'GroupInServiceInstances',
'GroupPendingInstances',
'GroupTerminatingInstances',
'GroupTotalInstances'
],
},
:process_types => [
'AZRebalance',
'AlarmNotification',
'HealthCheck',
'Launch',
'ReplaceUnhealthy',
'ScheduledActions',
'Terminate'
]
}
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', 'us-east-1', 'us-west-1'].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
end
end

View file

@ -0,0 +1,28 @@
require 'fog/aws/models/auto_scaling/activity'
module Fog
module AWS
class AutoScaling
class Activities < Fog::Collection
model Fog::AWS::AutoScaling::Activity
def all
data = []
next_token = nil
loop do
result = connection.describe_scaling_activities('NextToken' => next_token).body['DescribeScalingActivitiesResult']
data += result['Activities']
next_token = result['NextToken']
break if next_token.nil?
end
load(data)
end
def get(identity)
data = connection.describe_scaling_activities('ActivityId' => identity).body['DescribeScalingActivitiesResult']['Activities'].first
new(data) unless data.nil?
end
end
end
end
end

View file

@ -0,0 +1,25 @@
require 'fog/core/model'
module Fog
module AWS
class AutoScaling
class Activity < Fog::Model
identity :id, :aliases => 'ActivityId'
attribute :auto_scaling_group_name, :aliases => 'AutoScalingGroupName'
attribute :cause, :aliases => 'Cause'
attribute :description, :aliases => 'Description'
attribute :end_time, :aliases => 'EndTime'
attribute :progress, :aliases => 'Progress'
attribute :start_time, :aliases => 'StartTime'
attribute :status_code, :aliases => 'StatusCode'
attribute :status_message, :aliases => 'StatusMessage'
def group
connection.groups.get(attributes['AutoScalingGroupName'])
end
end
end
end
end

View file

@ -0,0 +1,13 @@
require 'fog/core/model'
module Fog
module AWS
class AutoScaling
class AdjustmentType < Fog::Model
identity :id, :aliases => 'AdjustmentType'
end
end
end
end

View file

@ -0,0 +1,15 @@
require 'fog/aws/models/auto_scaling/adjustment_type'
module Fog
module AWS
class AutoScaling
class AdjustmentTypes < Fog::Collection
model Fog::AWS::AutoScaling::AdjustmentType
def all
data = connection.describe_adjustment_types.body['DescribeAdjustmentTypesResult']['AdjustmentTypes']
load(data)
end
end
end
end
end

View file

@ -0,0 +1,63 @@
require 'fog/core/model'
module Fog
module AWS
class AutoScaling
class Configuration < Fog::Model
identity :id, :aliases => 'LaunchConfigurationName'
attribute :arn, :aliases => 'LaunchConfigurationARN'
attribute :block_device_mappings, :aliases => 'BlockDeviceMappings'
attribute :created_at, :aliases => 'CreatedTime'
attribute :image_id, :aliases => 'ImageId'
#attribute :instance_monitoring, :aliases => 'InstanceMonitoring'
attribute :instance_monitoring, :aliases => 'InstanceMonitoring', :squash => 'Enabled'
attribute :instance_type, :aliases => 'InstanceType'
attribute :kernel_id, :aliases => 'KernelId'
attribute :key_name, :aliases => 'KeyName'
attribute :ramdisk_id, :aliases => 'RamdiskId'
attribute :security_groups, :aliases => 'SecurityGroups'
attribute :user_data, :aliases => 'UserData'
def initialize(attributes={})
#attributes[:availability_zones] ||= %w(us-east-1a us-east-1b us-east-1c us-east-1d)
#attributes['ListenerDescriptions'] ||= [{
# 'Listener' => {'LoadBalancerPort' => 80, 'InstancePort' => 80, 'Protocol' => 'http'},
# 'PolicyNames' => []
#}]
#attributes['Policies'] ||= {'AppCookieStickinessPolicies' => [], 'LBCookieStickinessPolicies' => []}
super
end
def ready?
# AutoScaling requests are synchronous
true
end
def save
requires :id
requires :image_id
requires :instance_type
connection.create_launch_configuration(image_id, instance_type, id) #, listeners.map{|l| l.to_params})
# 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
# API call
reload
end
def reload
super
self
end
def destroy
requires :id
connection.delete_launch_configuration(id)
end
end
end
end
end

View file

@ -0,0 +1,33 @@
require 'fog/aws/models/auto_scaling/configuration'
module Fog
module AWS
class AutoScaling
class Configurations < Fog::Collection
model Fog::AWS::AutoScaling::Configuration
# Creates a new launch configuration
def initialize(attributes={})
super
end
def all
data = []
next_token = nil
loop do
result = connection.describe_launch_configurations('NextToken' => next_token).body['DescribeLaunchConfigurationsResult']
data += result['LaunchConfigurations']
next_token = result['NextToken']
break if next_token.nil?
end
load(data)
end
def get(identity)
data = connection.describe_launch_configurations('LaunchConfigurationNames' => identity).body['DescribeLaunchConfigurationsResult']['LaunchConfigurations'].first
new(data) unless data.nil?
end
end
end
end
end

View file

@ -0,0 +1,106 @@
require 'fog/core/model'
module Fog
module AWS
class AutoScaling
class Group < Fog::Model
identity :id, :aliases => 'AutoScalingGroupName'
attribute :arn, :aliases => 'AutoScalingGroupARN'
attribute :availability_zones, :aliases => 'AvailabilityZones'
attribute :created_at, :aliases => 'CreatedTime'
attribute :default_cooldown, :aliases => 'DefaultCooldown'
attribute :desired_capacity, :aliases => 'DesiredCapacity'
attribute :enabled_metrics, :aliases => 'EnabledMetrics'
attribute :health_check_grace_period, :aliases => 'HealthCheckGracePeriod'
attribute :health_check_type, :aliases => 'HealthCheckType'
attribute :instances, :aliases => 'Instances'
attribute :launch_configuration_name, :aliases => 'LaunchConfigurationName'
attribute :load_balancer_names, :aliases => 'LoadBalancerNames'
attribute :max_size, :aliases => 'MaxSize'
attribute :min_size, :aliases => 'MinSize'
attribute :placement_group, :aliases => 'PlacementGroup'
attribute :suspended_processes, :aliases => 'SuspendedProcesses'
attribute :vpc_zone_identifier, :aliases => 'VPCZoneIdentifier'
def initialize(attributes={})
attributes['DefaultCooldown'] ||= 0
attributes['DesiredCapacity'] ||= 0
attributes['EnabledMetrics'] ||= []
attributes['HealthCheckGracePeriod'] ||= 0
attributes['HealthCheckType'] ||= 'EC2'
attributes['Instances'] ||= []
attributes['LoadBalancerNames'] ||= []
attributes['MaxSize'] ||= 0
attributes['MinSize'] ||= 0
attributes['SuspendedProcesses'] ||= []
super
end
def configuration
connection.configurations.get(attributes['LaunchConfigurationName'])
end
def disable_metrics_collection(metrics = {})
requires :id
connection.disable_metrics_collection(id, 'Metrics' => metrics)
reload
end
def enable_metrics_collection(metrics = {})
requires :id
connection.enable_metrics_collection(id, 'Metrics' => metrics)
reload
end
def resume_processes(processes = [])
requires :id
connection.resume_processes(id, 'ScalingProcesses' => processes)
reload
end
def suspend_processes(processes = [])
requires :id
connection.suspend_processes(id, 'ScalingProcesses' => processes)
reload
end
def ready?
# AutoScaling requests are synchronous
true
end
def save
requires :id
requires :availability_zones
requires :launch_configuration_name
requires :max_size
requires :min_size
connection.create_auto_scaling_group(id, availability_zones, launch_configuration_name, max_size, min_size)
reload
end
def reload
super
# @instance_health = nil
self
end
def destroy
requires :id
connection.delete_auto_scaling_group(id)
end
private
def update(options)
requires :id
connection.update_auto_scaling_group(id, options)
reload
end
end
end
end
end

View file

@ -0,0 +1,32 @@
require 'fog/aws/models/auto_scaling/group'
module Fog
module AWS
class AutoScaling
class Groups < Fog::Collection
model Fog::AWS::AutoScaling::Group
# Creates a new auto scaling group.
def initialize(attributes={})
super
end
def all
data = []
next_token = nil
loop do
result = connection.describe_auto_scaling_groups('NextToken' => next_token).body['DescribeAutoScalingGroupsResult']
data += result['AutoScalingGroups']
next_token = result['NextToken']
break if next_token.nil?
end
load(data)
end
def get(identity)
data = connection.describe_auto_scaling_groups('AutoScalingGroupNames' => identity).body['DescribeAutoScalingGroupsResult']['AutoScalingGroups'].first
new(data) unless data.nil?
end
end
end
end
end

View file

@ -0,0 +1,60 @@
require 'fog/core/model'
module Fog
module AWS
class AutoScaling
class Instance < Fog::Model
identity :id, :aliases => 'InstanceId'
attribute :auto_scaling_group_name, :aliases => 'AutoScalingGroupName'
attribute :availability_zone, :aliases => 'AvailabilityZone'
attribute :health_status, :aliases => 'HealthStatus'
attribute :launch_configuration_name, :aliases => 'LaunchConfigurationName'
attribute :life_cycle_state, :aliases => 'LifecycleState'
def initialize(attributes={})
super
end
def group
connection.groups.get(attributes['AutoScalingGroupName'])
end
def configuration
connection.configurations.get(attributes['LaunchConfigurationName'])
end
def set_health(health_status, options)
requires :id
connection.set_instance_health(health_status, id, options)
reload
end
def terminate(should_decrement_desired_capacity)
requires :id
connection.terminate_instance_in_auto_scaling_group(id, should_decrement_desired_capacity)
reload
end
def healthy?
health_status == 'HEALTHY'
end
def ready?
life_cycle_state == 'InService'
end
def reload
super
self
end
#def destroy
# requires :id
# connection.delete_auto_scaling_group(id)
#end
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'fog/aws/models/auto_scaling/instance'
module Fog
module AWS
class AutoScaling
class Instances < Fog::Collection
model Fog::AWS::AutoScaling::Instance
def all
data = []
next_token = nil
loop do
result = connection.describe_auto_scaling_instances('NextToken' => next_token).body['DescribeAutoScalingInstancesResult']
data += result['AutoScalingInstances']
next_token = result['NextToken']
break if next_token.nil?
end
load(data)
end
def get(identity)
data = connection.describe_auto_scaling_instances('InstanceIds' => identity).body['DescribeAutoScalingInstancesResult']['AutoScalingInstances'].first
new(data) unless data.nil?
end
end
end
end
end

View file

@ -0,0 +1,13 @@
require 'fog/core/model'
module Fog
module AWS
class AutoScaling
class ProcessType < Fog::Model
identity :id, :aliases => 'ProcessName'
end
end
end
end

View file

@ -0,0 +1,15 @@
require 'fog/aws/models/auto_scaling/process_type'
module Fog
module AWS
class AutoScaling
class ProcessTypes < Fog::Collection
model Fog::AWS::AutoScaling::ProcessType
def all
data = connection.describe_scaling_process_types.body['DescribeScalingProcessTypesResult']['Processes']
load(data)
end
end
end
end
end

View file

@ -0,0 +1,28 @@
module Fog
module Parsers
module AWS
module AutoScaling
class Basic < Fog::Parsers::Base
def reset
@response = { 'ResponseMetadata' => {} }
end
def start_element(name, attrs = [])
super
end
def end_element(name)
case name
when 'RequestId'
@response['ResponseMetadata'][name] = value
end
end
end
end
end
end
end

View file

@ -0,0 +1,39 @@
module Fog
module Parsers
module AWS
module AutoScaling
class DescribeAdjustmentTypes < Fog::Parsers::Base
def reset
reset_adjustment_type
@results = { 'AdjustmentTypes' => [] }
@response = { 'DescribeAdjustmentTypesResult' => {}, 'ResponseMetadata' => {} }
end
def reset_adjustment_type
@adjustment_type = {}
end
def end_element(name)
case name
when 'member'
@results['AdjustmentTypes'] << @adjustment_type
reset_adjustment_type
when 'AdjustmentType'
@adjustment_type[name] = value
when 'RequestId'
@response['ResponseMetadata'][name] = value
when 'DescribeAdjustmentTypesResponse'
@response['DescribeAdjustmentTypesResult'] = @results
end
end
end
end
end
end
end

View file

@ -0,0 +1,126 @@
module Fog
module Parsers
module AWS
module AutoScaling
class DescribeAutoScalingGroups < Fog::Parsers::Base
def reset
reset_auto_scaling_group
reset_enabled_metric
reset_instance
reset_suspended_process
@results = { 'AutoScalingGroups' => [] }
@response = { 'DescribeAutoScalingGroupsResult' => {}, 'ResponseMetadata' => {} }
end
def reset_auto_scaling_group
@auto_scaling_group = { 'AvailabilityZones' => [], 'EnabledMetrics' => [], 'Instances' => [], 'LoadBalancerNames' => [], 'SuspendedProcesses' => [] }
end
def reset_enabled_metric
@enabled_metric = {}
end
def reset_instance
@instance = {}
end
def reset_suspended_process
@suspended_process = {}
end
def start_element(name, attrs = [])
super
case name
when 'AvailabilityZones'
@in_availability_zones = true
when 'EnabledMetrics'
@in_enabled_metrics = true
when 'Instances'
@in_instances = true
when 'LoadBalancerNames'
@in_load_balancer_names = true
when 'SuspendedProcesses'
@in_suspended_processes = true
end
end
def end_element(name)
case name
when 'member'
if @in_availability_zones
@auto_scaling_group['AvailabilityZones'] << value
elsif @in_enabled_metrics
@auto_scaling_group['EnabledMetrics'] << @enabled_metric
reset_enabled_metric
elsif @in_instances
@auto_scaling_group['Instances'] << @instance
reset_instance
elsif @in_load_balancer_names
@auto_scaling_group['LoadBalancerNames'] << value
elsif @in_suspended_processes
@auto_scaling_group['SuspendedProcesses'] << @suspended_process
reset_suspended_process
elsif !@in_instances && !@in_policies
@results['AutoScalingGroups'] << @auto_scaling_group
reset_auto_scaling_group
end
when 'AvailabilityZones'
@in_availability_zones = false
when 'Granularity', 'Metric'
@enabled_metric[name] = value
when 'EnabledMetrics'
@in_enabled_metrics = false
when 'LaunchConfigurationName'
if @in_instances
@instance[name] = value
else
@auto_scaling_group[name] = value
end
when 'AvailabilityZone', 'HealthStatus', 'InstanceId', 'LifecycleState'
@instance[name] = value
when 'Instances'
@in_instances = false
when 'LoadBalancerNames'
@in_load_balancer_names = false
when 'ProcessName', 'SuspensionReason'
@suspended_process[name] = value
when 'SuspendedProcesses'
@in_suspended_processes = false
when 'AutoScalingGroupARN', 'AutoScalingGroupName'
@auto_scaling_group[name] = value
when 'CreatedTime'
@auto_scaling_group[name] = Time.parse(value)
when 'DefaultCooldown', 'DesiredCapacity', 'HealthCheckGracePeriod'
@auto_scaling_group[name] = value.to_i
when 'HealthCheckType'
@auto_scaling_group[name] = value
when 'MaxSize', 'MinSize'
@auto_scaling_group[name] = value.to_i
when 'PlacementGroup', 'VPCZoneIdentifier'
@auto_scaling_group[name] = value
when 'NextToken'
@results[name] = value
when 'RequestId'
@response['ResponseMetadata'][name] = value
when 'DescribeAutoScalingGroupsResponse'
@response['DescribeAutoScalingGroupsResult'] = @results
end
end
end
end
end
end
end

View file

@ -0,0 +1,43 @@
module Fog
module Parsers
module AWS
module AutoScaling
class DescribeAutoScalingInstances < Fog::Parsers::Base
def reset
reset_auto_scaling_instance
@results = { 'AutoScalingInstances' => [] }
@response = { 'DescribeAutoScalingInstancesResult' => {}, 'ResponseMetadata' => {} }
end
def reset_auto_scaling_instance
@auto_scaling_instance = {}
end
def end_element(name)
case name
when 'member'
@results['AutoScalingInstances'] << @auto_scaling_instance
reset_auto_scaling_instance
when 'AutoScalingGroupName', 'AvailabilityZone', 'HealthStatus',
'InstanceId', 'LaunchConfigurationName', 'LifecycleState'
@auto_scaling_instance[name] = value
when 'NextToken'
@results[name] = value
when 'RequestId'
@response['ResponseMetadata'][name] = value
when 'DescribeAutoScalingInstancesResponse'
@response['DescribeAutoScalingInstancesResult'] = @results
end
end
end
end
end
end
end

View file

@ -0,0 +1,94 @@
module Fog
module Parsers
module AWS
module AutoScaling
class DescribeLaunchConfigurations < Fog::Parsers::Base
def reset
reset_launch_configuration
reset_block_device_mapping
reset_ebs
@results = { 'LaunchConfigurations' => [] }
@response = { 'DescribeLaunchConfigurationsResult' => {}, 'ResponseMetadata' => {} }
end
def reset_launch_configuration
@launch_configuration = { 'BlockDeviceMappings' => [], 'InstanceMonitoring' => {}, 'SecurityGroups' => [] }
end
def reset_block_device_mapping
@block_device_mapping = {}
end
def reset_ebs
@ebs = {}
end
def start_element(name, attrs = [])
super
case name
when 'BlockDeviceMappings'
@in_block_device_mappings = true
when 'SecurityGroups'
@in_security_groups = true
end
end
def end_element(name)
case name
when 'member'
if @in_block_device_mappings
@launch_configuration['BlockDeviceMappings'] << @block_device_mapping
reset_block_device_mapping
elsif @in_security_groups
@launch_configuration['SecurityGroups'] << value
else
@results['LaunchConfigurations'] << @launch_configuration
reset_launch_configuration
end
when 'DeviceName', 'VirtualName'
@block_device_mapping[name] = value
when 'SnapshotId', 'VolumeSize'
@ebs[name] = value
when 'Ebs'
@block_device_mapping[name] = @ebs
reset_ebs
when 'Enabled'
@launch_configuration['InstanceMonitoring'][name] = (value == 'true')
when 'CreatedTime'
@launch_configuration[name] = Time.parse(value)
when 'ImageId', 'InstanceType', 'KeyName'
@launch_configuration[name] = value
when 'LaunchConfigurationARN', 'LaunchConfigurationName'
@launch_configuration[name] = value
when 'KernelId', 'RamdiskId', 'UserData'
@launch_configuration[name] = value
when 'BlockDeviceMappings'
@in_block_device_mappings = false
when 'LaunchConfigurations'
@in_launch_configurations = false
when 'SecurityGroups'
@in_security_groups = false
when 'NextToken'
@results[name] = value
when 'RequestId'
@response['ResponseMetadata'][name] = value
when 'DescribeLaunchConfigurationsResponse'
@response['DescribeLaunchConfigurationsResult'] = @results
end
end
end
end
end
end
end

View file

@ -0,0 +1,66 @@
module Fog
module Parsers
module AWS
module AutoScaling
class DescribeMetricCollectionTypes < Fog::Parsers::Base
def reset
reset_granularity
reset_metric
@results = { 'Granularities' => [], 'Metrics' => [] }
@response = { 'DescribeMetricCollectionTypesResult' => {}, 'ResponseMetadata' => {} }
end
def reset_granularity
@granularity = {}
end
def reset_metric
@metric = {}
end
def start_element(name, attrs = [])
super
case name
when 'Granularities'
@in_granularities = true
when 'Metrics'
@in_metrics = true
end
end
def end_element(name)
case name
when 'member'
if @in_granularities
@results['Granularities'] << @granularity
reset_granularity
elsif @in_metrics
@results['Metrics'] << @metric
reset_metric
end
when 'Granularity'
@granularity[name] = value
when 'Granularities'
@in_granularities = false
when 'Metric'
@metric[name] = value
when 'Metrics'
@in_metrics = false
when 'RequestId'
@response['ResponseMetadata'][name] = value
when 'DescribeMetricCollectionTypesResult'
@response[name] = @results
end
end
end
end
end
end
end

View file

@ -0,0 +1,52 @@
module Fog
module Parsers
module AWS
module AutoScaling
class DescribePolicies < Fog::Parsers::Base
def reset
reset_scaling_policy
reset_alarm
@results = { 'ScalingPolicies' => [] }
@response = { 'DescribePoliciesResult' => {}, 'ResponseMetadata' => {} }
end
def reset_scaling_policy
@scaling_policy = { 'Alarms' => [] }
end
def reset_alarm
@alarm = {}
end
def end_element(name)
case name
when 'member'
@scaling_policy['Alarms'] << @alarm
reset_alarm
when 'AlarmARN', 'AlarmName'
@alarm[name] = value
when 'AdjustmentType', 'AutoScalingGroupName', 'PolicyARN', 'PolicyName'
@scaling_policy[name] = value
when 'Cooldown', 'ScalingAdjustment'
@scaling_adjustment[name] = value.to_i
when 'NextToken'
@results[name] = value
when 'RequestId'
@response['ResponseMetadata'][name] = value
when 'DescribePoliciesResponse'
@response['DescribePoliciesResult'] = @results
end
end
end
end
end
end
end

View file

@ -0,0 +1,47 @@
module Fog
module Parsers
module AWS
module AutoScaling
class DescribeScalingActivities < Fog::Parsers::Base
def reset
reset_activity
@results = { 'Activities' => [] }
@response = { 'DescribeScalingActivitiesResult' => {}, 'ResponseMetadata' => {} }
end
def reset_activity
@activity = {}
end
def end_element(name)
case name
when 'member'
@results['Activities'] << @activity
reset_activity
when 'ActivityId', 'AutoScalingGroupName', 'Cause', 'Description',
'StatusCode', 'StatusMessage'
@activity[name] = value
when 'EndTime', 'StartTime'
@activity[name] = Time.parse(value)
when 'Progress'
@activity[name] = value.to_i
when 'NextToken'
@results[name] = value
when 'RequestId'
@response['ResponseMetadata'][name] = value
when 'DescribeScalingActivitiesResponse'
@response['DescribeScalingActivitiesResult'] = @results
end
end
end
end
end
end
end

View file

@ -0,0 +1,39 @@
module Fog
module Parsers
module AWS
module AutoScaling
class DescribeScalingProcessTypes < Fog::Parsers::Base
def reset
reset_process_type
@results = { 'Processes' => [] }
@response = { 'DescribeScalingProcessTypesResult' => {}, 'ResponseMetadata' => {} }
end
def reset_process_type
@process_type = {}
end
def end_element(name)
case name
when 'member'
@results['Processes'] << @process_type
reset_process_type
when 'ProcessName'
@process_type[name] = value
when 'RequestId'
@response['ResponseMetadata'][name] = value
when 'DescribeScalingProcessTypesResponse'
@response['DescribeScalingProcessTypesResult'] = @results
end
end
end
end
end
end
end

View file

@ -0,0 +1,46 @@
module Fog
module Parsers
module AWS
module AutoScaling
class DescribeScheduledActions < Fog::Parsers::Base
def reset
reset_scheduled_update_group_action
@results = { 'ScheduledUpdateGroupActions' => [] }
@response = { 'DescribeScheduledActionsResult' => {}, 'ResponseMetadata' => {} }
end
def reset_scheduled_update_group_action
@scheduled_update_group_action = {}
end
def end_element(name)
case name
when 'member'
@results['ScheduledUpdateGroupActions'] << @scheduled_update_group_action
reset_scheduled_update_group_action
when 'AutoScalingGroupName', 'ScheduledActionARN', 'ScheduledActionName'
@activity[name] = value
when 'DesiredCapacity', 'MaxSize', 'MinSize'
@scheduled_update_group_action[name] = value.to_i
when 'Time'
@scheduled_update_group_action[name] = Time.parse(value)
when 'NextToken'
@results[name] = value
when 'RequestId'
@response['ResponseMetadata'][name] = value
when 'DescribeScheduledActionsResponse'
@response['DescribeScheduledActionsResult'] = @results
end
end
end
end
end
end
end

View file

@ -0,0 +1,30 @@
module Fog
module Parsers
module AWS
module AutoScaling
class PutScalingPolicy < Fog::Parsers::Base
def reset
@results = {}
@response = { 'PutScalingPolicyResult' => {}, 'ResponseMetadata' => {} }
end
def end_element(name)
case name
when 'PolicyARN'
@results[name] = value
when 'RequestId'
@response['ResponseMetadata'][name] = value
when 'PutScalingPolicyResponse'
@response['PutScalingPolicyResult'] = @results
end
end
end
end
end
end
end

View file

@ -0,0 +1,35 @@
module Fog
module Parsers
module AWS
module AutoScaling
class TerminateInstanceInAutoScalingGroup < Fog::Parsers::Base
def reset
@results = { 'Activity' => {} }
@response = { 'TerminateInstanceInAutoScalingGroupResult' => {}, 'ResponseMetadata' => {} }
end
def end_element(name)
case name
when 'ActivityId', 'AutoScalingGroupName', 'Cause',
'Description', 'StatusCode', 'StatusMessage'
@results['Activity'][name] = value
when 'EndTime', 'StartTime'
@results['Activity'][name] = Time.parse(value)
when 'Progress'
@results['Activity'][name] = value.to_i
when 'RequestId'
@response['ResponseMetadata'][name] = value
when 'TerminateInstanceInAutoScalingGroupResponse'
@response['TerminateInstanceInAutoScalingGroupResult'] = @results
end
end
end
end
end
end
end

View file

@ -0,0 +1,108 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/basic'
# Creates a new Auto Scaling group with the specified name. Once the
# creation request is completed, the AutoScalingGroup is ready to be
# used in other calls.
#
# ==== Parameters
# * auto_scaling_group_name<~String> - The name of the Auto Scaling
# group.
# * availability_zones<~Array> - A list of availability zones for the
# Auto Scaling group.
# * launch_configuration_name<~String> - The name of the launch
# configuration to use with the Auto Scaling group.
# * max_size<~Integer> - The maximum size of the Auto Scaling group.
# * min_size<~Integer> - The minimum size of the Auto Scaling group.
# * options<~Hash>:
# * 'DefaultCooldown'<~Integer> - The amount of time, in seconds,
# after a scaling activity completes before any further trigger-
# related scaling activities can start.
# * 'DesiredCapacity'<~Integer> - The number of EC2 instances that
# should be running in the group. For more information, see
# set_desired_capacity.
# * 'HealthCheckGracePeriod'<~Integer> - Length of time in seconds
# after a new EC2 instance comes into service that Auto Scaling
# starts checking its health.
# * 'HealthCheckType'<~String> - The service you want the health
# status from, Amazon EC2 or Elastic Load Balancer. Valid values
# are "EC2" or "ELB".
# * 'LoadBalancerNames'<~Array> - A list of LoadBalancers to use.
# * 'PlacementGroup'<~String> - Physical location of your cluster
# placement group created in Amazon EC2.
# * 'VPCZoneIdentifier'<~String> - Subnet identifier of the Virtual
# Private Cloud.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_CreateAutoScalingGroup.html
#
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]))
if load_balancer_names = options.delete('LoadBalancerNames')
options.merge!(AWS.indexed_param('LoadBalancerNames.member.%d', [*load_balancer_names]))
end
request({
'Action' => 'CreateAutoScalingGroup',
'AutoScalingGroupName' => auto_scaling_group_name,
'LaunchConfigurationName' => launch_configuration_name,
'MaxSize' => max_size,
'MinSize' => min_size,
:parser => Fog::Parsers::AWS::AutoScaling::Basic.new
}.merge!(options))
end
end
class Mock
def create_auto_scaling_group(auto_scaling_group_name, availability_zones, launch_configuration_name, max_size, min_size, options = {})
if data[:auto_scaling_groups].has_key?(auto_scaling_group_name)
raise Fog::AWS::AutoScaling::IdentifierTaken.new("AutoScalingGroup by this name already exists - A group with the name #{auto_scaling_group_name} already exists")
end
unless data[:launch_configurations].has_key?(launch_configuration_name)
raise Fog::AWS::AutoScaling::ValidationError.new('Launch configuration name not found - null')
end
data[:auto_scaling_groups][auto_scaling_group_name] = {
'AutoScalingGroupARN' => "arn:aws:autoscaling:eu-west-1:000000000000:autoScalingGroup:00000000-0000-0000-0000-000000000000:autoScalingGroupName/#{auto_scaling_group_name}",
'AutoScalingGroupName' => launch_configuration_name,
'AvailabilityZones' => availability_zones.to_a,
'CreatedTime' => Time.now.utc,
'DefaultCooldown' => 0,
'DesiredCapacity' => 0,
'EnabledMetrics' => [],
'HealthCheckGracePeriod' => 0,
'HealthCheckType' => 'EC2',
'Instances' => [],
'LaunchConfigurationName' => launch_configuration_name,
'LoadBalancerNames' => [],
'MaxSize' => max_size,
'MinSize' => min_size,
'PlacementGroup' => nil,
'SuspendedProcesses' => [],
'VPCZoneIdentifier' => nil
}.merge!(options)
response = Excon::Response.new
response.status = 200
response.body = {
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
}
response
end
end
end
end
end

View file

@ -0,0 +1,105 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/basic'
# Creates a new launch configuration. Once created, the new launch
# configuration is available for immediate use.
#
# ==== Parameters
# * image_id<~String> - Unique ID of the Amazon Machine Image (AMI)
# which was assigned during registration.
# * instance_type<~String> - The instance type of the EC2 instance.
# * launch_configuration_name<~String> - The name of the launch
# configuration to create.
# * options<~Hash>:
# * 'BlockDeviceMappings'<~Array>:
# * 'DeviceName'<~String> - The name of the device within Amazon
# EC2.
# * 'Ebs.SnapshotId'<~String> - The snapshot ID.
# * 'Ebs.VolumeSize'<~Integer> - The volume size, in GigaBytes.
# * 'VirtualName'<~String> - The virtual name associated with the
# device.
# * 'InstanceMonitoring'<~Hash>:
# * 'Enabled'<~Boolean> - Enabled detailed monitoring.
# * 'KernelId'<~String> - The ID of the kernel associated with the
# EC2 AMI.
# * 'KeyName'<~String> - The name of the EC2 key pair.
# * 'RamdiskId'<~String> - The ID of the RAM disk associated with the
# EC2 AMI.
# * 'SecurityGroups'<~Array> - The names of the security groups with
# which to associate EC2 instances.
# * 'UserData'<~String> - User data available to the launched EC2
# instances.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_CreateLaunchConfiguration.html
#
def create_launch_configuration(image_id, instance_type, launch_configuration_name, options = {})
if block_device_mappings = options.delete('BlockDeviceMappings')
block_device_mappings.each_with_index do |mapping, i|
for key, value in mapping
options.merge!({ format("BlockDeviceMappings.member.%d.#{key}", i+1) => value })
end
end
end
if security_groups = options.delete('SecurityGroups')
options.merge!(AWS.indexed_param('SecurityGroups.member.%d', [*security_groups]))
end
if options['UserData']
options['UserData'] = Base64.encode64(options['UserData'])
end
request({
'Action' => 'CreateLaunchConfiguration',
'ImageId' => image_id,
'InstanceType' => instance_type,
'LaunchConfigurationName' => launch_configuration_name,
:parser => Fog::Parsers::AWS::AutoScaling::Basic.new
}.merge!(options))
end
end
class Mock
def create_launch_configuration(image_id, instance_type, launch_configuration_name, options = {})
if data[:launch_configurations].has_key?(launch_configuration_name)
raise Fog::AWS::AutoScaling::IdentifierTaken.new("Launch Configuration by this name already exists - A launch configuration already exists with the name #{launch_configuration_name}")
end
data[:launch_configurations][launch_configuration_name] = {
'BlockDeviceMappings' => [],
'CreatedTime' => Time.now.utc,
'ImageId' => image_id,
'InstanceMonitoring' => { 'Enabled' => true },
'InstanceType' => instance_type,
'KernelId' => nil,
'KeyName' => nil,
'LaunchConfigurationARN' => "arn:aws:autoscaling:eu-west-1:000000000000:launchConfiguration:00000000-0000-0000-0000-000000000000:launchConfigurationName/#{launch_configuration_name}",
'LaunchConfigurationName' => launch_configuration_name,
'RamdiskId' => nil,
'SecurityGroups' => [],
'UserData' => nil
}.merge!(options)
response = Excon::Response.new
response.status = 200
response.body = {
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
}
response
end
end
end
end
end

View file

@ -0,0 +1,45 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/basic'
# Deletes the specified auto scaling group if the group has no
# instances and no scaling activities in progress.
#
# ==== Parameters
# * auto_scaling_group_name<~String> - The name of the Auto Scaling
# group.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_DeleteAutoScalingGroup.html
#
def delete_auto_scaling_group(auto_scaling_group_name)
request({
'Action' => 'DeleteAutoScalingGroup',
'AutoScalingGroupName' => auto_scaling_group_name,
:parser => Fog::Parsers::AWS::AutoScaling::Basic.new
})
end
end
class Mock
def delete_auto_scaling_group(auto_scaling_group_name)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,48 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/basic'
# Deletes the specified launch configuration.
#
# The specified launch configuration must not be attached to an Auto
# Scaling group. Once this call completes, the launch configuration is
# no longer available for use.
#
# ==== Parameters
# * launch_configuration_name<~String> - The name of the launch
# configuration.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_DeleteLaunchConfiguration.html
#
def delete_launch_configuration(launch_configuration_name)
request({
'Action' => 'DeleteLaunchConfiguration',
'LaunchConfigurationName' => launch_configuration_name,
:parser => Fog::Parsers::AWS::AutoScaling::Basic.new
})
end
end
class Mock
def delete_launch_configuration(launch_configuration_name)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,47 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/basic'
# Deletes a policy created by put_scaling_policy
#
# ==== Parameters
# * auto_scaling_group_name<~String> - The name of the Auto Scaling
# group.
# * policy_name<~String> - The name or PolicyARN of the policy you want
# to delete.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_DeletePolicy.html
#
def delete_policy(auto_scaling_group_name, policy_name)
request({
'Action' => 'DeletePolicy',
'AutoScalingGroupName' => auto_scaling_group_name,
'PolicyName' => policy_name,
:parser => Fog::Parsers::AWS::AutoScaling::Basic.new
}.merge!(options))
end
end
class Mock
def delete_policy(auto_scaling_group_name, policy_name)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,48 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/basic'
# Deletes a scheduled action previously created using the
# put_scheduled_update_group_action.
#
# ==== Parameters
# * auto_scaling_group_name<~String> - The name of the Auto Scaling
# group.
# * scheduled_action_name<~String> - The name of the action you want to
# delete.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_DeleteScheduledAction.html
#
def delete_scheduled_action(auto_scaling_group_name, scheduled_action_name)
request({
'Action' => 'DeleteScheduledAction',
'AutoScalingGroupName' => auto_scaling_group_name,
'ScheduledActionName' => scheduled_action_name,
:parser => Fog::Parsers::AWS::AutoScaling::Basic.new
})
end
end
class Mock
def delete_scheduled_action(auto_scaling_group_name, scheduled_action_name)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,52 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/describe_adjustment_types'
# Returns policy adjustment types for use in the put_scaling_policy
# action.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
# * 'DescribeAdjustmentTypesResponse'<~Hash>:
# * 'AdjustmentTypes'<~Array>:
# * 'AdjustmentType'<~String> - A policy adjustment type.
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_DescribeAdjustmentTypes.html
#
def describe_adjustment_types()
request({
'Action' => 'DescribeAdjustmentTypes',
:parser => Fog::Parsers::AWS::AutoScaling::DescribeAdjustmentTypes.new
})
end
end
class Mock
def describe_adjustment_types()
results = { 'AdjustmentTypes' => [] }
data[:adjustment_types].each do |adjustment_type|
results['AdjustmentTypes'] << { 'AdjustmentType' => adjustment_type }
end
response = Excon::Response.new
response.status = 200
response.body = {
'DescribeAdjustmentTypesResult' => results,
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
}
response
end
end
end
end
end

View file

@ -0,0 +1,128 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/describe_auto_scaling_groups'
# Returns a full description of each Auto Scaling group in the given
# list. This includes all Amazon EC2 instances that are members of the
# group. If a list of names is not provided, the service returns the
# full details of all Auto Scaling groups.
#
# This action supports pagination by returning a token if there are
# more pages to retrieve. To get the next page, call this action again
# with the returned token as the NextToken parameter.
#
# ==== Parameters
# * options<~Hash>:
# * 'AutoScalingGroupNames'<~Array> - A list of Auto Scaling group
# names.
# * 'MaxRecords'<~Integer> - The maximum number of records to return.
# * 'NextToken'<~String> - The token returned by a previous call to
# indicate that there is more data available.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
# * 'DescribeAutoScalingGroupsResponse'<~Hash>:
# * 'AutoScalingGroups'<~Array>:
# * 'AutoScalingGroup'<~Hash>:
# * 'AutoScalingGroupARN'<~String> - The Amazon Resource Name
# (ARN) of the Auto Scaling group.
# * 'AutoScalingGroupName'<~String> - Specifies the name of
# the group.
# * 'AvailabilityZones'<~Array> - Contains a list of
# availability zones for the group.
# * 'CreatedTime'<~Time> - Specifies the date and time the
# Auto Scaling group was created.
# * 'DefaultCooldown'<~Integer> - The umber of seconds after
# a scaling activity completes before any further scaling
# activities can start.
# * 'DesiredCapacity'<~Integer> - Specifies the desired
# capacity of the AutoScalingGroup.
# * 'EnabledMetrics'<~Array>:
# * enabledmetric<~Hash>:
# * 'Granularity'<~String> - The granularity of the
# enabled metric.
# * 'Metrics'<~String> - The name of the enabled metric.
# * 'HealthCheckGracePeriod'<~Integer>: The length of time
# that Auto Scaling waits before checking an instance's
# health status. The grace period begins when an instance
# comes into service.
# * 'HealthCheckType'<~String>: The service of interest for
# the health status check, either "EC2" for Amazon EC2 or
# "ELB" for Elastic Load Balancing.
# * 'Instances'<~Array>:
# * instance<~Hash>:
# * 'AvailabilityZone'<~String>: Availability zone
# associated with this instance.
# * 'HealthStatus'<~String>: The instance's health
# status.
# * 'InstanceId'<~String>: Specifies the EC2 instance ID.
# * 'LaunchConfigurationName'<~String>: The launch
# configuration associated with this instance.
# * 'LifecycleState'<~String>: Contains a description of
# the current lifecycle state.
# * 'LaunchConfigurationName'<~String> - Specifies the name
# of the associated launch configuration.
# * 'LoadBalancerNames'<~Array> - A list of load balancers
# associated with this Auto Scaling group.
# * 'MaxSize'<~Integer> - The maximum size of the group.
# * 'MinSize'<~Integer> - The minimum size of the group.
# * 'PlacementGroup'<~String> - The name of the cluster
# placement group, if applicable.
# * 'SuspendedProcesses'<~Array>:
# * suspendedprocess'<~Hash>:
# * 'ProcessName'<~String> - The name of the suspended
# process.
# * 'SuspensionReason'<~String> - The reason that the
# process was suspended.
# * 'VPCZoneIdentifier'<~String> - The identifier for the VPC
# connection, if applicable.
# * 'NextToken'<~String> - Acts as a paging mechanism for large
# result sets. Set to a non-empty string if there are
# additional results waiting to be returned. Pass this in to
# subsequent calls to return additional results.
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_DescribeAutoScalingGroups.html
#
def describe_auto_scaling_groups(options = {})
if auto_scaling_group_names = options.delete('AutoScalingGroupNames')
options.merge!(AWS.indexed_param('AutoScalingGroupNames.member.%d', [*auto_scaling_group_names]))
end
request({
'Action' => 'DescribeAutoScalingGroups',
:parser => Fog::Parsers::AWS::AutoScaling::DescribeAutoScalingGroups.new
}.merge!(options))
end
end
class Mock
def describe_auto_scaling_groups(options = {})
results = { 'AutoScalingGroups' => [] }
data[:auto_scaling_groups].each do |asg_name, asg_data|
results['AutoScalingGroups'] << {
'AutoScalingGroupName' => asg_name
}.merge!(asg_data)
end
response = Excon::Response.new
response.status = 200
response.body = {
'DescribeAutoScalingGroupsResult' => results,
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
}
response
end
end
end
end
end

View file

@ -0,0 +1,96 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/describe_auto_scaling_instances'
# Returns a description of each Auto Scaling instance in the
# instance_ids list. If a list is not provided, the service returns the
# full details of all instances.
#
# This action supports pagination by returning a token if there are
# more pages to retrieve. To get the next page, call this action again
# with the returned token as the NextToken parameter.
#
# ==== Parameters
# * options<~Hash>:
# * 'InstanceIds'<~Array> - The list of Auto Scaling instances to
# describe. If this list is omitted, all auto scaling instances are
# described. The list of requested instances cannot contain more
# than 50 items. If unknown instances are requested, they are
# ignored with no error.
# * 'MaxRecords'<~Integer> - The aximum number of Auto Scaling
# instances to be described with each call.
# * 'NextToken'<~String> - The token returned by a previous call to
# indicate that there is more data available.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
# * 'DescribeAutoScalingInstancesResponse'<~Hash>:
# * 'AutoScalingInstances'<~Array>:
# * autoscalinginstancedetails<~Hash>:
# * 'AutoScalingGroupName'<~String> - The name of the Auto
# Scaling Group associated with this instance.
# * 'AvailabilityZone'<~String> - The availability zone in
# which this instance resides.
# * 'HealthStatus'<~String> - The health status of this
# instance. "Healthy" means that the instance is healthy
# and should remain in service. "Unhealthy" means that the
# instance is unhealthy. Auto Scaling should terminate and
# replace it.
# * 'InstanceId'<~String> - The instance's EC2 instance ID.
# * 'LaunchConfigurationName'<~String> - The launch
# configuration associated with this instance.
# * 'LifecycleState'<~String> - The life cycle state of this
# instance.
# * 'NextToken'<~String> - Acts as a paging mechanism for large
# result sets. Set to a non-empty string if there are
# additional results waiting to be returned. Pass this in to
# subsequent calls to return additional results.
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_DescribeAutoScalingInstances.html
#
def describe_auto_scaling_instances(options = {})
if instance_ids = options.delete('InstanceIds')
options.merge!(AWS.indexed_param('InstanceIds.member.%d', [*instance_ids]))
end
request({
'Action' => 'DescribeAutoScalingInstances',
:parser => Fog::Parsers::AWS::AutoScaling::DescribeAutoScalingInstances.new
}.merge!(options))
end
end
class Mock
def describe_auto_scaling_instances(options = {})
results = { 'AutoScalingInstances' => [] }
data[:auto_scaling_groups].each do |asg_name, asg_data|
lc_name = data[asg_data][lc_name]
asg_data['Instances'].each do |instance|
results['AutoScalingInstances'] << {
'AutoScalingGroupName' => asg_name
}.merge!(instance)
end
end
response = Excon::Response.new
response.status = 200
response.body = {
'DescribeAutoScalingInstancesResult' => results,
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
}
response
end
end
end
end
end

View file

@ -0,0 +1,108 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/describe_launch_configurations'
# Returns a full description of the launch configurations given the
# specified names.
#
# If no names are specified, then the full details of all launch
# configurations are returned.
#
# ==== Parameters
# * options<~Hash>:
# * 'LaunchConfigurationNames'<~Array> - A list of launch
# configuration names.
# * 'MaxRecords'<~Integer> - The maximum number of launch
# configurations.
# * 'NextToken'<~String> - The token returned by a previous call to
# indicate that there is more data available.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
# * 'DescribeLaunchConfigurationsResponse'<~Hash>:
# * 'LaunchConfigurations'<~Array>:
# * launchconfiguration'<~Hash>:
# * 'BlockDeviceMappings'<~Array>:
# * blockdevicemapping<~Hash>:
# * 'DeviceName'<~String> - The name of the device within
# EC2.
# * 'Ebs'<~Hash>:
# * 'SnapshotId'<~String> - The snapshot ID
# * 'VolumeSize'<~Integer> - The volume size, in
# GigaBytes.
# * 'VirtualName'<~String> - The virtual name associated
# with the device.
# * 'CreatedTime'<~Time> - Provides the creation date and
# time for this launch configuration.
# * 'ImageId'<~String> - Provides the unique ID of the Amazon
# Machine Image (AMI) that was assigned during
# registration.
# * 'InstanceMonitoring'<~Hash>:
# * 'Enabled'<~Boolean> - If true, instance monitoring is
# enabled.
# * 'InstanceType'<~String> - Specifies the instance type of
# the EC2 instance.
# * 'KernelId'<~String> - Provides the ID of the kernel
# associated with the EC2 AMI.
# * 'KeyName'<~String> - Provides the name of the EC2 key
# pair.
# * 'LaunchConfigurationARN'<~String> - The launch
# configuration's Amazon Resource Name (ARN).
# * 'LaunchConfigurationName'<~String> - Specifies the name
# of the launch configuration.
# * 'RamdiskId'<~String> - Provides ID of the RAM disk
# associated with the EC2 AMI.
# * 'SecurityGroups'<~Array> - A description of the security
# groups to associate with the EC2 instances.
# * 'UserData'<~String> - The user data available to the
# launched EC2 instances.
# * 'NextToken'<~String> - Acts as a paging mechanism for large
# result sets. Set to a non-empty string if there are
# additional results waiting to be returned. Pass this in to
# subsequent calls to return additional results.
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_DescribeLaunchConfigurations.html
#
def describe_launch_configurations(options = {})
if launch_configuration_names = options.delete('LaunchConfigurationNames')
options.merge!(AWS.indexed_param('LaunchConfigurationNames.member.%d', [*launch_configuration_names]))
end
request({
'Action' => 'DescribeLaunchConfigurations',
:parser => Fog::Parsers::AWS::AutoScaling::DescribeLaunchConfigurations.new
}.merge!(options))
end
end
class Mock
def describe_launch_configurations(options = {})
results = { 'LaunchConfigurations' => [] }
data[:launch_configurations].each do |lc_name, lc_data|
results['LaunchConfigurations'] << {
'LaunchConfigurationName' => lc_name
}.merge!(lc_data)
end
response = Excon::Response.new
response.status = 200
response.body = {
'DescribeLaunchConfigurationsResult' => results,
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
}
response
end
end
end
end
end

View file

@ -0,0 +1,60 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/describe_metric_collection_types'
# Returns a list of metrics and a corresponding list of granularities
# for each metric.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
# * 'DescribeMetricCollectionTypesResult'<~Hash>:
# * 'Granularities'<~Array>:
# * 'Granularity'<~String> - The granularity of a Metric.
# * 'Metrics'<~Array>:
# * 'Metric'<~String> - The name of a Metric.
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_DescribeAutoScalingInstances.html
#
def describe_metric_collection_types()
request({
'Action' => 'DescribeMetricCollectionTypes',
:parser => Fog::Parsers::AWS::AutoScaling::DescribeMetricCollectionTypes.new
})
end
end
class Mock
def describe_metric_collection_types()
results = {
'Granularities' => [],
'Metrics' => []
}
data[:metric_collection_types][:granularities].each do |granularity|
results['Granularities'] << { 'Granularity' => granularity }
end
data[:metric_collection_types][:metrics].each do |metric|
results['Metrics'] << { 'Metric' => metric }
end
response = Excon::Response.new
response.status = 200
response.body = {
'DescribeMetricCollectionTypesResult' => results,
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
}
response
end
end
end
end
end

View file

@ -0,0 +1,85 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/describe_policies'
# Returns descriptions of what each policy does. This action supports
# pagination. If the response includes a token, there are more records
# available. To get the additional records, repeat the request with the
# response token as the NextToken parameter.
#
# ==== Parameters
# * options<~Hash>:
# * 'AutoScalingGroupName'<~String> - The name of the Auto Scaling
# group.
# * 'MaxRecords'<~Integer> - The maximum number of policies that will
# be described with each call.
# * 'NextToken'<~String> - The token returned by a previous call to
# indicate that there is more data available.
# * PolicyNames<~Array> - A list of policy names or policy ARNs to be
# described. If this list is omitted, all policy names are
# described. If an auto scaling group name is provided, the results
# are limited to that group.The list of requested policy names
# cannot contain more than 50 items. If unknown policy names are
# requested, they are ignored with no error.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
# * 'DescribePoliciesResult'<~Hash>:
# * 'ScalingPolicies'<~Array>:
# * 'AdjustmentType'<~String> - Specifies whether the
# adjustment is an absolute number or a percentage of the
# current capacity.
# * 'Alarms'<~Array>:
# * 'AlarmARN'<~String> - The Amazon Resource Name (ARN) of
# the alarm.
# * 'AlarmName'<~String> - The name of the alarm.
# * 'AutoScalingGroupName'<~String> - The name of the Auto
# Scaling group associated with this scaling policy.
# * 'Cooldown'<~Integer> - The amount of time, in seconds,
# after a scaling activity completes before any further
# trigger-related scaling activities can start.
# * 'PolicyARN'<~String> - The Amazon Resource Name (ARN) of
# the policy.
# * 'PolicyName'<~String> - The name of the scaling policy.
# * 'ScalingAdjustment'<~Integer> - The number associated with
# the specified AdjustmentType. A positive value adds to the
# current capacity and a negative value removes from the
# current capacity.
# * 'NextToken'<~String> - Acts as a paging mechanism for large
# result sets. Set to a non-empty string if there are
# additional results waiting to be returned. Pass this in to
# subsequent calls to return additional results.
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_DescribePolicies.html
#
def describe_policies(options = {})
if policy_names = options.delete('PolicyNames')
options.merge!(AWS.indexed_param('PolicyNames.member.%d', [*policy_names]))
end
request({
'Action' => 'DescribePolicies',
:parser => Fog::Parsers::AWS::AutoScaling::DescribePolicies.new
}.merge!(options))
end
end
class Mock
def describe_policies(options = {})
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,88 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/describe_scaling_activities'
# Returns the scaling activities for the specified Auto Scaling group.
#
# If the specified activity_ids list is empty, all the activities from
# the past six weeks are returned. Activities are sorted by completion
# time. Activities still in progress appear first on the list.
#
# This action supports pagination. If the response includes a token,
# there are more records available. To get the additional records,
# repeat the request with the response token as the NextToken
# parameter.
#
# ==== Parameters
# * options<~Hash>:
# * 'ActivityIds'<~Array> - A list containing the activity IDs of the
# desired scaling activities. If this list is omitted, all
# activities are described. If an AutoScalingGroupName is provided,
# the results are limited to that group. The list of requested
# activities cannot contain more than 50 items. If unknown
# activities are requested, they are ignored with no error.
# * 'AutoScalingGroupName'<~String> - The name of the Auto Scaling
# group.
# * 'MaxRecords'<~Integer> - The maximum number of scaling activities
# to return.
# * 'NextToken'<~String> - The token returned by a previous call to
# indicate that there is more data available.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
# * 'DescribeScalingActivitiesResponse'<~Hash>:
# * 'Activities'<~Array>:
# * 'ActivityId'<~String> - Specifies the ID of the activity.
# * 'AutoScalingGroupName'<~String> - The name of the Auto
# Scaling group.
# * 'Cause'<~String> - Contins the reason the activity was
# begun.
# * 'Description'<~String> - Contains a friendly, more verbose
# description of the scaling activity.
# * 'EndTime'<~Time> - Provides the end time of this activity.
# * 'Progress'<~Integer> - Specifies a value between 0 and 100
# that indicates the progress of the activity.
# * 'StartTime'<~Time> - Provides the start time of this
# activity.
# * 'StatusCode'<~String> - Contains the current status of the
# activity.
# * 'StatusMessage'<~String> - Contains a friendly, more
# verbose description of the activity status.
# * 'NextToken'<~String> - Acts as a paging mechanism for large
# result sets. Set to a non-empty string if there are
# additional results waiting to be returned. Pass this in to
# subsequent calls to return additional results.
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_DescribeScalingActivities.html
#
def describe_scaling_activities(options = {})
if activity_ids = options.delete('ActivityIds')
options.merge!(AWS.indexed_param('ActivityIds.member.%d', [*activity_ids]))
end
request({
'Action' => 'DescribeScalingActivities',
:parser => Fog::Parsers::AWS::AutoScaling::DescribeScalingActivities.new
}.merge!(options))
end
end
class Mock
def describe_scaling_activities(options = {})
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,54 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/describe_scaling_process_types'
# Returns scaling process types for use in the resume_processes and
# suspend_processes actions.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
# * 'DescribeScalingProcessTypesResult'<~Hash>:
# * 'Processes'<~Array>:
# * processtype<~Hash>:
# * 'ProcessName'<~String> - The name of a process.
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_DescribeScalingProcessTypes.html
#
def describe_scaling_process_types()
request({
'Action' => 'DescribeScalingProcessTypes',
:parser => Fog::Parsers::AWS::AutoScaling::DescribeScalingProcessTypes.new
})
end
end
class Mock
def describe_scaling_process_types()
results = { 'Processes' => [] }
data[:process_types].each do |process_type|
results['Processes'] << { 'ProcessName' => process_type }
end
response = Excon::Response.new
response.status = 200
response.body = {
'DescribeScalingProcessTypesResult' => results,
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
}
response
end
end
end
end
end

View file

@ -0,0 +1,83 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/describe_scheduled_actions'
# List all the actions scheduled for your Auto Scaling group that
# haven't been executed. To see a list of action already executed, see
# the activity record returned in describe_scaling_activities.
#
# ==== Parameters
# * options<~Hash>:
# * 'AutoScalingGroupName'<~String> - The name of the Auto Scaling
# group.
# * 'EndTime'<~Time> - The latest scheduled start time to return. If
# scheduled action names are provided, this field will be ignored.
# * 'MaxRecords'<~Integer> - The maximum number of scheduled actions
# to return.
# * 'NextToken'<~String> - The token returned by a previous call to
# indicate that there is more data available.
# * 'ScheduledActionNames'<~Array> - A list of scheduled actions to
# be described. If this list is omitted, all scheduled actions are
# described. The list of requested scheduled actions cannot contain
# more than 50 items. If an auto scaling group name is provided,
# the results are limited to that group. If unknown scheduled
# actions are requested, they are ignored with no error.
# * 'StartTime'<~Time> - The earliest scheduled start time to return.
# If scheduled action names are provided, this field will be
# ignored.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
# * 'DescribeScheduledActionsResponse'<~Hash>:
# * 'ScheduledUpdateGroupActions'<~Array>:
# * scheduledupdatesroupAction<~Hash>:
# * 'AutoScalingGroupName'<~String> - The name of the Auto
# Scaling group to be updated.
# * 'DesiredCapacity'<~Integer> -The number of instances you
# prefer to maintain in your Auto Scaling group.
# * 'MaxSize'<~Integer> - The maximum size of the Auto Scaling
# group.
# * 'MinSize'<~Integer> - The minimum size of the Auto Scaling
# group.
# * 'ScheduledActionARN'<~String> - The Amazon Resource Name
# (ARN) of this scheduled action.
# * 'Time'<~Time> - The time that the action is scheduled to
# occur. This value can be up to one month in the future.
# * 'NextToken'<~String> - Acts as a paging mechanism for large
# result sets. Set to a non-empty string if there are
# additional results waiting to be returned. Pass this in to
# subsequent calls to return additional results.
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_DescribeScheduledActions.html
#
def describe_scheduled_actions(options = {})
if scheduled_action_names = options.delete('ScheduledActionNames')
options.merge!(AWS.indexed_param('ScheduledActionNames.member.%d', [*scheduled_action_names]))
end
request({
'Action' => 'DescribeScheduledActions',
:parser => Fog::Parsers::AWS::AutoScaling::DescribeScheduledActions.new
}.merge!(options))
end
end
class Mock
def describe_scheduled_actions(options = {})
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,56 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/basic'
# Disables monitoring of group metrics for the Auto Scaling group
# specified in AutoScalingGroupName. You can specify the list of
# affected metrics with the Metrics parameter.
#
# ==== Parameters
# * 'AutoScalingGroupName'<~String> - The name or ARN of the Auto
# Scaling group.
# * options<~Hash>:
# * Metrics<~Array> - The list of metrics to disable. If no metrics
# are specified, all metrics are disabled.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_DisableMetricsCollection.html
#
def disable_metrics_collection(auto_scaling_group_name, options = {})
if metrics = options.delete('Metrics')
options.merge!(AWS.indexed_param('Metrics.member.%d', [*metrics]))
end
request({
'Action' => 'DisableMetricsCollection',
'AutoScalingGroupName' => auto_scaling_group_name,
:parser => Fog::Parsers::AWS::AutoScaling::Basic.new
}.merge!(options))
end
end
class Mock
def disable_metrics_collection(auto_scaling_group_name, options = {})
unless data[:auto_scaling_groups].has_key?(auto_scaling_group_name)
Fog::AWS::AutoScaling::ValidationError.new("Group #{auto_scaling_group_name} not found")
end
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,66 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/basic'
# Enables monitoring of group metrics for the Auto Scaling group
# specified in auto_scaling_group_name. You can specify the list of
# enabled metrics with the metrics parameter.
#
# Auto scaling metrics collection can be turned on only if the
# instance_monitoring.enabled flag, in the Auto Scaling group's launch
# configuration, is set to true.
#
# ==== Parameters
# * 'AutoScalingGroupName'<~String>: The name or ARN of the Auto
# Scaling group
# * options<~Hash>:
# * Granularity<~String>: The granularity to associate with the
# metrics to collect.
# * Metrics<~Array>: The list of metrics to collect. If no metrics
# are specified, all metrics are enabled.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_EnableMetricsCollection.html
#
def enable_metrics_collection(auto_scaling_group_name, granularity, options = {})
if metrics = options.delete('Metrics')
options.merge!(AWS.indexed_param('Metrics.member.%d', [*metrics]))
end
request({
'Action' => 'EnableMetricsCollection',
'AutoScalingGroupName' => auto_scaling_group_name,
'Granularity' => granularity,
:parser => Fog::Parsers::AWS::AutoScaling::Basic.new
}.merge!(options))
end
end
class Mock
def enable_metrics_collection(auto_scaling_group_name, granularity, options = {})
unless data[:auto_scaling_groups].has_key?(auto_scaling_group_name)
Fog::AWS::AutoScaling::ValidationError.new("Group #{auto_scaling_group_name} not found")
end
unless data[:metric_collection_types][:granularities].include?(granularity)
Fog::AWS::AutoScaling::ValidationError.new('Valid metrics granularity type is: [1Minute].')
end
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,50 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/basic'
# Runs the policy you create for your Auto Scaling group in
# put_scaling_policy.
#
# ==== Parameters
# * 'PolicyName'<~String> - The name or PolicyARN of the policy you
# want to run.
# * options<~Hash>:
# * 'AutoScalingGroupName'<~String> - The name or ARN of the Auto
# Scaling group.
# * 'HonorCooldown'<~Boolean> - Set to true if you want Auto Scaling
# to reject this request if the Auto Scaling group is in cooldown.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_ExecutePolicy.html
#
def execute_policy(policy_name, options = {})
request({
'Action' => 'ExecutePolicy',
'PolicyName' => policy_name,
:parser => Fog::Parsers::AWS::AutoScaling::Basic.new
}.merge!(options))
end
end
class Mock
def execute_policy(policy_name, options = {})
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,66 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/put_scaling_policy'
# Creates or updates a policy for an Auto Scaling group. To update an
# existing policy, use the existing policy name and set the
# parameter(s) you want to change. Any existing parameter not changed
# in an update to an existing policy is not changed in this update
# request.
#
# ==== Parameters
# * adjustment_type<~String> - Specifies whether the scaling_adjustment
# is an absolute number or a percentage of the current capacity.
# * auto_scaling_group_name<~String> - The name or ARN of the Auto
# Scaling group.
# * policy_name<~String> - The name of the policy you want to create or
# update.
# * scaling_adjustment<~Integer> - The number of instances by which to
# scale. AdjustmentType determines the interpretation of this number
# (e.g., as an absolute number or as a percentage of the existing
# Auto Scaling group size). A positive increment adds to the current
# capacity and a negative value removes from the current capacity.
# * options<~Hash>:
# * 'CoolDown'<~Integer> - The amount of time, in seconds, after a
# scaling activity completes before any further trigger-related
# scaling activities can start
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
# * 'PutScalingPolicyResponse'<~Hash>:
# * 'PolicyARN'<~String> - A policy's Amazon Resource Name (ARN).
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_PutScalingPolicy.html
#
def put_scaling_policy(adjustment_type, auto_scaling_group_name, policy_name, scaling_adjustment, options = {})
request({
'Action' => 'PutScalingPolicy',
'AdjustmentType' => adjustment_type,
'AutoScalingGroupName' => auto_scaling_group_name,
'PolicyName' => policy_name,
'ScalingAdustment' => scaling_adjustment,
:parser => Fog::Parsers::AWS::AutoScaling::PutScalingPolicy.new
}.merge!(options))
end
end
class Mock
def put_scaling_policy(adjustment_type, auto_scaling_group_name, policy_name, scaling_adjustment, options = {})
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,57 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/basic'
# Creates a scheduled scaling action for a Auto Scaling group. If you
# leave a parameter unspecified, the corresponding value remains
# unchanged in the affected Auto Scaling group.
#
# ==== Parameters
# * auto_scaling_group_name<~String> - The name or ARN of the Auto
# Scaling Group.
# * scheduled_action_name<~String> - Name of this scaling action.
# * time<~Datetime> - The time for this action to start
# * options<~Hash>:
# * 'DesiredCapacity'<~Integer> - The number of EC2 instances that
# should be running in this group.
# * 'MaxSize'<~Integer> - The maximum size for the Auto Scaling
# group.
# * 'MinSize'<~Integer> - The minimum size for the Auto Scaling
# group.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_PutScheduledUpdateGroupAction.html
#
def put_scheduled_update_group_action(auto_scaling_group_name, scheduled_action_name, time, options = {})
request({
'Action' => 'PutScheduledUpdateGroupAction',
'AutoScalingGroupName' => auto_scaling_group_name,
'ScheduledActionName' => scheduled_action_name,
'Time' => time.utc.strftime('%FT%T.%3NZ'),
:parser => Fog::Parsers::AWS::AutoScaling::Basic.new
}.merge!(options))
end
end
class Mock
def put_scheduled_update_group_action(auto_scaling_group_name, scheduled_policy_name, time, options = {})
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,50 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/basic'
# Resumes Auto Scaling processes for an Auto Scaling group.
#
# ==== Parameters
# * auto_scaling_group_name'<~String> - The name or Amazon Resource
# Name (ARN) of the Auto Scaling group.
# * options<~Hash>:
# * 'ScalingProcesses'<~Array> - The processes that you want to
# resume. To resume all process types, omit this parameter.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_ResumeProcesses.html
#
def resume_processes(auto_scaling_group_name, options = {})
if scaling_processes = options.delete('ScalingProcesses')
options.merge!(AWS.indexed_param('ScalingProcesses.member.%d', [*scaling_processes]))
end
request({
'Action' => 'ResumeProcesses',
'AutoScalingGroupName' => auto_scaling_group_name,
:parser => Fog::Parsers::AWS::AutoScaling::Basic.new
}.merge!(options))
end
end
class Mock
def resume_processes(auto_scaling_group_name, options = {})
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,87 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/basic'
# Adjusts the desired size of the AutoScalingGroup by initiating
# scaling activities. When reducing the size of the group, it is not
# possible to define which EC2 instances will be terminated. This
# applies to any auto-scaling decisions that might result in
# terminating instances.
#
# There are two common use cases for set_desired_capacity: one for
# users of the Auto Scaling triggering system, and another for
# developers who write their own triggering systems. Both use cases
# relate to the concept of cooldown.
#
# In the first case, if you use the Auto Scaling triggering system,
# set_desired_capacity changes the size of your Auto Scaling group
# without regard to the cooldown period. This could be useful, for
# example, if Auto Scaling did something unexpected for some reason. If
# your cooldown period is 10 minutes, Auto Scaling would normally
# reject requests to change the size of the group for that entire 10
# minute period. The set_desired_capacity command allows you to
# circumvent this restriction and change the size of the group before
# the end of the cooldown period.
#
# In the second case, if you write your own triggering system, you can
# use set_desired_capacity to control the size of your Auto Scaling
# group. If you want the same cooldown functionality that Auto Scaling
# offers, you can configure set_desired_capacity to honor cooldown by
# setting the HonorCooldown parameter to true.
#
# ==== Parameters
# * auto_scaling_group_name<~String> - The name of the Auto Scaling
# group.
# * desired_capacity<~Integer> - The new capacity setting for the Auto
# Scaling group.
# * options<~Hash>:
# * 'HonorCooldown'<~Boolean> - By default, set_desired_capacity
# overrides any cooldown period. Set to true if you want Auto
# Scaling to reject this request if the Auto Scaling group is in
# cooldown.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_SetDesiredCapacity.html
#
def set_desired_capacity(auto_scaling_group_name, desired_capacity, options = {})
request({
'Action' => 'SetDesiredCapacity',
'AutoScalingGroupName' => auto_scaling_group_name,
'DesiredCapacity' => desired_capacity,
:parser => Fog::Parsers::AWS::AutoScaling::Basic.new
}.merge!(options))
end
end
class Mock
def set_desired_capacity(auto_scaling_group_name, desired_capacity, options = {})
unless data[:auto_scaling_groups].has_key?(auto_scaling_group_name)
Fog::AWS::AutoScaling::ValidationError.new('AutoScalingGroup name not found - null')
end
data[:auto_scaling_groups][auto_scaling_group_name]['DesiredCapacity'] = desired_capacity
response = Excon::Response.new
response.status = 200
response.body = {
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
}
response
end
end
end
end
end

View file

@ -0,0 +1,55 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/basic'
# Sets the health status of an instance.
#
# ==== Parameters
# * health_status<~String> - The health status of the instance.
# "Healthy" means that the instance is healthy and should remain in
# service. "Unhealthy" means that the instance is unhealthy. Auto
# Scaling should terminate and replace it.
# * instance_id<~String> - The identifier of the EC2 instance.
# * options<~Hash>:
# * 'ShouldRespectGracePeriod'<~Boolean> - If true, this call should
# respect the grace period associated with the group.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_SetInstanceHealth.html
#
def set_instance_health(health_status, instance_id, options = {})
request({
'Action' => 'SetInstanceHealth',
'HealthStatus' => health_status,
'InstanceId' => instance_id,
:parser => Fog::Parsers::AWS::AutoScaling::Basic.new
}.merge!(options))
end
end
class Mock
def set_instance_health(health_status, instance_id, options = {})
unless data[:health_states].include?(health_status)
raise Fog::AWS::AutoScaling::ValidationError.new('Valid instance health states are: [#{data[:health_states].join(", ")}].')
end
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,57 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/basic'
# Suspends Auto Scaling processes for an Auto Scaling group. To suspend
# specific process types, specify them by name with the
# ScalingProcesses parameter. To suspend all process types, omit the
# ScalingProcesses.member.N parameter.
#
# ==== Parameters
# * 'AutoScalingGroupName'<~String> - The name or Amazon Resource Name
# (ARN) of the Auto Scaling group.
# * options<~Hash>:
# * 'ScalingProcesses'<~Array> - The processes that you want to
# suspend. To suspend all process types, omit this parameter.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_SuspendProcesses.html
#
def suspend_processes(auto_scaling_group_name, options = {})
if scaling_processes = options.delete('ScalingProcesses')
options.merge!(AWS.indexed_param('ScalingProcesses.member.%d', [*scaling_processes]))
end
request({
'Action' => 'SuspendProcesses',
'AutoScalingGroupName' => auto_scaling_group_name,
:parser => Fog::Parsers::AWS::AutoScaling::Basic.new
}.merge!(options))
end
end
class Mock
def suspend_processes(auto_scaling_group_name, options = {})
unless data[:auto_scaling_groups].has_key?(auto_scaling_group_name)
raise Fog::AWS::AutoScaling::ValidationError.new('AutoScalingGroup name not found - null')
end
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,65 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/terminate_instance_in_auto_scaling_group'
# Terminates the specified instance. Optionally, the desired group size
# can be adjusted.
#
# ==== Parameters
# * instance_id<~String> - The ID of the EC2 instance to be terminated.
# * should_decrement_desired_capacity<~Boolean> - Specifies whether
# (true) or not (false) terminating this instance should also
# decrement the size of the AutoScalingGroup.
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
# * 'TerminateGroupInAutoScalingInstanceResult'<~Hash>:
# * 'ActivityId'<~String> - Specifies the ID of the activity.
# * 'AutoScalingGroupName'<~String> - The name of the Auto
# Scaling group.
# * 'Cause'<~String> - Contains the reason the activity was
# begun.
# * 'Description'<~String> - Contains a friendly, more verbose
# description of the scaling activity.
# * 'EndTime'<~Time> - Provides the end time of this activity.
# * 'Progress'<~Integer> - Specifies a value between 0 and 100
# that indicates the progress of the activity.
# * 'StartTime'<~Time> - Provides the start time of this
# activity.
# * 'StatusCode'<~String> - Contains the current status of the
# activity.
# * 'StatusMessage'<~String> - Contains a friendly, more verbose
# description of the activity status.
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_TerminateInstanceInAutoScalingGroup.html
#
def terminate_instance_in_auto_scaling_group(instance_id, should_decrement_desired_capacity)
request({
'Action' => 'TerminateInstanceInAutoScalingGroup',
'InstanceId' => instance_id,
'ShouldDecrementDesiredCapacity' => should_decrement_desired_capacity.to_s,
:parser => Fog::Parsers::AWS::AutoScaling::TerminateInstanceInAutoScalingGroup.new
})
end
end
class Mock
def terminate_instance_in_auto_scaling_group(instance_id, should_decrement_desired_capacity)
Fog::Mock.not_implemented
end
end
end
end
end

View file

@ -0,0 +1,79 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/basic'
# Updates the configuration for the specified AutoScalingGroup.
#
# The new settings are registered upon the completion of this call. Any
# launch configuration settings take effect on any triggers after this
# call returns. Triggers that are currently in progress aren't
# affected.
#
# ==== Parameters
# * auto_scaling_group_name<~String> - The name of the Auto Scaling
# group.
# * options<~Hash>:
# * 'AvailabilityZones'<~Array>: Availability zones for the group
# * 'DefaultCooldown'<~Integer> - Amount of time, in seconds, after a
# scaling activity completes before any further trigger-related
# scaling activities can start
# * 'DesiredCapacity'<~Integer> - Desired capacity for the scaling group
# * 'HealthCheckGracePeriod'<~Integer> - Length of time that Auto
# Scaling waits before checking an instance's health status
# * 'HealthCheckType'<~String> - Service of interest for the health
# status check, either "EC2" or "ELB".
# * 'LaunchConfigurationName'<~String> - Name of the launch configuration
# * 'MaxSize'<~Integer> - Maximum size of the Auto Scaling group
# * 'MinSize'<~Integer> - Minimum size of the Auto Scaling group
# * 'PlacementGroup'<~String> - Name of the cluster placement group,
# if applicable
# * 'VPCZoneIdentifier'<~String> - Identifier for the VPC connection,
# if applicable
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ResponseMetadata'<~Hash>:
# * 'RequestId'<~String> - Id of request
#
# ==== See Also
# http://docs.amazonwebservices.com/AutoScaling/latest/APIReference/API_UpdateAutoScalingGroup.html
#
def update_auto_scaling_group(auto_scaling_group_name, options = {})
if availability_zones = options.delete('AvailabilityZones')
options.merge!(AWS.indexed_param('AvailabilityZones.member.%d', [*availability_zones]))
end
request({
'Action' => 'UpdateAutoScalingGroup',
'AutoScalingGroupName' => auto_scaling_group_name,
:parser => Fog::Parsers::AWS::AutoScaling::Basic.new
}.merge!(options))
end
end
class Mock
def update_auto_scaling_group(auto_scaling_group_name, options = {})
unless data[:auto_scaling_groups].has_key?(auto_scaling_group_name)
raise Fog::AWS::AutoScaling::ValidationError.new('AutoScalingGroup name not found - null')
end
data[:auto_scaling_group_name][auto_scaling_group_name].merge!(options)
response = Excon::Response.new
response.status = 200
response.body = {
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
}
response
end
end
end
end
end

View file

@ -3,6 +3,8 @@ class AWS < Fog::Bin
def class_for(key)
case key
when :auto_scaling
Fog::AWS::AutoScaling
when :cdn
Fog::AWS::CDN
when :cloud_formation
@ -34,6 +36,8 @@ class AWS < Fog::Bin
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :auto_scaling
Fog::AWS::AutoScaling.new
when :cdn
Fog::CDN.new(:provider => 'AWS')
when :cloud_formation

View file

@ -7,6 +7,7 @@ module Fog
extend Fog::Provider
service(:auto_scaling, 'aws/auto_scaling')
service(:cdn, 'cdn/aws')
service(:compute, 'compute/aws')
service(:cloud_formation, 'aws/cloud_formation')

View file

@ -0,0 +1,80 @@
Shindo.tests('AWS::AutoScaling | auto_scaling_tests', ['aws', 'auto_scaling']) do
@asg_name = 'fog-test-asg'
@lc_name = 'fog-test-lc'
tests('success') do
pending if Fog.mocking?
tests("#describe_adjustment_types").formats(AWS::AutoScaling::Formats::DESCRIBE_ADJUSTMENT_TYPES) do
AWS[:auto_scaling].describe_adjustment_types.body
end
tests("#describe_metric_collection_types").formats(AWS::AutoScaling::Formats::DESCRIBE_METRIC_COLLECTION_TYPES) do
AWS[:auto_scaling].describe_metric_collection_types.body
end
tests("#describe_scaling_process_types").formats(AWS::AutoScaling::Formats::DESCRIBE_SCALING_PROCESS_TYPES) do
AWS[:auto_scaling].describe_scaling_process_types.body
end
tests("#create_launch_configuration").formats(AWS::AutoScaling::Formats::BASIC) do
image_id = 'ami-8c1fece5'
instance_type = 't1.micro'
#listeners = [{'LoadBalancerPort' => 80, 'InstancePort' => 80, 'Protocol' => 'http'}]
AWS[:auto_scaling].create_launch_configuration(image_id, instance_type, @lc_name).body
end
tests("#describe_launch_configurations").formats(AWS::AutoScaling::Formats::DESCRIBE_LAUNCH_CONFIGURATIONS) do
AWS[:auto_scaling].describe_launch_configurations().body
end
tests("#describe_launch_configurations").formats(AWS::AutoScaling::Formats::DESCRIBE_LAUNCH_CONFIGURATIONS) do
AWS[:auto_scaling].describe_launch_configurations('LaunchConfigurationNames' => @lc_name).body
end
tests("#describe_launch_configurations").formats(AWS::AutoScaling::Formats::DESCRIBE_LAUNCH_CONFIGURATIONS) do
AWS[:auto_scaling].describe_launch_configurations('LaunchConfigurationNames' => [@lc_name]).body
end
tests("#create_auto_scaling_group").formats(AWS::AutoScaling::Formats::BASIC) do
zones = ['us-east-1d']
max_size = 0
min_size = 0
AWS[:auto_scaling].create_auto_scaling_group(@asg_name, zones, @lc_name, max_size, min_size).body
end
tests("#describe_auto_scaling_groups").formats(AWS::AutoScaling::Formats::DESCRIBE_AUTO_SCALING_GROUPS) do
AWS[:auto_scaling].describe_auto_scaling_groups().body
end
tests("#describe_auto_scaling_groups").formats(AWS::AutoScaling::Formats::DESCRIBE_AUTO_SCALING_GROUPS) do
AWS[:auto_scaling].describe_auto_scaling_groups('AutoScalingGroupNames' => @asg_name).body
end
tests("#describe_auto_scaling_groups").formats(AWS::AutoScaling::Formats::DESCRIBE_AUTO_SCALING_GROUPS) do
AWS[:auto_scaling].describe_auto_scaling_groups('AutoScalingGroupNames' => [@asg_name]).body
end
tests("#describe_auto_scaling_instances").formats(AWS::AutoScaling::Formats::DESCRIBE_AUTO_SCALING_INSTANCES) do
AWS[:auto_scaling].describe_auto_scaling_instances().body
end
tests("#describe_scaling_activities").formats(AWS::AutoScaling::Formats::DESCRIBE_SCALING_ACTIVITIES) do
AWS[:auto_scaling].describe_scaling_activities().body
end
tests("#describe_scaling_activities").formats(AWS::AutoScaling::Formats::DESCRIBE_SCALING_ACTIVITIES) do
AWS[:auto_scaling].describe_scaling_activities('ActivityIds' => '1').body
end
tests("#describe_scaling_activities").formats(AWS::AutoScaling::Formats::DESCRIBE_SCALING_ACTIVITIES) do
AWS[:auto_scaling].describe_scaling_activities('ActivityIds' => ['1', '2']).body
end
tests("#describe_scaling_activities").formats(AWS::AutoScaling::Formats::DESCRIBE_SCALING_ACTIVITIES) do
AWS[:auto_scaling].describe_scaling_activities('AutoScalingGroupName' => @asg_name).body
end
tests("#set_desired_capacity").formats(AWS::AutoScaling::Formats::BASIC) do
desired_capacity = 0
AWS[:auto_scaling].set_desired_capacity(@asg_name, desired_capacity).body
end
tests("#delete_auto_scaling_group").formats(AWS::AutoScaling::Formats::BASIC) do
AWS[:auto_scaling].delete_auto_scaling_group(@asg_name).body
end
tests("#delete_launch_configuration").formats(AWS::AutoScaling::Formats::BASIC) do
AWS[:auto_scaling].delete_launch_configuration(@lc_name).body
end
end
end

View file

@ -0,0 +1,185 @@
class AWS
module AutoScaling
module Formats
BASIC = {
'ResponseMetadata' => {'RequestId' => String}
}
PAGINATED = {
'NextToken' => Fog::Nullable::String
}
ACTIVITY = {
'ActivityId' => String,
'AutoScalingGroupName' => String,
'Cause' => String,
'Description' => String,
'EndTime' => Time,
'Progress' => Integer,
'StartTime' => Time,
'StatusCode' => String,
'StatusMessage' => String
}
ALARM = {
'AlarmARN' => String,
'AlarmName' => String
}
BLOCK_DEVICE_MAPPING = {
'DeviceName' => String,
'Ebs' => {'SnapshotId' => String, 'VolumeSize' => Integer},
'VirtualName' => String
}
ENABLED_METRIC = {
'Granularity' => Array,
'Metric' => Array
}
INSTANCE = {
'AvailabilityZone' => String,
'HealthStatus' => String,
'InstanceId' => String,
'LaunchConfigurationName' => String,
'LifecycleState' => String
}
SCHEDULED_UPDATE_GROUP_ACTION = {
'AutoScalingGroupName' => String,
'DesiredCapacity' => Integer,
'MaxSize' => Integer,
'MinSize' => Integer,
'ScheduledActionARN' => String,
'ScheduledActionName' => String,
'Time' => Time
}
PROCESS_TYPE = {
'ProcessName' => String
}
SUSPENDED_PROCESS = PROCESS_TYPE.merge({
'SuspensionReason' => String
})
AUTO_SCALING_GROUP = {
'AutoScalingGroupARN' => String,
'AutoScalingGroupName' => String,
'AvailabilityZones' => Array,
'CreatedTime' => Time,
'DefaultCooldown' => Integer,
'DesiredCapacity' => Integer,
'EnabledMetrics' => [ENABLED_METRIC],
'HealthCheckGracePeriod' => Integer,
'HealthCheckType' => String,
'Instances' => [INSTANCE],
'LaunchConfigurationName' => String,
'LoadBalancerNames' => Array,
'MaxSize' => Integer,
'MinSize' => Integer,
'PlacementGroup' => Fog::Nullable::String,
'SuspendedProcesses' => [SUSPENDED_PROCESS],
'VPCZoneIdentifier' => Fog::Nullable::String
}
AUTO_SCALING_INSTANCE_DETAILS = INSTANCE.merge({
'AutoScalingGroupName' => String
})
LAUNCH_CONFIGURATION = {
'BlockDeviceMappings' => [BLOCK_DEVICE_MAPPING],
'CreatedTime' => Time,
'ImageId' => String,
'InstanceMonitoring' => {'Enabled' => Fog::Boolean},
'InstanceType' => String,
'KernelId' => Fog::Nullable::String,
'KeyName' => Fog::Nullable::String,
'LaunchConfigurationARN' => String,
'LaunchConfigurationName' => String,
'RamdiskId' => Fog::Nullable::String,
'SecurityGroups' => Array,
'UserData' => Fog::Nullable::String
}
SCALING_POLICY = {
'AdjustmentType' => String,
'Alarms' => [ALARM],
'AutoScalingGroupName' => String,
'Cooldown' => Integer,
'PolicyARN' => String,
'PolicyName' => String,
'ScalingAdjustment' => Integer
}
DESCRIBE_ADJUSTMENT_TYPES = BASIC.merge({
'DescribeAdjustmentTypesResult' => {
'AdjustmentTypes' => [{'AdjustmentType' => String}]
}
})
DESCRIBE_AUTO_SCALING_GROUPS = BASIC.merge({
'DescribeAutoScalingGroupsResult' => PAGINATED.merge({
'AutoScalingGroups' => [AUTO_SCALING_GROUP],
})
})
DESCRIBE_AUTO_SCALING_INSTANCES = BASIC.merge({
'DescribeAutoScalingInstancesResult' => PAGINATED.merge({
'AutoScalingInstances' => [AUTO_SCALING_INSTANCE_DETAILS],
})
})
DESCRIBE_LAUNCH_CONFIGURATIONS = BASIC.merge({
'DescribeLaunchConfigurationsResult' => PAGINATED.merge({
'LaunchConfigurations' => [LAUNCH_CONFIGURATION],
})
})
DESCRIBE_METRIC_COLLECTION_TYPES = BASIC.merge({
'DescribeMetricCollectionTypesResult' => {
'Granularities' => [{'Granularity' => String}],
'Metrics' => [{'Metric' => String}]
}
})
DESCRIBE_POLICIES = BASIC.merge({
'DescribePoliciesResult' => PAGINATED.merge({
'ScalingPolicies' => [SCALING_POLICY]
})
})
DESCRIBE_SCALING_ACTIVITIES = BASIC.merge({
'DescribeScalingActivitiesResult' => PAGINATED.merge({
'Activities' => [ACTIVITY],
})
})
DESCRIBE_SCALING_PROCESS_TYPES = BASIC.merge({
'DescribeScalingProcessTypesResult' => {
'Processes' => [PROCESS_TYPE]
}
})
DESCRIBE_SCHEDULED_ACTIONS = BASIC.merge({
'DescribeScheduledActionsResult' => PAGINATED.merge({
'ScheduledUpdateGroupActions' => [SCHEDULED_UPDATE_GROUP_ACTION]
})
})
PUT_SCALING_POLICY = BASIC.merge({
'PutScalingPolicyResult' => {
'PolicyARN' => String
}
})
TERMINATE_INSTANCE_IN_AUTO_SCALING_GROUP = BASIC.merge({
'TerminateInstanceInAutoScalingGroupResult' => {
'Activity' => [ACTIVITY]
}
})
end
end
end

View file

@ -0,0 +1,235 @@
Shindo.tests('AWS::AutoScaling | model_tests', ['aws', 'auto_scaling']) do
tests('success') do
pending if Fog.mocking?
lc = nil
lc_id = 'fog-model-lc'
tests('configurations') do
tests('getting a missing configuration') do
returns(nil) { AWS[:auto_scaling].configurations.get('fog-no-such-lc') }
end
tests('create configuration') do
lc = AWS[:auto_scaling].configurations.create(:id => lc_id, :image_id => 'ami-8c1fece5', :instance_type => 't1.micro')
#tests("dns names is set").returns(true) { lc.dns_name.is_a?(String) }
tests("created_at is set").returns(true) { Time === lc.created_at }
#tests("policies is empty").returns([]) { lc.policies }
end
tests('all configurations') do
lc_ids = AWS[:auto_scaling].configurations.all.map{|e| e.id}
tests("contains lc").returns(true) { lc_ids.include? lc_id }
end
tests('get configuration') do
lc2 = AWS[:auto_scaling].configurations.get(lc_id)
tests('ids match').returns(lc_id) { lc2.id }
end
tests('creating a duplicate configuration') do
raises(Fog::AWS::AutoScaling::IdentifierTaken) do
AWS[:auto_scaling].configurations.create(:id => lc_id, :image_id => 'ami-8c1fece5', :instance_type => 't1.micro')
end
end
end
tests('groups') do
tests('getting a missing group') do
returns(nil) { AWS[:auto_scaling].groups.get('fog-no-such-asg') }
end
asg = nil
asg_id = 'fog-model-asg'
tests('create') do
asg = AWS[:auto_scaling].groups.create(:id => asg_id, :availability_zones => ['us-east-1d'], :launch_configuration_name => lc_id)
#tests("dns names is set").returns(true) { asg.dns_name.is_a?(String) }
tests("created_at is set").returns(true) { Time === asg.created_at }
#tests("policies is empty").returns([]) { asg.policies }
end
tests('all') do
asg_ids = AWS[:auto_scaling].groups.all.map{|e| e.id}
tests("contains asg").returns(true) { asg_ids.include? asg_id }
end
tests('get') do
asg2 = AWS[:auto_scaling].groups.get(asg_id)
tests('ids match').returns(asg_id) { asg2.id }
end
tests('suspend processes') do
asg.suspend_processes()
#tests('processes suspended').returns([]) { asg.suspended_processes }
end
tests('resume processes') do
asg.resume_processes()
tests('no processes suspended').returns([]) { asg.suspended_processes }
end
tests('creating a duplicate group') do
raises(Fog::AWS::AutoScaling::IdentifierTaken) do
AWS[:auto_scaling].groups.create(:id => asg_id, :availability_zones => ['us-east-1d'], :launch_configuration_name => lc_id)
end
end
tests('destroy group') do
asg.destroy
asg = nil
end
#tests('registering an invalid instance') do
# raises(Fog::AWS::AutoScaling::InvalidInstance) { asg.register_instances('i-00000000') }
#end
#tests('deregistering an invalid instance') do
# raises(Fog::AWS::AutoScaling::InvalidInstance) { asg.deregister_instances('i-00000000') }
#end
end
tests('configurations') do
tests('destroy configuration') do
lc.destroy
lc = nil
end
end
#server = AWS[:compute].servers.create
#tests('register instance') do
# begin
# elb.register_instances(server.id)
# rescue Fog::AWS::ELB::InvalidInstance
# # It may take a moment for a newly created instances to be visible to ELB requests
# raise if @retried_registered_instance
# @retried_registered_instance = true
# sleep 1
# retry
# end
#
# returns([server.id]) { elb.instances }
#end
#tests('instance_health') do
# returns('OutOfService') do
# elb.instance_health.detect{|hash| hash['InstanceId'] == server.id}['State']
# end
#
# returns([server.id]) { elb.instances_out_of_service }
#end
#tests('deregister instance') do
# elb.deregister_instances(server.id)
# returns([]) { elb.instances }
#end
#server.destroy
#tests('disable_availability_zones') do
# elb.disable_availability_zones(%w{us-east-1c us-east-1d})
# returns(%w{us-east-1a us-east-1b}) { elb.availability_zones.sort }
#end
#tests('enable_availability_zones') do
# elb.enable_availability_zones(%w{us-east-1c us-east-1d})
# returns(%w{us-east-1a us-east-1b us-east-1c us-east-1d}) { elb.availability_zones.sort }
#end
#tests('default health check') do
# default_health_check = {
# "HealthyThreshold"=>10,
# "Timeout"=>5,
# "UnhealthyThreshold"=>2,
# "Interval"=>30,
# "Target"=>"TCP:80"
# }
# returns(default_health_check) { elb.health_check }
#end
#tests('configure_health_check') do
# new_health_check = {
# "HealthyThreshold"=>5,
# "Timeout"=>10,
# "UnhealthyThreshold"=>3,
# "Interval"=>15,
# "Target"=>"HTTP:80/index.html"
# }
# elb.configure_health_check(new_health_check)
# returns(new_health_check) { elb.health_check }
#end
#tests('listeners') do
# default_listener_description = [{"Listener"=>{"InstancePort"=>80, "Protocol"=>"HTTP", "LoadBalancerPort"=>80}, "PolicyNames"=>[]}]
# tests('default') do
# returns(1) { elb.listeners.size }
#
# listener = elb.listeners.first
# returns([80,80,'HTTP', []]) { [listener.instance_port, listener.lb_port, listener.protocol, listener.policy_names] }
#
# end
#
# tests('#get') do
# returns(80) { elb.listeners.get(80).lb_port }
# end
#
# tests('create') do
# new_listener = { 'InstancePort' => 443, 'LoadBalancerPort' => 443, 'Protocol' => 'TCP'}
# elb.listeners.create(:instance_port => 443, :lb_port => 443, :protocol => 'TCP')
# returns(2) { elb.listeners.size }
# returns(443) { elb.listeners.get(443).lb_port }
# end
#
# tests('destroy') do
# elb.listeners.get(443).destroy
# returns(nil) { elb.listeners.get(443) }
# end
#end
#tests('policies') do
# app_policy_id = 'my-app-policy'
#
# tests 'are empty' do
# returns([]) { elb.policies.to_a }
# end
#
# tests('#all') do
# returns([]) { elb.policies.all.to_a }
# end
#
# tests('create app policy') do
# elb.policies.create(:id => app_policy_id, :cookie => 'my-app-cookie', :cookie_stickiness => :app)
# returns(app_policy_id) { elb.policies.first.id }
# end
#
# tests('get policy') do
# returns(app_policy_id) { elb.policies.get(app_policy_id).id }
# end
#
# tests('destroy app policy') do
# elb.policies.first.destroy
# returns([]) { elb.policies.to_a }
# end
#
# lb_policy_id = 'my-lb-policy'
# tests('create lb policy') do
# elb.policies.create(:id => lb_policy_id, :expiration => 600, :cookie_stickiness => :lb)
# returns(lb_policy_id) { elb.policies.first.id }
# end
#
# tests('setting a listener policy') do
# elb.set_listener_policy(80, lb_policy_id)
# returns([lb_policy_id]) { elb.listeners.get(80).policy_names }
# end
#
# tests('unsetting a listener policy') do
# elb.unset_listener_policy(80)
# returns([]) { elb.listeners.get(80).policy_names }
# end
#
# tests('a malformed policy') do
# raises(ArgumentError) { elb.policies.create(:id => 'foo', :cookie_stickiness => 'invalid stickiness') }
# end
#end
end
end