1
0
Fork 0
mirror of https://github.com/fog/fog-aws.git synced 2022-11-09 13:50:52 -05:00
fog--fog-aws/lib/fog/aws/requests/ecs/deregister_container_instance.rb
2015-06-05 21:39:54 -03:00

63 lines
2.4 KiB
Ruby

module Fog
module AWS
class ECS
class Real
require 'fog/aws/parsers/ecs/deregister_container_instance'
# Deregisters an Amazon ECS container instance from the specified cluster.
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DeregisterContainerInstance.html
# ==== Parameters
# * cluster <~String> - short name or full ARN of the cluster that hosts the container instance you want to deregister.
# * containerInstance <~String> - container instance UUID or full Amazon Resource Name (ARN) of the container instance you want to deregister.
# * force <~Boolean> - Force the deregistration of the container instance.
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'ContainerInstance' <~Hash> - full description of the deregistered container instance
def deregister_container_instance(params={})
request({
'Action' => 'DeregisterContainerInstance',
:parser => Fog::Parsers::AWS::ECS::DeregisterContainerInstance.new
}.merge(params))
end
end
class Mock
def deregister_container_instance(params={})
response = Excon::Response.new
response.status = 200
instance_id = params.delete('containerInstance')
instance_error = "ClientException => Container instance can not be blank."
raise Fog::AWS::ECS::Error, instance_error unless instance_id
if match = instance_id.match(/^arn:aws:ecs:.+:\d{1,12}:container-instance\/(.+)$/)
i = self.data[:container_instances].index do |inst|
inst['containerInstanceArn'].eql?(instance_id)
end
else
i = self.data[:container_instances].index do |inst|
inst['containerInstanceArn'].match(/#{instance_id}$/)
end
end
msg = "ClientException => Referenced container instance #{instance_id} not found."
raise Fog::AWS::ECS::Error, msg unless i
instance = self.data[:container_instances][i]
self.data[:container_instances].delete_at(i)
response.body = {
'DeregisterContainerInstanceResult' => {
'containerInstance' => instance
},
'ResponseMetadata' => {
'RequestId' => Fog::AWS::Mock.request_id
}
}
response
end
end
end
end
end