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.
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,24 @@
1
+ module Fog
2
+ module Parsers
3
+ module AWS
4
+ module ECS
5
+ require 'fog/aws/parsers/ecs/task'
6
+
7
+ class RunTask < Fog::Parsers::AWS::ECS::Task
8
+ def reset
9
+ super
10
+ @result = 'RunTaskResult'
11
+ @response[@result] = {'failures' => [], 'tasks' => []}
12
+ @contexts = %w(failures tasks containers overrides networkBindings containerOverrides)
13
+ @context = []
14
+ @task = {}
15
+ @failure = {}
16
+ @container = {}
17
+ @net_binding = {}
18
+ @container_overrides = []
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,82 @@
1
+ module Fog
2
+ module Parsers
3
+ module AWS
4
+ module ECS
5
+ require 'fog/aws/parsers/ecs/base'
6
+
7
+ class Service < Fog::Parsers::AWS::ECS::Base
8
+ def start_element(name, attrs = [])
9
+ super
10
+ if @contexts.include?(name)
11
+ @context.push(name)
12
+ end
13
+ end
14
+
15
+ def end_element(name)
16
+ super
17
+ case name
18
+ when *@contexts
19
+ @context.pop
20
+ when 'member'
21
+ case @context.last
22
+ when 'services'
23
+ @response[@result]['services'] << @service
24
+ @service = {}
25
+ when 'loadBalancers'
26
+ @service['loadBalancers'] ||= []
27
+ @service['loadBalancers'] << @load_balancer
28
+ @load_balancer = {}
29
+ when 'events'
30
+ @service['events'] ||= []
31
+ @service['events'] << @event
32
+ @event = {}
33
+ when 'deployments'
34
+ @service['deployments'] ||= []
35
+ @service['deployments'] << @deployment
36
+ @deployment = {}
37
+ end
38
+ when 'clusterArn', 'roleArn', 'serviceArn', 'serviceName'
39
+ @service[name] = value
40
+ when 'taskDefinition', 'status'
41
+ case @context.last
42
+ when 'service', 'services'
43
+ @service[name] = value
44
+ when 'deployments'
45
+ @deployment[name] = value
46
+ end
47
+ when 'desiredCount', 'pendingCount', 'runningCount'
48
+ case @context.last
49
+ when 'service', 'services'
50
+ @service[name] = value.to_i
51
+ when 'deployments'
52
+ @deployment[name] = value.to_i
53
+ end
54
+ when 'loadBalancerName', 'containerName'
55
+ @load_balancer[name] = value
56
+ when 'containerPort'
57
+ @load_balancer[name] = value.to_i
58
+ when 'createdAt'
59
+ case @context.last
60
+ when 'events'
61
+ @event[name] = Time.parse(value)
62
+ when 'deployments'
63
+ @deployment[name] = Time.parse(value)
64
+ end
65
+ when 'id'
66
+ case @context.last
67
+ when 'events'
68
+ @event[name] = value
69
+ when 'deployments'
70
+ @deployment[name] = value
71
+ end
72
+ when 'message'
73
+ @event[name] = value
74
+ when 'updatedAt'
75
+ @deployment[name] = Time.parse(value)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,24 @@
1
+ module Fog
2
+ module Parsers
3
+ module AWS
4
+ module ECS
5
+ require 'fog/aws/parsers/ecs/task'
6
+
7
+ class StartTask < Fog::Parsers::AWS::ECS::Task
8
+ def reset
9
+ super
10
+ @result = 'StartTaskResult'
11
+ @response[@result] = {'failures' => [], 'tasks' => []}
12
+ @contexts = %w(failures tasks containers overrides networkBindings containerOverrides)
13
+ @context = []
14
+ @task = {}
15
+ @failure = {}
16
+ @container = {}
17
+ @net_binding = {}
18
+ @container_overrides = []
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ module Fog
2
+ module Parsers
3
+ module AWS
4
+ module ECS
5
+ require 'fog/aws/parsers/ecs/task'
6
+
7
+ class StopTask < Fog::Parsers::AWS::ECS::Task
8
+ def reset
9
+ super
10
+ @result = 'StopTaskResult'
11
+ @response[@result] = {'task' => {}}
12
+ @contexts = %w(task containers overrides networkBindings containerOverrides)
13
+ @context = []
14
+ @task = {}
15
+ @container = {}
16
+ @net_binding = {}
17
+ @container_overrides = []
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,77 @@
1
+ module Fog
2
+ module Parsers
3
+ module AWS
4
+ module ECS
5
+ require 'fog/aws/parsers/ecs/base'
6
+
7
+ class Task < Fog::Parsers::AWS::ECS::Base
8
+ def start_element(name, attrs = [])
9
+ super
10
+ if @contexts.include?(name)
11
+ @context.push(name)
12
+ end
13
+ end
14
+
15
+ def end_element(name)
16
+ super
17
+ case name
18
+ when 'containerOverrides'
19
+ @task['overrides'] ||= {}
20
+ @task['overrides'][name] = @container_overrides
21
+ @context.pop
22
+ when 'task'
23
+ @response[@result][name] = @task
24
+ when *@contexts
25
+ @context.pop
26
+ when 'member'
27
+ case @context.last
28
+ when 'tasks'
29
+ @response[@result]['tasks'] << @task
30
+ @task = {}
31
+ when 'containers'
32
+ @task['containers'] ||= []
33
+ @task['containers'] << @container
34
+ @container = {}
35
+ when 'networkBindings'
36
+ @container['networkBindings'] ||= []
37
+ @container['networkBindings'] << @net_binding
38
+ @net_binding = {}
39
+ when 'failures'
40
+ @response[@result]['failures'] << @failure
41
+ @failure = {}
42
+ end
43
+ when 'clusterArn', 'desiredStatus', 'startedBy', 'containerInstanceArn', 'taskDefinitionArn'
44
+ @task[name] = value
45
+ when 'taskArn', 'lastStatus'
46
+ case @context.last
47
+ when 'tasks'
48
+ @task[name] = value
49
+ when 'containers'
50
+ @container[name] = value
51
+ end
52
+ when 'containerArn'
53
+ @container[name] = value
54
+ when 'exitCode'
55
+ @container[name] = value.to_i
56
+ when 'name'
57
+ case @context.last
58
+ when 'containers'
59
+ @container[name] = value
60
+ when 'containerOverrides'
61
+ @container_overrides << value
62
+ end
63
+ when 'networkBindings'
64
+ @container[name] = @net_bindings
65
+ when 'bindIP'
66
+ @net_binding[name] = value
67
+ when 'hostPort', 'containerPort'
68
+ @net_binding[name] = value.to_i
69
+ when 'arn', 'reason'
70
+ @failure[name] = value
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,95 @@
1
+ module Fog
2
+ module Parsers
3
+ module AWS
4
+ module ECS
5
+ require 'fog/aws/parsers/ecs/base'
6
+
7
+ class TaskDefinition < Fog::Parsers::AWS::ECS::Base
8
+ def start_element(name, attrs = [])
9
+ super
10
+ if @contexts.include?(name)
11
+ @context.push(name)
12
+ end
13
+ end
14
+
15
+ def end_element(name)
16
+ super
17
+ case name
18
+ when 'taskDefinitionArn'
19
+ @response[@result][@definition][name] = value
20
+ when 'revision'
21
+ @response[@result][@definition][name] = value.to_i
22
+ when *@contexts
23
+ @context.pop
24
+ when 'member'
25
+ case @context.last
26
+ when 'volumes'
27
+ @response[@result][@definition]['volumes'] << @volume
28
+ @volume = {}
29
+ when 'containerDefinitions'
30
+ @response[@result][@definition]['containerDefinitions'] << @container
31
+ @container = {}
32
+ when 'command'
33
+ @container['command'] ||= []
34
+ @container['command'] << value
35
+ when 'entryPoint'
36
+ @container['entryPoint'] ||= []
37
+ @container['entryPoint'] << value
38
+ when 'links'
39
+ @container['links'] ||= []
40
+ @container['links'] << value
41
+ when 'environment'
42
+ @container['environment'] ||= []
43
+ @container['environment'] << @environment
44
+ @environment = {}
45
+ when 'mountPoints'
46
+ @container['mountPoints'] ||= []
47
+ @container['mountPoints'] << @mountpoint
48
+ @mountpoint = {}
49
+ when 'portMappings'
50
+ @container['portMappings'] ||= []
51
+ @container['portMappings'] << @portmapping
52
+ @portmapping = {}
53
+ end
54
+ when 'name'
55
+ case @context.last
56
+ when 'volumes'
57
+ @volume[name] = value
58
+ when 'containerDefinitions'
59
+ @container[name] = value
60
+ when 'environment'
61
+ @environment[name] = value
62
+ end
63
+ when 'host'
64
+ @volume[name] = @host
65
+ @host = {}
66
+ when 'sourcePath'
67
+ @host[name] = value
68
+ when 'cpu', 'memory'
69
+ @container[name] = value.to_i
70
+ when 'essential'
71
+ @container[name] = value == 'true'
72
+ when 'image'
73
+ @container[name] = value
74
+ when 'value'
75
+ @environment[name] = value
76
+ when 'readOnly'
77
+ case @context.last
78
+ when 'mountPoints'
79
+ @mountpoint[name] = value == 'true'
80
+ when 'volumesFrom'
81
+ @volume_from[name] = value == 'true'
82
+ end
83
+ when 'containerPath', 'sourceVolume'
84
+ @mountpoint[name] = value
85
+ when 'containerPort', 'hostPort'
86
+ @portmapping[name] = value.to_i
87
+ when 'sourceContainer'
88
+ @volume_from[name] = value
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,31 @@
1
+ module Fog
2
+ module Parsers
3
+ module AWS
4
+ module ECS
5
+ require 'fog/aws/parsers/ecs/service'
6
+
7
+ class UpdateService < Fog::Parsers::AWS::ECS::Service
8
+ def reset
9
+ super
10
+ @result = 'UpdateServiceResult'
11
+ @response[@result] = {}
12
+ @contexts = %w(service loadBalancers events deployments)
13
+ @service = {}
14
+ @context = []
15
+ @deployment = {}
16
+ @load_balancer = {}
17
+ @event = {}
18
+ end
19
+
20
+ def end_element(name)
21
+ super
22
+ case name
23
+ when 'service'
24
+ @response[@result]['service'] = @service
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -37,7 +37,7 @@ module Fog
37
37
  end
38
38
 
39
39
  class Mock
40
- def create_vpc(cidrBlock)
40
+ def create_vpc(cidrBlock, options = {})
41
41
  Excon::Response.new.tap do |response|
42
42
  if cidrBlock
43
43
  response.status = 200
@@ -0,0 +1,64 @@
1
+ module Fog
2
+ module AWS
3
+ class ECS
4
+ class Real
5
+ require 'fog/aws/parsers/ecs/create_cluster'
6
+
7
+ # Creates a new Amazon ECS cluster
8
+ # http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_CreateCluster.html
9
+ # ==== Parameters
10
+ # * clusterName <~String> - The name of your cluster.
11
+ # ==== Returns
12
+ # * response<~Excon::Response>:
13
+ # * body<~Hash>:
14
+ # * 'Cluster' <~Hash> - The full description of your new cluster
15
+ def create_cluster(params={})
16
+ request({
17
+ 'Action' => 'CreateCluster',
18
+ :parser => Fog::Parsers::AWS::ECS::CreateCluster.new
19
+ }.merge(params))
20
+ end
21
+ end
22
+
23
+ class Mock
24
+ def create_cluster(params={})
25
+ response = Excon::Response.new
26
+ response.status = 200
27
+
28
+ params.has_key?('clusterName') || params['clusterName'] = 'default'
29
+
30
+ owner_id = Fog::AWS::Mock.owner_id
31
+ cluster_name = params['clusterName']
32
+ cluster_path = "cluster/#{cluster_name}"
33
+ cluster_arn = Fog::AWS::Mock.arn('ecs', owner_id, cluster_path, region)
34
+ cluster = {}
35
+
36
+ search_cluster_result = self.data[:clusters].select { |c| c['clusterName'].eql?(cluster_name) }
37
+ if search_cluster_result.empty?
38
+ cluster = {
39
+ 'clusterName' => cluster_name,
40
+ 'clusterArn' => cluster_arn,
41
+ 'status' => 'ACTIVE',
42
+ 'registeredContainerInstancesCount' => 0,
43
+ 'runningTasksCount' => 0,
44
+ 'pendingTasksCount' => 0
45
+ }
46
+ self.data[:clusters] << cluster
47
+ else
48
+ cluster = search_cluster_result.first
49
+ end
50
+
51
+ response.body = {
52
+ 'CreateClusterResult' => {
53
+ 'cluster' => cluster
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,118 @@
1
+ module Fog
2
+ module AWS
3
+ class ECS
4
+ class Real
5
+ require 'fog/aws/parsers/ecs/create_service'
6
+
7
+ # Runs and maintains a desired number of tasks from a specified task definition.
8
+ # http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_CreateService.html
9
+ # ==== Parameters
10
+ # * clientToken <~String> - unique, case-sensitive identifier you provide to ensure the idempotency of the request.
11
+ # * cluster <~String> - short name or full Amazon Resource Name (ARN) of the cluster that you want to run your service on.
12
+ # * desiredCount <~Integer> - number of instantiations of the specified task definition that you would like to place and keep running on your cluster.
13
+ # * loadBalancers <~Array> - list of load balancer objects, containing the load balancer name, the container name (as it appears in a container definition), and the container port to access from the load balancer.
14
+ # * role <~String> - name or full Amazon Resource Name (ARN) of the IAM role that allows your Amazon ECS container agent to make calls to your load balancer on your behalf.
15
+ # * serviceName <~String> - name of your service
16
+ # * 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
17
+ # ==== Returns
18
+ # * response<~Excon::Response>:
19
+ # * body<~Hash>:
20
+ # * 'Service' <~Hash> - The full description of your new service
21
+ def create_service(params={})
22
+ if load_balancers = params.delete('loadBalancers')
23
+ params.merge!(Fog::AWS.indexed_param('loadBalancers.member', [*load_balancers]))
24
+ end
25
+ request({
26
+ 'Action' => 'CreateService',
27
+ :parser => Fog::Parsers::AWS::ECS::CreateService.new
28
+ }.merge(params))
29
+ end
30
+ end
31
+
32
+ class Mock
33
+ def create_service(params={})
34
+ response = Excon::Response.new
35
+ response.status = 200
36
+
37
+ e = Fog::AWS::ECS::Error
38
+ msg = 'ClientException => desiredCount cannot be empty.'
39
+ raise e, msg unless desired_count = params['desiredCount']
40
+ msg = 'ClientException => serviceName cannot be empty.'
41
+ raise e unless service_name = params['serviceName']
42
+ msg = 'ClientException => taskDefinition cannot be empty.'
43
+ raise e unless task_definition = params['taskDefinition']
44
+
45
+ owner_id = Fog::AWS::Mock.owner_id
46
+
47
+ service_path = "service/#{service_name}"
48
+ service_arn = Fog::AWS::Mock.arn('ecs', owner_id, service_path, region)
49
+
50
+ cluster = params['cluster'] || 'default'
51
+ if !cluster.match(/^arn:aws:ecs:.+:.+:cluster\/(.+)$/)
52
+ cluster_path = "cluster/#{cluster}"
53
+ cluster_arn = Fog::AWS::Mock.arn('ecs', owner_id, cluster_path, region)
54
+ else
55
+ cluster_arn = cluster
56
+ end
57
+
58
+ if params['role']
59
+ role = params['role'] if params['role']
60
+ if !role.match(/^arn:aws:iam:.*:.*:role\/(.+)$/)
61
+ role_path = "role/#{role}"
62
+ role_arn = Fog::AWS::Mock.arn('iam', owner_id, role_path, region)
63
+ else
64
+ role_arn = role
65
+ end
66
+ end
67
+
68
+ if !task_definition.match(/^arn:aws:ecs:.+:.+:task-definition\/.+$/)
69
+ task_def_path = "task-definition\/#{task_definition}"
70
+ task_def_arn = Fog::AWS::Mock.arn('ecs', owner_id, task_def_path, region)
71
+ else
72
+ task_def_arn = task_definition
73
+ end
74
+
75
+ load_balancers = params['loadBalancers'] || []
76
+
77
+ service = {
78
+ 'events' => [],
79
+ 'serviceName' => service_name,
80
+ 'serviceArn' => service_arn,
81
+ 'taskDefinition' => task_def_arn,
82
+ 'clusterArn' => cluster_arn,
83
+ 'status' => 'ACTIVE',
84
+ 'roleArn' => role_arn,
85
+ 'loadBalancers' => [*load_balancers],
86
+ 'deployments' => [],
87
+ 'desiredCount' => desired_count,
88
+ 'pendingCount' => 0,
89
+ 'runningCount' => 0
90
+ }
91
+
92
+ service['deployments'] << {
93
+ 'updatedAt' => Time.now.utc,
94
+ 'id' => "ecs-svc/#{Fog::Mock.random_numbers(19)}",
95
+ 'taskDefinition' => task_def_arn,
96
+ 'status' => 'PRIMARY',
97
+ 'desiredCount' => desired_count,
98
+ 'createdAt' => Time.now.utc,
99
+ 'pendingCount' => 0,
100
+ 'runningCount' => 0
101
+ }
102
+
103
+ self.data[:services] << service
104
+
105
+ response.body = {
106
+ 'CreateServiceResult' => {
107
+ 'service' => service,
108
+ },
109
+ 'ResponseMetadata' => {
110
+ 'RequestId' => Fog::AWS::Mock.request_id
111
+ }
112
+ }
113
+ response
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end