1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
module Fog
module AWS
class ECS
class Real
require 'fog/aws/parsers/ecs/describe_services'
# Describes the specified services running in your cluster.
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeServices.html
# ==== Parameters
# * cluster <~String> - name of the cluster that hosts the service you want to describe.
# * services <~Array> - list of services you want to describe.
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'services' <~Array> - The list of services described.
# * 'failures' <~Array> - The list of failures associated with the call (if any).
def describe_services(params={})
if services = params.delete('services')
params.merge!(Fog::AWS.indexed_param('services.member', [*services]))
end
request({
'Action' => 'DescribeServices',
:parser => Fog::Parsers::AWS::ECS::DescribeServices.new
}.merge(params))
end
end
class Mock
def describe_services(params={})
response = Excon::Response.new
response.status = 200
cluster = params.delete('cluster') || 'default'
services = params.delete('services')
msg = 'InvalidParameterException => Services cannot be empty.'
raise Fog::AWS::ECS::Error, msg unless services
owner_id = Fog::AWS::Mock.owner_id
if !cluster.match(/^arn:aws:ecs:.+:.+:cluster\/(.+)$/)
cluster_path = "cluster/#{cluster}"
cluster_arn = Fog::AWS::Mock.arn('ecs', owner_id, cluster_path, region)
else
cluster_arn = cluster
end
result = []
([*services].select { |s| s.match(/^arn:/) }).each do |ds|
result.concat(self.data[:services].select do |sv|
sv['serviceArn'].eql?(ds) && sv['clusterArn'].eql?(cluster_arn)
end)
end
([*services].select { |s| !s.match(/^arn:/) }).each do |ds|
result.concat(self.data[:services].select do |sv|
sv['serviceName'].eql?(ds) && sv['clusterArn'].eql?(cluster_arn)
end)
end
response.body = {
'DescribeServicesResult' => {
'services' => result,
'failures' => []
},
'ResponseMetadata' => {
'RequestId' => Fog::AWS::Mock.request_id
}
}
response
end
end
end
end
end
|