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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fog/aws.rb +2 -0
  3. data/lib/fog/aws/ecs.rb +187 -0
  4. data/lib/fog/aws/models/compute/flavors.rb +10 -0
  5. data/lib/fog/aws/parsers/ecs/base.rb +28 -0
  6. data/lib/fog/aws/parsers/ecs/container_instance.rb +75 -0
  7. data/lib/fog/aws/parsers/ecs/create_cluster.rb +30 -0
  8. data/lib/fog/aws/parsers/ecs/create_service.rb +31 -0
  9. data/lib/fog/aws/parsers/ecs/delete_cluster.rb +30 -0
  10. data/lib/fog/aws/parsers/ecs/delete_service.rb +31 -0
  11. data/lib/fog/aws/parsers/ecs/deregister_container_instance.rb +31 -0
  12. data/lib/fog/aws/parsers/ecs/deregister_task_definition.rb +32 -0
  13. data/lib/fog/aws/parsers/ecs/describe_clusters.rb +55 -0
  14. data/lib/fog/aws/parsers/ecs/describe_container_instances.rb +38 -0
  15. data/lib/fog/aws/parsers/ecs/describe_services.rb +24 -0
  16. data/lib/fog/aws/parsers/ecs/describe_task_definition.rb +32 -0
  17. data/lib/fog/aws/parsers/ecs/describe_tasks.rb +24 -0
  18. data/lib/fog/aws/parsers/ecs/list_clusters.rb +27 -0
  19. data/lib/fog/aws/parsers/ecs/list_container_instances.rb +27 -0
  20. data/lib/fog/aws/parsers/ecs/list_services.rb +27 -0
  21. data/lib/fog/aws/parsers/ecs/list_task_definition_families.rb +27 -0
  22. data/lib/fog/aws/parsers/ecs/list_task_definitions.rb +27 -0
  23. data/lib/fog/aws/parsers/ecs/list_tasks.rb +27 -0
  24. data/lib/fog/aws/parsers/ecs/register_task_definition.rb +32 -0
  25. data/lib/fog/aws/parsers/ecs/run_task.rb +24 -0
  26. data/lib/fog/aws/parsers/ecs/service.rb +82 -0
  27. data/lib/fog/aws/parsers/ecs/start_task.rb +24 -0
  28. data/lib/fog/aws/parsers/ecs/stop_task.rb +23 -0
  29. data/lib/fog/aws/parsers/ecs/task.rb +77 -0
  30. data/lib/fog/aws/parsers/ecs/task_definition.rb +95 -0
  31. data/lib/fog/aws/parsers/ecs/update_service.rb +31 -0
  32. data/lib/fog/aws/requests/compute/create_vpc.rb +1 -1
  33. data/lib/fog/aws/requests/ecs/create_cluster.rb +64 -0
  34. data/lib/fog/aws/requests/ecs/create_service.rb +118 -0
  35. data/lib/fog/aws/requests/ecs/delete_cluster.rb +61 -0
  36. data/lib/fog/aws/requests/ecs/delete_service.rb +72 -0
  37. data/lib/fog/aws/requests/ecs/deregister_container_instance.rb +63 -0
  38. data/lib/fog/aws/requests/ecs/deregister_task_definition.rb +58 -0
  39. data/lib/fog/aws/requests/ecs/describe_clusters.rb +83 -0
  40. data/lib/fog/aws/requests/ecs/describe_container_instances.rb +64 -0
  41. data/lib/fog/aws/requests/ecs/describe_services.rb +76 -0
  42. data/lib/fog/aws/requests/ecs/describe_task_definition.rb +64 -0
  43. data/lib/fog/aws/requests/ecs/describe_tasks.rb +65 -0
  44. data/lib/fog/aws/requests/ecs/list_clusters.rb +45 -0
  45. data/lib/fog/aws/requests/ecs/list_container_instances.rb +46 -0
  46. data/lib/fog/aws/requests/ecs/list_services.rb +59 -0
  47. data/lib/fog/aws/requests/ecs/list_task_definition_families.rb +56 -0
  48. data/lib/fog/aws/requests/ecs/list_task_definitions.rb +55 -0
  49. data/lib/fog/aws/requests/ecs/list_tasks.rb +50 -0
  50. data/lib/fog/aws/requests/ecs/register_task_definition.rb +68 -0
  51. data/lib/fog/aws/requests/ecs/run_task.rb +114 -0
  52. data/lib/fog/aws/requests/ecs/start_task.rb +130 -0
  53. data/lib/fog/aws/requests/ecs/stop_task.rb +64 -0
  54. data/lib/fog/aws/requests/ecs/update_service.rb +81 -0
  55. data/lib/fog/aws/version.rb +1 -1
  56. data/tests/requests/compute/vpc_tests.rb +7 -0
  57. data/tests/requests/ecs/cluster_tests.rb +112 -0
  58. data/tests/requests/ecs/container_instance_tests.rb +119 -0
  59. data/tests/requests/ecs/helper.rb +276 -0
  60. data/tests/requests/ecs/sample_task_definition1.json +56 -0
  61. data/tests/requests/ecs/service_tests.rb +132 -0
  62. data/tests/requests/ecs/task_definitions_tests.rb +97 -0
  63. data/tests/requests/ecs/task_tests.rb +145 -0
  64. metadata +59 -2
@@ -0,0 +1,64 @@
1
+ module Fog
2
+ module AWS
3
+ class ECS
4
+ class Real
5
+ require 'fog/aws/parsers/ecs/describe_task_definition'
6
+
7
+ # Describes a task definition
8
+ # http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeTaskDefinition.html
9
+ # ==== Parameters
10
+ # * taskDefinition <~String> - The family for the latest revision, family and revision (family:revision) for a specific revision in the family, or full Amazon Resource Name (ARN) of the task definition that you want to describe.
11
+ # ==== Returns
12
+ # * response<~Excon::Response>:
13
+ # * body<~Hash>:
14
+ # * 'taskDefinition' <~Hash> - full task definition description
15
+ def describe_task_definition(params={})
16
+ request({
17
+ 'Action' => 'DescribeTaskDefinition',
18
+ :parser => Fog::Parsers::AWS::ECS::DescribeTaskDefinition.new
19
+ }.merge(params))
20
+ end
21
+ end
22
+
23
+ class Mock
24
+ def describe_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
+ result = self.data[:task_definitions].select { |t| t['taskDefinitionArn'].eql?(task_def_name) }
36
+ when /^(.+:.+)$/
37
+ result = self.data[:task_definitions].select { |t| t['taskDefinitionArn'].match(/task-definition\/#{task_def_name}/) }
38
+ else
39
+ result = self.data[:task_definitions].select { |t| t['family'].eql?(task_def_name) }
40
+ if !result.empty?
41
+ result = [] << (result.max_by { |t| t['revision'] })
42
+ end
43
+ end
44
+
45
+ if result.empty?
46
+ raise Fog::AWS::ECS::Error, 'ClientException => Unable to describe task definition.'
47
+ end
48
+
49
+ task_definition = result.first
50
+
51
+ response.body = {
52
+ 'DescribeTaskDefinitionResult' => {
53
+ 'taskDefinition' => task_definition
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,65 @@
1
+ module Fog
2
+ module AWS
3
+ class ECS
4
+ class Real
5
+ require 'fog/aws/parsers/ecs/describe_tasks'
6
+
7
+ # Describes a specified task or tasks.
8
+ # http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeTasks.html
9
+ # ==== Parameters
10
+ # * cluster <~String> - short name or full Amazon Resource Name (ARN) of the cluster that hosts the task you want to describe
11
+ # * tasks <~Array> - space-separated list of task UUIDs or full Amazon Resource Name (ARN) entries
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * body<~Hash>:
15
+ # * 'tasks' <~Array> - The list of tasks
16
+ # * 'failures' <~Array> - The list of failures (if any)
17
+ def describe_tasks(params={})
18
+ if tasks = params.delete('tasks')
19
+ params.merge!(Fog::AWS.indexed_param('tasks.member', [*tasks]))
20
+ end
21
+
22
+ request({
23
+ 'Action' => 'DescribeTasks',
24
+ :parser => Fog::Parsers::AWS::ECS::DescribeTasks.new
25
+ }.merge(params))
26
+ end
27
+ end
28
+
29
+ class Mock
30
+ def describe_tasks(params={})
31
+ response = Excon::Response.new
32
+ response.status = 200
33
+
34
+ unless tasks = params.delete('tasks')
35
+ msg = 'InvalidParameterException => Tasks cannot be empty.'
36
+ raise Fog::AWS::ECS::Error, msg
37
+ end
38
+
39
+ cluster = params.delete('cluster') || 'default'
40
+
41
+ result = []
42
+ [*tasks].each do |tid|
43
+ if match = tid.match(/^arn:aws:ecs:.+:\d{1,12}:task\/(.+)$/)
44
+ result = self.data[:tasks].select { |t| t['taskArn'].eql?(tid) }
45
+ else
46
+ result = self.data[:tasks].select { |t| t['taskArn'].match(/#{tid}$/) }
47
+ end
48
+ end
49
+
50
+ tasks = result
51
+ response.body = {
52
+ 'DescribeTasksResult' => {
53
+ 'failures' => [],
54
+ 'tasks' => tasks
55
+ },
56
+ 'ResponseMetadata' => {
57
+ 'RequestId' => Fog::AWS::Mock.request_id
58
+ }
59
+ }
60
+ response
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,45 @@
1
+ module Fog
2
+ module AWS
3
+ class ECS
4
+ class Real
5
+ require 'fog/aws/parsers/ecs/list_clusters'
6
+
7
+ # Returns a list of existing clusters
8
+ # http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListClusters.html
9
+ # ==== Parameters
10
+ # * maxResults <~Integer> - The maximum number of cluster results returned by ListClusters in paginated output.
11
+ # * nextToken <~String> - The nextToken value returned from a previous paginated ListClusters request where maxResults was used.
12
+ # ==== Returns
13
+ # * response<~Excon::Response>:
14
+ # * body<~Hash>:
15
+ # * 'ClusterArns' <~Array> - list of full Amazon Resource Name (ARN) entries for each cluster associated with your account.
16
+ # * 'NextToken' <~String> - nextToken value to include in a future ListClusters request.
17
+ def list_clusters(params={})
18
+ request({
19
+ 'Action' => 'ListClusters',
20
+ :parser => Fog::Parsers::AWS::ECS::ListClusters.new
21
+ }.merge(params))
22
+ end
23
+ end
24
+
25
+ class Mock
26
+ def list_clusters(params={})
27
+ response = Excon::Response.new
28
+ response.status = 200
29
+
30
+ cluster_arns = self.data[:clusters].map { |c| c['clusterArn'] }
31
+
32
+ response.body = {
33
+ 'ListClustersResult' => {
34
+ 'clusterArns' => cluster_arns
35
+ },
36
+ 'ResponseMetadata' => {
37
+ 'RequestId' => Fog::AWS::Mock.request_id
38
+ }
39
+ }
40
+ response
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,46 @@
1
+ module Fog
2
+ module AWS
3
+ class ECS
4
+ class Real
5
+ require 'fog/aws/parsers/ecs/list_container_instances'
6
+
7
+ # Returns a list of container instances in a specified cluster.
8
+ # http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListContainerInstances.html
9
+ # ==== Parameters
10
+ # * cluster <~String> - short name or full Amazon Resource Name (ARN) of the cluster that hosts the container instances you want to list.
11
+ # * maxResults <~Integer> - maximum number of container instance results returned by ListContainerInstances in paginated output.
12
+ # * nextToken <~String> - nextToken value returned from a previous paginated ListContainerInstances request where maxResults was used.
13
+ # ==== Returns
14
+ # * response<~Excon::Response>:
15
+ # * body<~Hash>:
16
+ # * 'ContainerInstanceArns' <~Array> - list of container instance full ARN entries for each container instance associated with the specified cluster.
17
+ # * 'NextToken' <~String> - nextToken value to include in a future ListContainerInstances request.
18
+ def list_container_instances(params={})
19
+ request({
20
+ 'Action' => 'ListContainerInstances',
21
+ :parser => Fog::Parsers::AWS::ECS::ListContainerInstances.new
22
+ }.merge(params))
23
+ end
24
+ end
25
+
26
+ class Mock
27
+ def list_container_instances(params={})
28
+ response = Excon::Response.new
29
+ response.status = 200
30
+
31
+ instance_arns = self.data[:container_instances].map { |i| i['containerInstanceArn'] }
32
+
33
+ response.body = {
34
+ 'ListContainerInstancesResult' => {
35
+ 'containerInstanceArns' => instance_arns
36
+ },
37
+ 'ResponseMetadata' => {
38
+ 'RequestId' => Fog::AWS::Mock.request_id
39
+ }
40
+ }
41
+ response
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,59 @@
1
+ module Fog
2
+ module AWS
3
+ class ECS
4
+ class Real
5
+ require 'fog/aws/parsers/ecs/list_services'
6
+
7
+ # Lists the services that are running in a specified cluster.
8
+ # http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListServices.html
9
+ # ==== Parameters
10
+ # * cluster <~String> - The short name or full Amazon Resource Name (ARN) of the cluster that hosts the services you want to list.
11
+ # * maxResults <~Integer> - The maximum number of container instance results returned by ListServices in paginated output.
12
+ # * nextToken <~String> - The nextToken value returned from a previous paginated ListServices request where maxResults was used.
13
+ # ==== Returns
14
+ # * response<~Excon::Response>:
15
+ # * body<~Hash>:
16
+ # * 'ServiceArns' <~Array> - list of full Amazon Resource Name (ARN) entries for each service associated with the specified cluster.
17
+ # * 'NextToken' <~String> - nextToken value to include in a future ListServices request.
18
+ def list_services(params={})
19
+ request({
20
+ 'Action' => 'ListServices',
21
+ :parser => Fog::Parsers::AWS::ECS::ListServices.new
22
+ }.merge(params))
23
+ end
24
+ end
25
+
26
+ class Mock
27
+ def list_services(params={})
28
+ response = Excon::Response.new
29
+ response.status = 200
30
+
31
+ owner_id = Fog::AWS::Mock.owner_id
32
+
33
+ cluster = params.delete('cluster') || 'default'
34
+ if !cluster.match(/^arn:aws:ecs:.+:.+:cluster\/(.+)$/)
35
+ cluster_path = "cluster/#{cluster}"
36
+ cluster_arn = Fog::AWS::Mock.arn('ecs', owner_id, cluster_path, region)
37
+ else
38
+ cluster_arn = cluster
39
+ end
40
+
41
+ result = self.data[:services].select do |s|
42
+ s['clusterArn'].eql?(cluster_arn)
43
+ end
44
+ service_arns = result.map { |s| s['serviceArn'] }
45
+
46
+ response.body = {
47
+ 'ListServicesResult' => {
48
+ 'serviceArns' => service_arns
49
+ },
50
+ 'ResponseMetadata' => {
51
+ 'RequestId' => Fog::AWS::Mock.request_id
52
+ }
53
+ }
54
+ response
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,56 @@
1
+ module Fog
2
+ module AWS
3
+ class ECS
4
+ class Real
5
+ require 'fog/aws/parsers/ecs/list_task_definition_families'
6
+
7
+ # Returns a list of task definition families that are registered to your account.
8
+ # http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListTaskDefinitionFamilies.html
9
+ # ==== Parameters
10
+ # * familyPrefix <~String> - familyPrefix is a string that is used to filter the results of ListTaskDefinitionFamilies.
11
+ # * maxResults <~Integer> - maximum number of task definition family results returned by ListTaskDefinitionFamilies in paginated output.
12
+ # * nextToken <~String> - nextToken value returned from a previous paginated ListTaskDefinitionFamilies request where maxResults was used.
13
+ # ==== Returns
14
+ # * response<~Excon::Response>:
15
+ # * body<~Hash>:
16
+ # * 'Families' <~Array> - list of task definition family names that match the ListTaskDefinitionFamilies request.
17
+ # * 'NextToken' <~String> - nextToken value to include in a future ListTaskDefinitionFamilies request.
18
+ def list_task_definition_families(params={})
19
+ request({
20
+ 'Action' => 'ListTaskDefinitionFamilies',
21
+ :parser => Fog::Parsers::AWS::ECS::ListTaskDefinitionFamilies.new
22
+ }.merge(params))
23
+ end
24
+ end
25
+
26
+ class Mock
27
+ def list_task_definition_families(params={})
28
+ response = Excon::Response.new
29
+ response.status = 200
30
+
31
+ family_prefix = params['familyPrefix']
32
+
33
+ if family_prefix
34
+ result = self.data[:task_definitions].select do |t|
35
+ t['family'].match(/^#{family_prefix}/)
36
+ end
37
+ else
38
+ result = self.data[:task_definitions].dup
39
+ end
40
+ result.map! { |t| t['family'] }
41
+ result.uniq!
42
+
43
+ response.body = {
44
+ 'ListTaskDefinitionFamiliesResult' => {
45
+ 'families' => result
46
+ },
47
+ 'ResponseMetadata' => {
48
+ 'RequestId' => Fog::AWS::Mock.request_id
49
+ }
50
+ }
51
+ response
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,55 @@
1
+ module Fog
2
+ module AWS
3
+ class ECS
4
+ class Real
5
+ require 'fog/aws/parsers/ecs/list_task_definitions'
6
+
7
+ # Returns a list of task definitions that are registered to your account
8
+ # http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListTaskDefinitions.html
9
+ # ==== Parameters
10
+ # * familyPrefix <~String> - The full family name that you want to filter the ListTaskDefinitions results with.
11
+ # * maxResults <~Integer> - The maximum number of task definition results returned by ListTaskDefinitions in paginated output.
12
+ # * nextToken <~String> - The nextToken value returned from a previous paginated ListTaskDefinitions request.
13
+ # ==== Returns
14
+ # * response<~Excon::Response>:
15
+ # * body<~Hash>:
16
+ # * 'TaskDefinitionArns' <~Array> - list of task definition Amazon Resource Name (ARN) entries for the ListTaskDefintions request.
17
+ # * 'NextToken' <~String> - nextToken value to include in a future ListTaskDefinitions request
18
+ def list_task_definitions(params={})
19
+ request({
20
+ 'Action' => 'ListTaskDefinitions',
21
+ :parser => Fog::Parsers::AWS::ECS::ListTaskDefinitions.new
22
+ }.merge(params))
23
+ end
24
+ end
25
+
26
+ class Mock
27
+ def list_task_definitions(params={})
28
+ if %w(
29
+ familyPrefix
30
+ maxResults
31
+ nextToken
32
+ ).any? { |k| params.has_key?(k) }
33
+ Fog::Logger.warning("list_task_definitions filters are not yet mocked [light_black](#{caller.first})[/]")
34
+ Fog::Mock.not_implemented
35
+ end
36
+
37
+ response = Excon::Response.new
38
+ response.status = 200
39
+
40
+ taskdef_arns = self.data[:task_definitions].map { |c| c['taskDefinitionArn'] }
41
+
42
+ response.body = {
43
+ 'ListTaskDefinitionsResult' => {
44
+ 'taskDefinitionArns' => taskdef_arns
45
+ },
46
+ 'ResponseMetadata' => {
47
+ 'RequestId' => Fog::AWS::Mock.request_id
48
+ }
49
+ }
50
+ response
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,50 @@
1
+ module Fog
2
+ module AWS
3
+ class ECS
4
+ class Real
5
+ require 'fog/aws/parsers/ecs/list_tasks'
6
+
7
+ # Returns a list of tasks for a specified cluster.
8
+ # http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListTasks.html
9
+ # ==== Parameters
10
+ # * cluster <~String> - short name or full Amazon Resource Name (ARN) of the cluster that hosts the tasks you want to list.
11
+ # * containerInstance <~String> - container instance UUID or full Amazon Resource Name (ARN) of the container instance that you want to filter the ListTasks results with.
12
+ # * family <~String> - name of the family that you want to filter the ListTasks results with.
13
+ # * maxResults <~Integer> - maximum number of task results returned by ListTasks in paginated output.
14
+ # * nextToken <~String> - nextToken value returned from a previous paginated ListTasks request where maxResults was used.
15
+ # * serviceName <~String> - name of the service that you want to filter the ListTasks results with.
16
+ # * startedBy <~String> - startedBy value that you want to filter the task results with.
17
+ # ==== Returns
18
+ # * response<~Excon::Response>:
19
+ # * body<~Hash>:
20
+ # * 'TaskArns' <~Array> - list of task Amazon Resource Name (ARN) entries for the ListTasks request.
21
+ # * 'NextToken' <~String> - nextToken value to include in a future ListTasks request.
22
+ def list_tasks(params={})
23
+ request({
24
+ 'Action' => 'ListTasks',
25
+ :parser => Fog::Parsers::AWS::ECS::ListTasks.new
26
+ }.merge(params))
27
+ end
28
+ end
29
+
30
+ class Mock
31
+ def list_tasks(params={})
32
+ response = Excon::Response.new
33
+ response.status = 200
34
+
35
+ task_arns = self.data[:tasks].map { |t| t['taskArn'] }
36
+
37
+ response.body = {
38
+ 'ListTasksResult' => {
39
+ 'taskArns' => task_arns
40
+ },
41
+ 'ResponseMetadata' => {
42
+ 'RequestId' => Fog::AWS::Mock.request_id
43
+ }
44
+ }
45
+ response
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end