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

autoscaler attach/detatch

Amazon doc links inline in the commits
This commit is contained in:
Shai Rosenfeld 2016-02-23 16:33:54 -08:00
parent 0ad726dab2
commit 4b7a384d82
5 changed files with 151 additions and 1 deletions

View file

@ -35,6 +35,8 @@ module Fog
request :describe_tags
request :describe_termination_policy_types
request :detach_load_balancers
request :detach_instances
request :attach_instances
request :disable_metrics_collection
request :enable_metrics_collection
request :execute_policy

View file

@ -61,6 +61,18 @@ module Fog
reload
end
def detach_instances(*instance_ids)
requires :id
service.detach_instances(id, 'InstanceIds' => instance_ids)
reload
end
def attach_instances(*instance_ids)
requires :id
service.attach_instances(id, 'InstanceIds' => instance_ids)
reload
end
def disable_metrics_collection(metrics = {})
requires :id
service.disable_metrics_collection(id, 'Metrics' => metrics)

View file

@ -0,0 +1,59 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/basic'
# Removes one or more instances from the specified Auto Scaling group.
#
# cli equiv:
# `aws autoscaling attach-instances --instance-ids i-93633f9b --auto-scaling-group-name my-auto-scaling-group`
#
# ==== Parameters
#
# * AutoScalingGroupName<~String> - The name of the Auto Scaling group``
# * 'InstanceIds'<~Array> - The list of Auto Scaling instances to detach.
#
# ==== See Also
#
# http://docs.aws.amazon.com/cli/latest/reference/autoscaling/attach-instances.html
ExpectedOptions[:asg_name] = %w[AutoScalingGroupName]
def attach_instances(auto_scaling_group_name, options = {})
if instance_ids = options.delete('InstanceIds')
options.merge!(AWS.indexed_param('InstanceIds.member.%d', [*instance_ids]))
end
request({
'Action' => 'AttachInstances',
'AutoScalingGroupName' => auto_scaling_group_name,
:parser => Fog::Parsers::AWS::AutoScaling::Basic.new
}.merge!(options))
end
end
class Mock
def attach_instances(auto_scaling_group_name, options = {})
unexpected_options = options.keys - ExpectedOptions[:asg_name]
unless unexpected_options.empty?
raise Fog::AWS::AutoScaling::ValidationError.new("Options #{unexpected_options.join(',')} should not be included in request")
end
unless self.data[:auto_scaling_groups].key?(auto_scaling_group_name)
raise Fog::AWS::AutoScaling::ValidationError.new('AutoScalingGroup name not found - null')
end
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,69 @@
module Fog
module AWS
class AutoScaling
class Real
require 'fog/aws/parsers/auto_scaling/basic'
# Removes one or more instances from the specified Auto Scaling group.
#
# cli equiv:
# `aws autoscaling detach-instances --instance-ids i-2a2d8978 --auto-scaling-group-name my-asg --should-decrement-desired-capacity`
#
# ==== Parameters
#
# * AutoScalingGroupName<~String> - The name of the Auto Scaling group``
# * 'InstanceIds'<~Array> - The list of Auto Scaling instances to detach.
#
# * options<~Hash>:
# 'shouldDecrementDesiredCapacity'<~Boolean> - decrement the asg capacity or not (it will boot another if an instance id detached)
#
# ==== See Also
# http://docs.aws.amazon.com/AutoScaling/latest/DeveloperGuide/detach-instance-asg.html
#
ExpectedOptions[:asg_name] = %w[AutoScalingGroupName]
ExpectedOptions[:instance_ids] = %w[AutoScalingGroupName]
def detach_instances(auto_scaling_group_name, options = {})
if should_decrement_desired_capacity = options.delete('ShouldDecrementDesiredCapacity')
options.merge!('ShouldDecrementDesiredCapacity' => true.to_s)
else
options.merge!('ShouldDecrementDesiredCapacity' => false.to_s)
end
if instance_ids = options.delete('InstanceIds')
options.merge!(AWS.indexed_param('InstanceIds.member.%d', [*instance_ids]))
end
request({
'Action' => 'DetachInstances',
'AutoScalingGroupName' => auto_scaling_group_name,
:parser => Fog::Parsers::AWS::AutoScaling::Basic.new
}.merge!(options))
end
end
class Mock
def detach_instances(auto_scaling_group_name, options = {})
unexpected_options = options.keys - ExpectedOptions[:asg_name] - ExpectedOptions[:instance_ids]
unless unexpected_options.empty?
raise Fog::AWS::AutoScaling::ValidationError.new("Options #{unexpected_options.join(',')} should not be included in request")
end
unless self.data[:auto_scaling_groups].key?(auto_scaling_group_name)
raise Fog::AWS::AutoScaling::ValidationError.new('AutoScalingGroup name not found - null')
end
response = Excon::Response.new
response.status = 200
response.body = {
'ResponseMetadata' => { 'RequestId' => Fog::AWS::Mock.request_id }
}
response
end
end
end
end
end

View file

@ -35,7 +35,15 @@ Shindo.tests('AWS::AutoScaling | auto_scaling_tests', ['aws', 'auto_scaling']) d
Fog::AWS[:auto_scaling].detach_load_balancers(@asg_name, 'LoadBalancerNames' => 'elb-test-fog').body
end
tests("#describe_auto_scaling_groups").formats(AWS::AutoScaling::Formats::DESCRIBE_AUTO_SCALING_GROUPS) do
tests("#detach_instances").formats(AWS::AutoScaling::Formats::BASIC) do
Fog::AWS[:auto_scaling].detach_instances(@asg_name, 'InstanceIds' => 'i-deadbeef').body
end
tests("#attach_instances").formats(AWS::AutoScaling::Formats::BASIC) do
Fog::AWS[:auto_scaling].attach_instances(@asg_name, 'InstanceIds' => 'i-deadbeef').body
end
tests("#describe_auto_scaling_groups").formats(AWS::AutoScaling::Formats::DESCRIBE_AUTO_SCALING_GROUPS) do
Fog::AWS[:auto_scaling].describe_auto_scaling_groups().body
end
tests("#describe_auto_scaling_groups").formats(AWS::AutoScaling::Formats::DESCRIBE_AUTO_SCALING_GROUPS) do