fog-aws 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,68 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class ECS
|
4
|
+
class Real
|
5
|
+
require 'fog/aws/parsers/ecs/register_task_definition'
|
6
|
+
|
7
|
+
# Registers a new task definition from the supplied family and containerDefinitions.
|
8
|
+
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_RegisterTaskDefinition.html
|
9
|
+
# ==== Parameters
|
10
|
+
# * containerDefinitions <~Array> - list of container definitions in JSON format that describe the different containers that make up your task.
|
11
|
+
# * family <~String> - family for a task definition, which allows you to track multiple versions of the same task definition.
|
12
|
+
# * volumes <~String> - list of volume definitions in JSON format that containers in your task may use.
|
13
|
+
# ==== Returns
|
14
|
+
# * response<~Excon::Response>:
|
15
|
+
# * body<~Hash>:
|
16
|
+
# * 'TaskDefinition' <~Array> - full task definition description registered
|
17
|
+
def register_task_definition(params={})
|
18
|
+
serialized_params = {}
|
19
|
+
params.each_pair do |k,v|
|
20
|
+
serialized_params.merge!(Fog::AWS.serialize_keys(k, v))
|
21
|
+
end
|
22
|
+
request({
|
23
|
+
'Action' => 'RegisterTaskDefinition',
|
24
|
+
:parser => Fog::Parsers::AWS::ECS::RegisterTaskDefinition.new
|
25
|
+
}.merge(serialized_params))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Mock
|
30
|
+
def register_task_definition(params={})
|
31
|
+
response = Excon::Response.new
|
32
|
+
response.status = 200
|
33
|
+
|
34
|
+
family_error = 'ClientException => Family can not be blank.'
|
35
|
+
container_error = 'ClientException => Container list cannot be empty.'
|
36
|
+
raise Fog::AWS::ECS::Error, family_error unless params['family']
|
37
|
+
raise Fog::AWS::ECS::Error, container_error unless params['containerDefinitions']
|
38
|
+
|
39
|
+
owner_id = Fog::AWS::Mock.owner_id
|
40
|
+
taskdef_name = params['family']
|
41
|
+
taskdef_rev = (1..9).to_a.shuffle.first
|
42
|
+
taskdef_path = "task-definition/#{taskdef_name}:#{taskdef_rev}"
|
43
|
+
taskdef_arn = Fog::AWS::Mock.arn('ecs', owner_id, taskdef_path, region)
|
44
|
+
|
45
|
+
task_definition = {
|
46
|
+
'revision' => taskdef_rev,
|
47
|
+
'taskDefinitionArn' => taskdef_arn,
|
48
|
+
'family' => params['family'],
|
49
|
+
'containerDefinitions' => params['containerDefinitions']
|
50
|
+
}
|
51
|
+
task_definition['volumes'] = params['volumes'] if params['volumes']
|
52
|
+
|
53
|
+
self.data[:task_definitions] << task_definition
|
54
|
+
|
55
|
+
response.body = {
|
56
|
+
'ResponseMetadata' => {
|
57
|
+
'RequestId' => Fog::AWS::Mock.request_id
|
58
|
+
},
|
59
|
+
'RegisterTaskDefinitionResult' => {
|
60
|
+
'taskDefinition' => task_definition
|
61
|
+
}
|
62
|
+
}
|
63
|
+
response
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class ECS
|
4
|
+
class Real
|
5
|
+
require 'fog/aws/parsers/ecs/run_task'
|
6
|
+
|
7
|
+
# Start a task using random placement and the default Amazon ECS scheduler.
|
8
|
+
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_RunTask.html
|
9
|
+
# ==== Parameters
|
10
|
+
# * cluster <~String> - short name or full Amazon Resource Name (ARN) of the cluster that you want to run your task on.
|
11
|
+
# * count <~Integer> - number of instantiations of the specified task that you would like to place on your cluster.
|
12
|
+
# * overrides <~Hash> - list of container overrides.
|
13
|
+
# * startedBy <~String> - optional tag specified when a task is started
|
14
|
+
# * taskDefinition <~String> - family and revision (family:revision) or full ARN of the task definition that you want to run.
|
15
|
+
# ==== Returns
|
16
|
+
# * response<~Excon::Response>:
|
17
|
+
# * body<~Hash>:
|
18
|
+
# * 'tasks' <~Array> - full description of the tasks that were run.
|
19
|
+
# * 'failures' <~Array> - Any failed tasks from your RunTask action are listed here.
|
20
|
+
def run_task(params={})
|
21
|
+
if overrides = params.delete('overrides')
|
22
|
+
serialized_overrides = {}
|
23
|
+
if overrides.is_a?(Hash)
|
24
|
+
overrides.each_pair do |k,v|
|
25
|
+
serialized_overrides.merge!(Fog::AWS.serialize_keys(k, v))
|
26
|
+
end
|
27
|
+
end
|
28
|
+
params.merge!('overrides' => serialized_overrides)
|
29
|
+
end
|
30
|
+
|
31
|
+
request({
|
32
|
+
'Action' => 'RunTask',
|
33
|
+
:parser => Fog::Parsers::AWS::ECS::RunTask.new
|
34
|
+
}.merge(params))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Mock
|
39
|
+
def run_task(params={})
|
40
|
+
response = Excon::Response.new
|
41
|
+
response.status = 200
|
42
|
+
|
43
|
+
unless task_def_id = params.delete('taskDefinition')
|
44
|
+
msg = 'ClientException => TaskDefinition cannot be empty.'
|
45
|
+
raise Fog::AWS::ECS::Error, msg
|
46
|
+
end
|
47
|
+
|
48
|
+
begin
|
49
|
+
result = describe_task_definition('taskDefinition' => task_def_id).body
|
50
|
+
task_def = result["DescribeTaskDefinitionResult"]["taskDefinition"]
|
51
|
+
task_def_arn = task_def["taskDefinitionArn"]
|
52
|
+
rescue Fog::AWS::ECS::Error => e
|
53
|
+
msg = 'ClientException => TaskDefinition not found.'
|
54
|
+
raise Fog::AWS::ECS::Error, msg
|
55
|
+
end
|
56
|
+
|
57
|
+
if %w(count overrides).any? { |k| params.has_key?(k) }
|
58
|
+
Fog::Logger.warning("you used parameters not mocked yet [light_black](#{caller.first})[/]")
|
59
|
+
Fog::Mock.not_implemented
|
60
|
+
end
|
61
|
+
|
62
|
+
cluster_id = params.delete('cluster') || 'default'
|
63
|
+
cluster_arn = nil
|
64
|
+
owner_id = Fog::AWS::Mock.owner_id
|
65
|
+
|
66
|
+
if cluster_id.match(/^arn:aws:ecs:.+:\d{1,12}:cluster\/(.+)$/)
|
67
|
+
cluster_arn = cluster_id
|
68
|
+
else
|
69
|
+
cluster_path = "cluster/#{cluster_id}"
|
70
|
+
cluster_arn = Fog::AWS::Mock.arn('ecs', owner_id, cluster_path, region)
|
71
|
+
end
|
72
|
+
|
73
|
+
task_path = "task/#{UUID.uuid}"
|
74
|
+
task_arn = Fog::AWS::Mock.arn('ecs', owner_id, task_path, region)
|
75
|
+
instance_path = "container-instance/#{UUID.uuid}"
|
76
|
+
container_instance_arn = Fog::AWS::Mock.arn('ecs', owner_id, instance_path, region)
|
77
|
+
|
78
|
+
containers = []
|
79
|
+
task_def["containerDefinitions"].each do |c|
|
80
|
+
container_path = "container/#{UUID.uuid}"
|
81
|
+
containers << {
|
82
|
+
'name' => c['name'],
|
83
|
+
'taskArn' => task_arn,
|
84
|
+
'lastStatus' => 'PENDING',
|
85
|
+
'containerArn' => Fog::AWS::Mock.arn('ecs', owner_id, container_path, region)
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
task = {
|
90
|
+
'clusterArn' => cluster_arn,
|
91
|
+
'desiredStatus' => 'RUNNING',
|
92
|
+
'taskDefinitionArn' => task_def_arn,
|
93
|
+
'lastStatus' => 'PENDING',
|
94
|
+
'taskArn' => task_arn,
|
95
|
+
'containerInstanceArn' => container_instance_arn,
|
96
|
+
'containers' => containers
|
97
|
+
}
|
98
|
+
self.data[:tasks] << task
|
99
|
+
|
100
|
+
response.body = {
|
101
|
+
'RunTaskResult' => {
|
102
|
+
'failures' => [],
|
103
|
+
'tasks' => [] << task
|
104
|
+
},
|
105
|
+
'ResponseMetadata' => {
|
106
|
+
'RequestId' => Fog::AWS::Mock.request_id
|
107
|
+
}
|
108
|
+
}
|
109
|
+
response
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class ECS
|
4
|
+
class Real
|
5
|
+
require 'fog/aws/parsers/ecs/start_task'
|
6
|
+
|
7
|
+
# Starts a new task from the specified task definition on the specified container instance or instances.
|
8
|
+
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_StartTask.html
|
9
|
+
# ==== Parameters
|
10
|
+
# * cluster <~String> - short name or full Amazon Resource Name (ARN) of the cluster that you want to start your task on.
|
11
|
+
# * containerInstances <~Array> - container instance UUIDs or full ARN entries for the container instances on which you would like to place your task.
|
12
|
+
# * overrides <~Hash> - list of container overrides.
|
13
|
+
# * startedBy <~String> - optional tag specified when a task is started
|
14
|
+
# * taskDefinition <~String> - family and revision (family:revision) or full ARN of the task definition that you want to start.
|
15
|
+
# ==== Returns
|
16
|
+
# * response<~Excon::Response>:
|
17
|
+
# * body<~Hash>:
|
18
|
+
# * 'tasks' <~Array> - full description of the tasks that were started.
|
19
|
+
# * 'failures' <~Array> - Any failed tasks from your StartTask action are listed here.
|
20
|
+
def start_task(params={})
|
21
|
+
if container_instances = params.delete('containerInstances')
|
22
|
+
params.merge!(Fog::AWS.indexed_param('containerInstances.member', [*container_instances]))
|
23
|
+
end
|
24
|
+
|
25
|
+
if overrides = params.delete('overrides')
|
26
|
+
serialized_overrides = {}
|
27
|
+
if overrides.is_a?(Hash)
|
28
|
+
overrides.each_pair do |k,v|
|
29
|
+
serialized_overrides.merge!(Fog::AWS.serialize_keys(k, v))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
params.merge!('overrides' => serialized_overrides)
|
33
|
+
end
|
34
|
+
|
35
|
+
request({
|
36
|
+
'Action' => 'StartTask',
|
37
|
+
:parser => Fog::Parsers::AWS::ECS::StartTask.new
|
38
|
+
}.merge(params))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Mock
|
43
|
+
def start_task(params={})
|
44
|
+
response = Excon::Response.new
|
45
|
+
response.status = 200
|
46
|
+
|
47
|
+
unless task_def_id = params.delete('taskDefinition')
|
48
|
+
msg = 'ClientException => TaskDefinition cannot be empty.'
|
49
|
+
raise Fog::AWS::ECS::Error, msg
|
50
|
+
end
|
51
|
+
|
52
|
+
unless instances_id = params.delete('containerInstances')
|
53
|
+
msg = 'ClientException => Container instances cannot be empty.'
|
54
|
+
raise Fog::AWS::ECS::Error, msg
|
55
|
+
end
|
56
|
+
|
57
|
+
begin
|
58
|
+
result = describe_task_definition('taskDefinition' => task_def_id).body
|
59
|
+
task_def = result["DescribeTaskDefinitionResult"]["taskDefinition"]
|
60
|
+
task_def_arn = task_def["taskDefinitionArn"]
|
61
|
+
rescue Fog::AWS::ECS::Error => e
|
62
|
+
msg = 'ClientException => TaskDefinition not found.'
|
63
|
+
raise Fog::AWS::ECS::Error, msg
|
64
|
+
end
|
65
|
+
|
66
|
+
if %w(startedBy overrides).any? { |k| params.has_key?(k) }
|
67
|
+
Fog::Logger.warning("you used parameters not mocked yet [light_black](#{caller.first})[/]")
|
68
|
+
Fog::Mock.not_implemented
|
69
|
+
end
|
70
|
+
|
71
|
+
cluster_id = params.delete('cluster') || 'default'
|
72
|
+
cluster_arn = nil
|
73
|
+
owner_id = Fog::AWS::Mock.owner_id
|
74
|
+
|
75
|
+
if cluster_id.match(/^arn:aws:ecs:.+:\d{1,12}:cluster\/(.+)$/)
|
76
|
+
cluster_arn = cluster_id
|
77
|
+
else
|
78
|
+
cluster_path = "cluster/#{cluster_id}"
|
79
|
+
cluster_arn = Fog::AWS::Mock.arn('ecs', owner_id, cluster_path, region)
|
80
|
+
end
|
81
|
+
|
82
|
+
task_path = "task/#{UUID.uuid}"
|
83
|
+
task_arn = Fog::AWS::Mock.arn('ecs', owner_id, task_path, region)
|
84
|
+
instance_path = "container-instance/#{UUID.uuid}"
|
85
|
+
|
86
|
+
instance_id = [*instances_id].first
|
87
|
+
if instance_id.match(/^arn:aws:ecs:.+:\d{1,12}:container-instance\/(.+)$/)
|
88
|
+
container_instance_arn = instance_id
|
89
|
+
else
|
90
|
+
instance_path = "container-instance/#{instance_id}"
|
91
|
+
container_instance_arn = Fog::AWS::Mock.arn('ecs', owner_id, instance_path, region)
|
92
|
+
end
|
93
|
+
|
94
|
+
containers = []
|
95
|
+
task_def["containerDefinitions"].each do |c|
|
96
|
+
container_path = "container/#{UUID.uuid}"
|
97
|
+
containers << {
|
98
|
+
'name' => c['name'],
|
99
|
+
'taskArn' => task_arn,
|
100
|
+
'lastStatus' => 'PENDING',
|
101
|
+
'containerArn' => Fog::AWS::Mock.arn('ecs', owner_id, container_path, region)
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
task = {
|
106
|
+
'clusterArn' => cluster_arn,
|
107
|
+
'desiredStatus' => 'RUNNING',
|
108
|
+
'taskDefinitionArn' => task_def_arn,
|
109
|
+
'lastStatus' => 'PENDING',
|
110
|
+
'taskArn' => task_arn,
|
111
|
+
'containerInstanceArn' => container_instance_arn,
|
112
|
+
'containers' => containers
|
113
|
+
}
|
114
|
+
self.data[:tasks] << task
|
115
|
+
|
116
|
+
response.body = {
|
117
|
+
'StartTaskResult' => {
|
118
|
+
'failures' => [],
|
119
|
+
'tasks' => [] << task
|
120
|
+
},
|
121
|
+
'ResponseMetadata' => {
|
122
|
+
'RequestId' => Fog::AWS::Mock.request_id
|
123
|
+
}
|
124
|
+
}
|
125
|
+
response
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class ECS
|
4
|
+
class Real
|
5
|
+
require 'fog/aws/parsers/ecs/stop_task'
|
6
|
+
|
7
|
+
# Stops a running task.
|
8
|
+
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_StopTask.html
|
9
|
+
# ==== Parameters
|
10
|
+
# * cluster <~String> - short name or full Amazon Resource Name (ARN) of the cluster that hosts the task you want to stop.
|
11
|
+
# * task <~String> - task UUIDs or full Amazon Resource Name (ARN) entry of the task you would like to stop.
|
12
|
+
# ==== Returns
|
13
|
+
# * response<~Excon::Response>:
|
14
|
+
# * body<~Hash>:
|
15
|
+
# * 'Task' <~Hash> - The full description of the stopped task.
|
16
|
+
def stop_task(params={})
|
17
|
+
request({
|
18
|
+
'Action' => 'StopTask',
|
19
|
+
:parser => Fog::Parsers::AWS::ECS::StopTask.new
|
20
|
+
}.merge(params))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class Mock
|
25
|
+
def stop_task(params={})
|
26
|
+
response = Excon::Response.new
|
27
|
+
response.status = 200
|
28
|
+
|
29
|
+
unless task_id = params.delete('task')
|
30
|
+
msg = "InvalidParameterException => Task can not be blank."
|
31
|
+
raise Fog::AWS::ECS::Error, msg
|
32
|
+
end
|
33
|
+
|
34
|
+
if cluster = params.delete('cluster')
|
35
|
+
Fog::Logger.warning("you used parameters not mocked yet [light_black](#{caller.first})[/]")
|
36
|
+
end
|
37
|
+
|
38
|
+
if match = task_id.match(/^arn:aws:ecs:.+:\d{1,12}:task\/(.+)$/)
|
39
|
+
i = self.data[:tasks].index { |t| t['taskArn'].eql?(task_id) }
|
40
|
+
else
|
41
|
+
i = self.data[:tasks].index { |t| t['taskArn'].match(/#{task_id}$/) }
|
42
|
+
end
|
43
|
+
|
44
|
+
msg = "ClientException => The referenced task was not found."
|
45
|
+
raise Fog::AWS::ECS::Error, msg unless i
|
46
|
+
|
47
|
+
task = self.data[:tasks][i]
|
48
|
+
task['desiredStatus'] = 'STOPPED'
|
49
|
+
self.data[:tasks].delete_at(i)
|
50
|
+
|
51
|
+
response.body = {
|
52
|
+
'StopTaskResult' => {
|
53
|
+
'task' => task
|
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,81 @@
|
|
1
|
+
module Fog
|
2
|
+
module AWS
|
3
|
+
class ECS
|
4
|
+
class Real
|
5
|
+
require 'fog/aws/parsers/ecs/update_service'
|
6
|
+
|
7
|
+
# Modify the desired count or task definition used in a service.
|
8
|
+
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_UpdateService.html
|
9
|
+
# ==== Parameters
|
10
|
+
# * cluster <~String> - short name or full Amazon Resource Name (ARN) of the cluster that your service is running on.
|
11
|
+
# * desiredCount <~Integer> - number of instantiations of the task that you would like to place and keep running in your service.
|
12
|
+
# * service <~String> - name of the service that you want to update.
|
13
|
+
# * taskDefinition <~String> - family and revision (family:revision) or full Amazon Resource Name (ARN) of the task definition that you want to run in your service.
|
14
|
+
# ==== Returns
|
15
|
+
# * response<~Excon::Response>:
|
16
|
+
# * body<~Hash>:
|
17
|
+
# * 'Service'<~Hash> - The full description of the updated cluster
|
18
|
+
def update_service(params={})
|
19
|
+
request({
|
20
|
+
'Action' => 'UpdateService',
|
21
|
+
:parser => Fog::Parsers::AWS::ECS::UpdateService.new
|
22
|
+
}.merge(params))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Mock
|
27
|
+
def update_service(params={})
|
28
|
+
response = Excon::Response.new
|
29
|
+
response.status = 200
|
30
|
+
|
31
|
+
service_id = params.delete('service')
|
32
|
+
msg = 'ClientException => Service cannot be empty.'
|
33
|
+
raise Fog::AWS::ECS::Error, msg unless service_id
|
34
|
+
|
35
|
+
owner_id = Fog::AWS::Mock.owner_id
|
36
|
+
|
37
|
+
cluster = params.delete('cluster') || 'default'
|
38
|
+
if !cluster.match(/^arn:aws:ecs:.+:.+:cluster\/(.+)$/)
|
39
|
+
cluster_path = "cluster/#{cluster}"
|
40
|
+
cluster_arn = Fog::AWS::Mock.arn('ecs', owner_id, cluster_path, region)
|
41
|
+
else
|
42
|
+
cluster_arn = cluster
|
43
|
+
end
|
44
|
+
|
45
|
+
if match = service_id.match(/^arn:aws:ecs:.+:\d{1,12}:service\/(.+)$/)
|
46
|
+
i = self.data[:services].index do |s|
|
47
|
+
s['clusterArn'].eql?(cluster_arn) && s['serviceArn'].eql?(service_id)
|
48
|
+
end
|
49
|
+
else
|
50
|
+
i = self.data[:services].index do |s|
|
51
|
+
s['clusterArn'].eql?(cluster_arn) && s['serviceName'].eql?(service_id)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
msg = "ServiceNotFoundException => Service not found."
|
56
|
+
raise Fog::AWS::ECS::Error, msg unless i
|
57
|
+
|
58
|
+
service = self.data[:services][i]
|
59
|
+
|
60
|
+
if desired_count = params.delete('desiredCount')
|
61
|
+
# ignore
|
62
|
+
end
|
63
|
+
|
64
|
+
if task_definition = params.delete('taskDefinition')
|
65
|
+
service['taskDefinition'] = task_definition
|
66
|
+
end
|
67
|
+
|
68
|
+
response.body = {
|
69
|
+
'UpdateServiceResult' => {
|
70
|
+
'service' => service
|
71
|
+
},
|
72
|
+
'ResponseMetadata' => {
|
73
|
+
'RequestId' => Fog::AWS::Mock.request_id
|
74
|
+
}
|
75
|
+
}
|
76
|
+
response
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|