fog-aws 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fog/aws.rb +2 -0
- data/lib/fog/aws/ecs.rb +187 -0
- data/lib/fog/aws/models/compute/flavors.rb +10 -0
- data/lib/fog/aws/parsers/ecs/base.rb +28 -0
- data/lib/fog/aws/parsers/ecs/container_instance.rb +75 -0
- data/lib/fog/aws/parsers/ecs/create_cluster.rb +30 -0
- data/lib/fog/aws/parsers/ecs/create_service.rb +31 -0
- data/lib/fog/aws/parsers/ecs/delete_cluster.rb +30 -0
- data/lib/fog/aws/parsers/ecs/delete_service.rb +31 -0
- data/lib/fog/aws/parsers/ecs/deregister_container_instance.rb +31 -0
- data/lib/fog/aws/parsers/ecs/deregister_task_definition.rb +32 -0
- data/lib/fog/aws/parsers/ecs/describe_clusters.rb +55 -0
- data/lib/fog/aws/parsers/ecs/describe_container_instances.rb +38 -0
- data/lib/fog/aws/parsers/ecs/describe_services.rb +24 -0
- data/lib/fog/aws/parsers/ecs/describe_task_definition.rb +32 -0
- data/lib/fog/aws/parsers/ecs/describe_tasks.rb +24 -0
- data/lib/fog/aws/parsers/ecs/list_clusters.rb +27 -0
- data/lib/fog/aws/parsers/ecs/list_container_instances.rb +27 -0
- data/lib/fog/aws/parsers/ecs/list_services.rb +27 -0
- data/lib/fog/aws/parsers/ecs/list_task_definition_families.rb +27 -0
- data/lib/fog/aws/parsers/ecs/list_task_definitions.rb +27 -0
- data/lib/fog/aws/parsers/ecs/list_tasks.rb +27 -0
- data/lib/fog/aws/parsers/ecs/register_task_definition.rb +32 -0
- data/lib/fog/aws/parsers/ecs/run_task.rb +24 -0
- data/lib/fog/aws/parsers/ecs/service.rb +82 -0
- data/lib/fog/aws/parsers/ecs/start_task.rb +24 -0
- data/lib/fog/aws/parsers/ecs/stop_task.rb +23 -0
- data/lib/fog/aws/parsers/ecs/task.rb +77 -0
- data/lib/fog/aws/parsers/ecs/task_definition.rb +95 -0
- data/lib/fog/aws/parsers/ecs/update_service.rb +31 -0
- data/lib/fog/aws/requests/compute/create_vpc.rb +1 -1
- data/lib/fog/aws/requests/ecs/create_cluster.rb +64 -0
- data/lib/fog/aws/requests/ecs/create_service.rb +118 -0
- data/lib/fog/aws/requests/ecs/delete_cluster.rb +61 -0
- data/lib/fog/aws/requests/ecs/delete_service.rb +72 -0
- data/lib/fog/aws/requests/ecs/deregister_container_instance.rb +63 -0
- data/lib/fog/aws/requests/ecs/deregister_task_definition.rb +58 -0
- data/lib/fog/aws/requests/ecs/describe_clusters.rb +83 -0
- data/lib/fog/aws/requests/ecs/describe_container_instances.rb +64 -0
- data/lib/fog/aws/requests/ecs/describe_services.rb +76 -0
- data/lib/fog/aws/requests/ecs/describe_task_definition.rb +64 -0
- data/lib/fog/aws/requests/ecs/describe_tasks.rb +65 -0
- data/lib/fog/aws/requests/ecs/list_clusters.rb +45 -0
- data/lib/fog/aws/requests/ecs/list_container_instances.rb +46 -0
- data/lib/fog/aws/requests/ecs/list_services.rb +59 -0
- data/lib/fog/aws/requests/ecs/list_task_definition_families.rb +56 -0
- data/lib/fog/aws/requests/ecs/list_task_definitions.rb +55 -0
- data/lib/fog/aws/requests/ecs/list_tasks.rb +50 -0
- data/lib/fog/aws/requests/ecs/register_task_definition.rb +68 -0
- data/lib/fog/aws/requests/ecs/run_task.rb +114 -0
- data/lib/fog/aws/requests/ecs/start_task.rb +130 -0
- data/lib/fog/aws/requests/ecs/stop_task.rb +64 -0
- data/lib/fog/aws/requests/ecs/update_service.rb +81 -0
- data/lib/fog/aws/version.rb +1 -1
- data/tests/requests/compute/vpc_tests.rb +7 -0
- data/tests/requests/ecs/cluster_tests.rb +112 -0
- data/tests/requests/ecs/container_instance_tests.rb +119 -0
- data/tests/requests/ecs/helper.rb +276 -0
- data/tests/requests/ecs/sample_task_definition1.json +56 -0
- data/tests/requests/ecs/service_tests.rb +132 -0
- data/tests/requests/ecs/task_definitions_tests.rb +97 -0
- data/tests/requests/ecs/task_tests.rb +145 -0
- metadata +59 -2
@@ -0,0 +1,61 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class ECS
|
4
|
+
class Real
|
5
|
+
require 'fog/aws/parsers/ecs/delete_cluster'
|
6
|
+
|
7
|
+
# Deletes the specified cluster
|
8
|
+
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DeleteCluster.html
|
9
|
+
# ==== Parameters
|
10
|
+
# * cluster <~String> - The short name or full Amazon Resource Name (ARN) of the cluster that you want to delete
|
11
|
+
# ==== Returns
|
12
|
+
# * response<~Excon::Response>:
|
13
|
+
# * body<~Hash>:
|
14
|
+
# * 'Cluster'<~Hash> - The full description of the deleted cluster
|
15
|
+
def delete_cluster(params={})
|
16
|
+
request({
|
17
|
+
'Action' => 'DeleteCluster',
|
18
|
+
:parser => Fog::Parsers::AWS::ECS::DeleteCluster.new
|
19
|
+
}.merge(params))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Mock
|
24
|
+
def delete_cluster(params={})
|
25
|
+
response = Excon::Response.new
|
26
|
+
response.status = 200
|
27
|
+
|
28
|
+
cluster_id = params.delete('cluster')
|
29
|
+
|
30
|
+
if !cluster_id
|
31
|
+
message = 'ClientException => Cluster can not be blank.'
|
32
|
+
raise Fog::AWS::ECS::Error, message
|
33
|
+
end
|
34
|
+
|
35
|
+
if match = cluster_id.match(/^arn:aws:ecs:.+:\d{1,12}:cluster\/(.+)$/)
|
36
|
+
i = self.data[:clusters].index { |c| c['clusterArn'].eql?(cluster_id) }
|
37
|
+
else
|
38
|
+
i = self.data[:clusters].index { |c| c['clusterName'].eql?(cluster_id) }
|
39
|
+
end
|
40
|
+
|
41
|
+
if i
|
42
|
+
cluster = self.data[:clusters].delete_at(i)
|
43
|
+
else
|
44
|
+
raise Fog::AWS::ECS::NotFound, 'Cluster not found.'
|
45
|
+
end
|
46
|
+
|
47
|
+
cluster['status'] = 'INACTIVE'
|
48
|
+
response.body = {
|
49
|
+
'DeleteClusterResult' => {
|
50
|
+
'cluster' => cluster
|
51
|
+
},
|
52
|
+
'ResponseMetadata' => {
|
53
|
+
'RequestId' => Fog::AWS::Mock.request_id
|
54
|
+
}
|
55
|
+
}
|
56
|
+
response
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class ECS
|
4
|
+
class Real
|
5
|
+
require 'fog/aws/parsers/ecs/delete_service'
|
6
|
+
|
7
|
+
# Deletes a specified service within a cluster.
|
8
|
+
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DeleteService.html
|
9
|
+
# ==== Parameters
|
10
|
+
# * cluster <~String> - name of the cluster that hosts the service you want to delete.
|
11
|
+
# * service <~String> - name of the service you want to delete.
|
12
|
+
# ==== Returns
|
13
|
+
# * response<~Excon::Response>:
|
14
|
+
# * body<~Hash>:
|
15
|
+
# * 'Service'<~Hash> - The full description of the deleted service
|
16
|
+
def delete_service(params={})
|
17
|
+
request({
|
18
|
+
'Action' => 'DeleteService',
|
19
|
+
:parser => Fog::Parsers::AWS::ECS::DeleteService.new
|
20
|
+
}.merge(params))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Mock
|
25
|
+
def delete_service(params={})
|
26
|
+
response = Excon::Response.new
|
27
|
+
response.status = 200
|
28
|
+
|
29
|
+
service_id = params.delete('service')
|
30
|
+
msg = 'ClientException => Service cannot be empty.'
|
31
|
+
raise Fog::AWS::ECS::Error, msg unless service_id
|
32
|
+
|
33
|
+
owner_id = Fog::AWS::Mock.owner_id
|
34
|
+
|
35
|
+
cluster = params.delete('cluster') || 'default'
|
36
|
+
if !cluster.match(/^arn:aws:ecs:.+:.+:cluster\/(.+)$/)
|
37
|
+
cluster_path = "cluster/#{cluster}"
|
38
|
+
cluster_arn = Fog::AWS::Mock.arn('ecs', owner_id, cluster_path, region)
|
39
|
+
else
|
40
|
+
cluster_arn = cluster
|
41
|
+
end
|
42
|
+
|
43
|
+
if match = service_id.match(/^arn:aws:ecs:.+:\d{1,12}:service\/(.+)$/)
|
44
|
+
i = self.data[:services].index do |s|
|
45
|
+
s['clusterArn'].eql?(cluster_arn) && s['serviceArn'].eql?(service_id)
|
46
|
+
end
|
47
|
+
else
|
48
|
+
i = self.data[:services].index do |s|
|
49
|
+
s['clusterArn'].eql?(cluster_arn) && s['serviceName'].eql?(service_id)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
msg = "ServiceNotFoundException => Service not found."
|
54
|
+
raise Fog::AWS::ECS::Error, msg unless i
|
55
|
+
|
56
|
+
service = self.data[:services][i]
|
57
|
+
self.data[:services].delete_at(i)
|
58
|
+
|
59
|
+
response.body = {
|
60
|
+
'DeleteServiceResult' => {
|
61
|
+
'service' => service
|
62
|
+
},
|
63
|
+
'ResponseMetadata' => {
|
64
|
+
'RequestId' => Fog::AWS::Mock.request_id
|
65
|
+
}
|
66
|
+
}
|
67
|
+
response
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class ECS
|
4
|
+
class Real
|
5
|
+
require 'fog/aws/parsers/ecs/deregister_container_instance'
|
6
|
+
|
7
|
+
# Deregisters an Amazon ECS container instance from the specified cluster.
|
8
|
+
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DeregisterContainerInstance.html
|
9
|
+
# ==== Parameters
|
10
|
+
# * cluster <~String> - short name or full ARN of the cluster that hosts the container instance you want to deregister.
|
11
|
+
# * containerInstance <~String> - container instance UUID or full Amazon Resource Name (ARN) of the container instance you want to deregister.
|
12
|
+
# * force <~Boolean> - Force the deregistration of the container instance.
|
13
|
+
# ==== Returns
|
14
|
+
# * response<~Excon::Response>:
|
15
|
+
# * body<~Hash>:
|
16
|
+
# * 'ContainerInstance' <~Hash> - full description of the deregistered container instance
|
17
|
+
def deregister_container_instance(params={})
|
18
|
+
request({
|
19
|
+
'Action' => 'DeregisterContainerInstance',
|
20
|
+
:parser => Fog::Parsers::AWS::ECS::DeregisterContainerInstance.new
|
21
|
+
}.merge(params))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Mock
|
26
|
+
def deregister_container_instance(params={})
|
27
|
+
response = Excon::Response.new
|
28
|
+
response.status = 200
|
29
|
+
|
30
|
+
instance_id = params.delete('containerInstance')
|
31
|
+
instance_error = "ClientException => Container instance can not be blank."
|
32
|
+
raise Fog::AWS::ECS::Error, instance_error unless instance_id
|
33
|
+
|
34
|
+
if match = instance_id.match(/^arn:aws:ecs:.+:\d{1,12}:container-instance\/(.+)$/)
|
35
|
+
i = self.data[:container_instances].index do |inst|
|
36
|
+
inst['containerInstanceArn'].eql?(instance_id)
|
37
|
+
end
|
38
|
+
else
|
39
|
+
i = self.data[:container_instances].index do |inst|
|
40
|
+
inst['containerInstanceArn'].match(/#{instance_id}$/)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
msg = "ClientException => Referenced container instance #{instance_id} not found."
|
45
|
+
raise Fog::AWS::ECS::Error, msg unless i
|
46
|
+
|
47
|
+
instance = self.data[:container_instances][i]
|
48
|
+
self.data[:container_instances].delete_at(i)
|
49
|
+
|
50
|
+
response.body = {
|
51
|
+
'DeregisterContainerInstanceResult' => {
|
52
|
+
'containerInstance' => instance
|
53
|
+
},
|
54
|
+
'ResponseMetadata' => {
|
55
|
+
'RequestId' => Fog::AWS::Mock.request_id
|
56
|
+
}
|
57
|
+
}
|
58
|
+
response
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class ECS
|
4
|
+
class Real
|
5
|
+
require 'fog/aws/parsers/ecs/deregister_task_definition'
|
6
|
+
|
7
|
+
# Deregisters the specified task definition.
|
8
|
+
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DeregisterTaskDefinition.html
|
9
|
+
# ==== Parameters
|
10
|
+
# * taskDefinition <~String> - The family and revision (family:revision) or full Amazon Resource Name (ARN) of the task definition that you want to deregister.
|
11
|
+
# ==== Returns
|
12
|
+
# * response<~Excon::Response>:
|
13
|
+
# * body<~Hash>:
|
14
|
+
# * 'TaskDefinition' <~Hash> - full description of the deregistered task
|
15
|
+
def deregister_task_definition(params={})
|
16
|
+
request({
|
17
|
+
'Action' => 'DeregisterTaskDefinition',
|
18
|
+
:parser => Fog::Parsers::AWS::ECS::DeregisterTaskDefinition.new
|
19
|
+
}.merge(params))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Mock
|
24
|
+
def deregister_task_definition(params={})
|
25
|
+
response = Excon::Response.new
|
26
|
+
response.status = 200
|
27
|
+
|
28
|
+
taskdef_error = "ClientException => Task Definition can not be blank."
|
29
|
+
raise Fog::AWS::ECS::Error, taskdef_error unless params['taskDefinition']
|
30
|
+
|
31
|
+
task_def_name = params['taskDefinition']
|
32
|
+
|
33
|
+
case task_def_name
|
34
|
+
when /^arn:aws:ecs:.+:\d{1,12}:task-definition\/(.+:.+)$/
|
35
|
+
i = self.data[:task_definitions].index { |t| t['taskDefinitionArn'].eql?(task_def_name) }
|
36
|
+
when /^(.+:.+)$/
|
37
|
+
i = self.data[:task_definitions].index { |t| t['taskDefinitionArn'].match(/task-definition\/#{task_def_name}$/) }
|
38
|
+
else
|
39
|
+
raise Fog::AWS::ECS::Error, 'Invalid task definition'
|
40
|
+
end
|
41
|
+
|
42
|
+
raise Fog::AWS::ECS::NotFound, 'Task definition not found.' unless i
|
43
|
+
task_definition = self.data[:task_definitions].delete_at(i)
|
44
|
+
|
45
|
+
response.body = {
|
46
|
+
'DeregisterTaskDefinitionResult' => {
|
47
|
+
'taskDefinition' => task_definition
|
48
|
+
},
|
49
|
+
'ResponseMetadata' => {
|
50
|
+
'RequestId' => Fog::AWS::Mock.request_id
|
51
|
+
}
|
52
|
+
}
|
53
|
+
response
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class ECS
|
4
|
+
class Real
|
5
|
+
require 'fog/aws/parsers/ecs/describe_clusters'
|
6
|
+
|
7
|
+
# Describes one or more of your clusters.
|
8
|
+
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeClusters.html
|
9
|
+
# ==== Parameters
|
10
|
+
# * clusters <~Array> - list of cluster names or full cluster Amazon Resource Name (ARN) entries
|
11
|
+
# ==== Returns
|
12
|
+
# * response<~Excon::Response>:
|
13
|
+
# * body<~Hash>:
|
14
|
+
# * 'clusters' <~Array> - The list of clusters
|
15
|
+
# * 'failures' <~Array> - The list of failures (if any)
|
16
|
+
def describe_clusters(params={})
|
17
|
+
if members = params.delete('clusters')
|
18
|
+
params.merge!(Fog::AWS.indexed_param('clusters.member', [*members]))
|
19
|
+
end
|
20
|
+
|
21
|
+
request({
|
22
|
+
'Action' => 'DescribeClusters',
|
23
|
+
:parser => Fog::Parsers::AWS::ECS::DescribeClusters.new
|
24
|
+
}.merge(params))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Mock
|
29
|
+
def describe_clusters(params={})
|
30
|
+
response = Excon::Response.new
|
31
|
+
response.status = 200
|
32
|
+
|
33
|
+
members = params.delete('clusters')
|
34
|
+
members = 'default' unless members
|
35
|
+
clusters = []
|
36
|
+
failures = []
|
37
|
+
|
38
|
+
[*members].each do |c|
|
39
|
+
if match = c.match(/^arn:aws:ecs:.+:\d{1,12}:cluster\/(.+)$/)
|
40
|
+
result = self.data[:clusters].select { |cl| cl['clusterArn'].eql?(c) }
|
41
|
+
else
|
42
|
+
result = self.data[:clusters].select { |cl| cl['clusterName'].eql?(c) }
|
43
|
+
end
|
44
|
+
if result.empty?
|
45
|
+
cluster_name = match[1] if match
|
46
|
+
cluster_name = c unless match
|
47
|
+
failures << { 'name' => cluster_name }
|
48
|
+
else
|
49
|
+
clusters << result.first
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
owner_id = Fog::AWS::Mock.owner_id
|
54
|
+
|
55
|
+
failures.map! do |f|
|
56
|
+
{
|
57
|
+
'arn' => Fog::AWS::Mock.arn('ecs', owner_id, "cluster/#{f['name']}", region),
|
58
|
+
'reason' => 'MISSING'
|
59
|
+
}
|
60
|
+
end
|
61
|
+
clusters.map! do |c|
|
62
|
+
{
|
63
|
+
'clusterName' => c['clusterName'],
|
64
|
+
'clusterArn' => c['clusterArn'],
|
65
|
+
'status' => c['status']
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
response.body = {
|
70
|
+
'DescribeClustersResult' => {
|
71
|
+
'failures' => failures,
|
72
|
+
'clusters' => clusters
|
73
|
+
},
|
74
|
+
'ResponseMetadata' => {
|
75
|
+
'RequestId' => Fog::AWS::Mock.request_id
|
76
|
+
}
|
77
|
+
}
|
78
|
+
response
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class ECS
|
4
|
+
class Real
|
5
|
+
require 'fog/aws/parsers/ecs/describe_container_instances'
|
6
|
+
|
7
|
+
# Describes Amazon EC2 Container Service container instances.
|
8
|
+
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeContainerInstances.html
|
9
|
+
# ==== Parameters
|
10
|
+
# * cluster <~String> - short name or full ARN of the cluster that hosts the container instances you want to describe.
|
11
|
+
# * containerInstances <~Array> - list of container instance UUIDs or full Amazon Resource Name (ARN) entries.
|
12
|
+
# ==== Returns
|
13
|
+
# * response<~Excon::Response>:
|
14
|
+
# * body<~Hash>:
|
15
|
+
# * 'containerInstances' <~Array> - list of container instances.
|
16
|
+
# * 'failures' <~Array> - list of failures (if any)
|
17
|
+
def describe_container_instances(params={})
|
18
|
+
if instances = params.delete('containerInstances')
|
19
|
+
params.merge!(Fog::AWS.indexed_param('containerInstances.member', [*instances]))
|
20
|
+
end
|
21
|
+
|
22
|
+
request({
|
23
|
+
'Action' => 'DescribeContainerInstances',
|
24
|
+
:parser => Fog::Parsers::AWS::ECS::DescribeContainerInstances.new
|
25
|
+
}.merge(params))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Mock
|
30
|
+
def describe_container_instances(params={})
|
31
|
+
response = Excon::Response.new
|
32
|
+
response.status = 200
|
33
|
+
|
34
|
+
cluster = params.delete('cluster') || 'default'
|
35
|
+
|
36
|
+
instances_id = params.delete('containerInstances')
|
37
|
+
msg = 'ClientException => Container instance cannot be empty.'
|
38
|
+
raise Fog::AWS::ECS::Error, msg unless instances_id
|
39
|
+
|
40
|
+
result = []
|
41
|
+
[*instances_id].each do |inst|
|
42
|
+
if match = inst.match(/^arn:aws:ecs:.+:\d{1,12}:container-instance\/(.+)$/)
|
43
|
+
result = self.data[:container_instances].select { |i| i['containerInstanceArn'].eql?(inst) }
|
44
|
+
else
|
45
|
+
result = self.data[:container_instances].select { |i| i['containerInstanceArn'].match(/#{inst}$/) }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
instances = result
|
50
|
+
response.body = {
|
51
|
+
'DescribeContainerInstancesResult' => {
|
52
|
+
'containerInstances' => instances,
|
53
|
+
'failures' => []
|
54
|
+
},
|
55
|
+
'ResponseMetadata' => {
|
56
|
+
'RequestId' => Fog::AWS::Mock.request_id
|
57
|
+
}
|
58
|
+
}
|
59
|
+
response
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class ECS
|
4
|
+
class Real
|
5
|
+
require 'fog/aws/parsers/ecs/describe_services'
|
6
|
+
|
7
|
+
# Describes the specified services running in your cluster.
|
8
|
+
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeServices.html
|
9
|
+
# ==== Parameters
|
10
|
+
# * cluster <~String> - name of the cluster that hosts the service you want to describe.
|
11
|
+
# * services <~Array> - list of services you want to describe.
|
12
|
+
# ==== Returns
|
13
|
+
# * response<~Excon::Response>:
|
14
|
+
# * body<~Hash>:
|
15
|
+
# * 'services' <~Array> - The list of services described.
|
16
|
+
# * 'failures' <~Array> - The list of failures associated with the call (if any).
|
17
|
+
def describe_services(params={})
|
18
|
+
if services = params.delete('services')
|
19
|
+
params.merge!(Fog::AWS.indexed_param('services.member', [*services]))
|
20
|
+
end
|
21
|
+
|
22
|
+
request({
|
23
|
+
'Action' => 'DescribeServices',
|
24
|
+
:parser => Fog::Parsers::AWS::ECS::DescribeServices.new
|
25
|
+
}.merge(params))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Mock
|
30
|
+
def describe_services(params={})
|
31
|
+
response = Excon::Response.new
|
32
|
+
response.status = 200
|
33
|
+
|
34
|
+
cluster = params.delete('cluster') || 'default'
|
35
|
+
services = params.delete('services')
|
36
|
+
msg = 'InvalidParameterException => Services cannot be empty.'
|
37
|
+
raise Fog::AWS::ECS::Error, msg unless services
|
38
|
+
|
39
|
+
owner_id = Fog::AWS::Mock.owner_id
|
40
|
+
|
41
|
+
if !cluster.match(/^arn:aws:ecs:.+:.+:cluster\/(.+)$/)
|
42
|
+
cluster_path = "cluster/#{cluster}"
|
43
|
+
cluster_arn = Fog::AWS::Mock.arn('ecs', owner_id, cluster_path, region)
|
44
|
+
else
|
45
|
+
cluster_arn = cluster
|
46
|
+
end
|
47
|
+
|
48
|
+
result = []
|
49
|
+
([*services].select { |s| s.match(/^arn:/) }).each do |ds|
|
50
|
+
result.concat(self.data[:services].select do |sv|
|
51
|
+
sv['serviceArn'].eql?(ds) && sv['clusterArn'].eql?(cluster_arn)
|
52
|
+
end)
|
53
|
+
end
|
54
|
+
([*services].select { |s| !s.match(/^arn:/) }).each do |ds|
|
55
|
+
result.concat(self.data[:services].select do |sv|
|
56
|
+
sv['serviceName'].eql?(ds) && sv['clusterArn'].eql?(cluster_arn)
|
57
|
+
end)
|
58
|
+
end
|
59
|
+
|
60
|
+
response.body = {
|
61
|
+
'DescribeServicesResult' => {
|
62
|
+
'services' => result,
|
63
|
+
'failures' => []
|
64
|
+
},
|
65
|
+
'ResponseMetadata' => {
|
66
|
+
'RequestId' => Fog::AWS::Mock.request_id
|
67
|
+
}
|
68
|
+
}
|
69
|
+
response
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|