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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e0d4cac4894ba3bccfd3df9686c95311418cfb5
4
- data.tar.gz: 7e8b47035280cc888f00521d79760b1a22bb4326
3
+ metadata.gz: 53e5c13a8cdab463ca2f7e696ce8f6be7a28e6b7
4
+ data.tar.gz: 7c0b522b66731d66b8374cf1cf8d8c8cba679d57
5
5
  SHA512:
6
- metadata.gz: 7e9e38a21257953f72fabc2a5cd3188523ad55c9f646a55f560aad3e441b546833f3866102050ca7f879fba2abfb1e6849a4bfd47edf229def8c6912a4b6baf3
7
- data.tar.gz: 755a06be0f463c4ff0be9bc4b08598b6035401f793a1bb5aa1014067cf89bff0a06c7d7879a833b289d2fd1575274dbc8539d56ef79b49e477e985f1e7bd55d5
6
+ metadata.gz: 5c93b6c6b2d5013370a4277bd28002c5b357af8d28846f21c1c44147a1ec4773e15c4ab047795ee5fd718755b66ad153db597be569cbe33e043c930e599e9f01
7
+ data.tar.gz: 174a539d140553b296d6ef4beb68f792f6f02a67ca3c17a7d25a76c7d1038aade3807ec7efb7be7e1bb0c479c010ad5e790a9e396bd7fec7895d73de4c620c9e
@@ -36,6 +36,7 @@ module Fog
36
36
  autoload :CloudWatch, File.expand_path('../aws/cloud_watch', __FILE__)
37
37
  autoload :DataPipeline, File.expand_path('../aws/data_pipeline', __FILE__)
38
38
  autoload :DynamoDB, File.expand_path('../aws/dynamodb', __FILE__)
39
+ autoload :ECS, File.expand_path('../aws/ecs', __FILE__)
39
40
  autoload :ELB, File.expand_path('../aws/elb', __FILE__)
40
41
  autoload :EMR, File.expand_path('../aws/emr', __FILE__)
41
42
  autoload :ElasticBeanstalk, File.expand_path('../aws/beanstalk', __FILE__)
@@ -62,6 +63,7 @@ module Fog
62
63
  service(:dns, 'DNS')
63
64
  service(:dynamodb, 'DynamoDB')
64
65
  service(:elasticache, 'Elasticache')
66
+ service(:ecs, 'ECS')
65
67
  service(:elb, 'ELB')
66
68
  service(:emr, 'EMR')
67
69
  service(:federation, 'Federation')
@@ -0,0 +1,187 @@
1
+ module Fog
2
+ module AWS
3
+ class ECS < Fog::Service
4
+
5
+ requires :aws_access_key_id, :aws_secret_access_key
6
+ recognizes :region, :host, :path, :port, :scheme, :persistent, :use_iam_profile, :aws_session_token, :aws_credentials_expire_at, :version, :instrumentor, :instrumentor_name
7
+
8
+ request_path 'fog/aws/requests/ecs'
9
+ request :list_clusters
10
+ request :create_cluster
11
+ request :delete_cluster
12
+ request :describe_clusters
13
+
14
+ request :list_task_definitions
15
+ request :describe_task_definition
16
+ request :deregister_task_definition
17
+ request :register_task_definition
18
+ request :list_task_definition_families
19
+
20
+ request :list_services
21
+ request :describe_services
22
+ request :create_service
23
+ request :delete_service
24
+ request :update_service
25
+
26
+ request :list_container_instances
27
+ request :describe_container_instances
28
+ request :deregister_container_instance
29
+
30
+ request :list_tasks
31
+ request :describe_tasks
32
+ request :run_task
33
+ request :start_task
34
+ request :stop_task
35
+
36
+ class Real
37
+ attr_reader :region
38
+
39
+ include Fog::AWS::CredentialFetcher::ConnectionMethods
40
+ # Initialize connection to ECS
41
+ #
42
+ # ==== Notes
43
+ # options parameter must include values for :aws_access_key_id and
44
+ # :aws_secret_access_key in order to create a connection
45
+ #
46
+ # ==== Examples
47
+ # ecs = ECS.new(
48
+ # :aws_access_key_id => your_aws_access_key_id,
49
+ # :aws_secret_access_key => your_aws_secret_access_key
50
+ # )
51
+ #
52
+ # ==== Parameters
53
+ # * options<~Hash> - config arguments for connection. Defaults to {}.
54
+ # * region<~String> - optional region to use. For instance, 'eu-west-1', 'us-east-1' and etc.
55
+ #
56
+ # ==== Returns
57
+ # * ECS object with connection to AWS.
58
+ def initialize(options={})
59
+ @use_iam_profile = options[:use_iam_profile]
60
+ @instrumentor = options[:instrumentor]
61
+ @instrumentor_name = options[:instrumentor_name] || 'fog.aws.ecs'
62
+ @connection_options = options[:connection_options] || {}
63
+
64
+ @region = options[:region] || 'us-east-1'
65
+ @host = options[:host] || "ecs.#{@region}.amazonaws.com"
66
+ @path = options[:path] || '/'
67
+ @persistent = options[:persistent] || false
68
+ @port = options[:port] || 443
69
+ @scheme = options[:scheme] || 'https'
70
+ @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
71
+ @version = options[:version] || '2014-11-13'
72
+
73
+ setup_credentials(options)
74
+ end
75
+
76
+ def reload
77
+ @connection.reset
78
+ end
79
+
80
+ private
81
+
82
+ def setup_credentials(options)
83
+ @aws_access_key_id = options[:aws_access_key_id]
84
+ @aws_secret_access_key = options[:aws_secret_access_key]
85
+ @aws_session_token = options[:aws_session_token]
86
+ @aws_credentials_expire_at = options[:aws_credentials_expire_at]
87
+
88
+ @signer = Fog::AWS::SignatureV4.new( @aws_access_key_id, @aws_secret_access_key,@region,'ecs')
89
+ end
90
+
91
+ def request(params)
92
+ refresh_credentials_if_expired
93
+
94
+ idempotent = params.delete(:idempotent)
95
+ parser = params.delete(:parser)
96
+
97
+ body, headers = Fog::AWS.signed_params_v4(
98
+ params,
99
+ {'Content-Type' => 'application/x-www-form-urlencoded' },
100
+ {
101
+ :aws_session_token => @aws_session_token,
102
+ :signer => @signer,
103
+ :host => @host,
104
+ :path => @path,
105
+ :port => @port,
106
+ :version => @version,
107
+ :method => 'POST'
108
+ }
109
+ )
110
+
111
+ if @instrumentor
112
+ @instrumentor.instrument("#{@instrumentor_name}.request", params) do
113
+ _request(body, headers, idempotent, parser)
114
+ end
115
+ else
116
+ _request(body, headers, idempotent, parser)
117
+ end
118
+ end
119
+
120
+ def _request(body, headers, idempotent, parser)
121
+ @connection.request({
122
+ :body => body,
123
+ :expects => 200,
124
+ :headers => headers,
125
+ :idempotent => idempotent,
126
+ :method => 'POST',
127
+ :parser => parser
128
+ })
129
+ rescue Excon::Errors::HTTPStatusError => error
130
+ match = Fog::AWS::Errors.match_error(error)
131
+ raise if match.empty?
132
+ raise case match[:code]
133
+ when 'NotFound'
134
+ Fog::AWS::ECS::NotFound.slurp(error, match[:message])
135
+ else
136
+ Fog::AWS::ECS::Error.slurp(error, "#{match[:code]} => #{match[:message]}")
137
+ end
138
+ end
139
+ end
140
+
141
+ class Mock
142
+ def self.data
143
+ @data ||= Hash.new do |hash, region|
144
+ hash[region] = Hash.new do |region_hash, key|
145
+ region_hash[key] = {
146
+ :clusters => [],
147
+ :task_definitions => [],
148
+ :services => [],
149
+ :container_instances => [],
150
+ :tasks => []
151
+ }
152
+ end
153
+ end
154
+ end
155
+
156
+ def self.reset
157
+ @data = nil
158
+ end
159
+
160
+ attr_accessor :region
161
+
162
+ def initialize(options={})
163
+ @use_iam_profile = options[:use_iam_profile]
164
+ @region = options[:region] || 'us-east-1'
165
+
166
+ unless ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-central-1', 'eu-west-1', 'us-east-1', 'us-west-1', 'us-west-2', 'sa-east-1'].include?(@region)
167
+ raise ArgumentError, "Unknown region: #{@region.inspect}"
168
+ end
169
+
170
+ setup_credentials(options)
171
+ end
172
+
173
+ def data
174
+ self.class.data[@region][@aws_access_key_id]
175
+ end
176
+
177
+ def reset_data
178
+ self.class.data[@region].delete(@aws_access_key_id)
179
+ end
180
+
181
+ def setup_credentials(options)
182
+ @aws_access_key_id = options[:aws_access_key_id]
183
+ end
184
+ end
185
+ end
186
+ end
187
+ end
@@ -44,6 +44,16 @@ module Fog
44
44
  :ebs_optimized_available => false,
45
45
  :instance_store_volumes => 0
46
46
  },
47
+ {
48
+ :id => 't2.large',
49
+ :name => 'Micro Instance',
50
+ :bits => 64,
51
+ :cores => 2,
52
+ :disk => 0,
53
+ :ram => 8192,
54
+ :ebs_optimized_available => false,
55
+ :instance_store_volumes => 0
56
+ },
47
57
  {
48
58
  :id => 'm1.small',
49
59
  :name => 'Small Instance',
@@ -0,0 +1,28 @@
1
+ module Fog
2
+ module Parsers
3
+ module AWS
4
+ module ECS
5
+ # Base parser for ResponseMetadata, RequestId
6
+ class Base < Fog::Parsers::Base
7
+ def reset
8
+ super
9
+ @response = {'ResponseMetadata' => {}}
10
+ end
11
+
12
+ def start_element(name, attrs = [])
13
+ super
14
+ end
15
+
16
+ def end_element(name)
17
+ case name
18
+ when 'RequestId'
19
+ @response['ResponseMetadata'][name] = value
20
+ else
21
+ super
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,75 @@
1
+ module Fog
2
+ module Parsers
3
+ module AWS
4
+ module ECS
5
+ require 'fog/aws/parsers/ecs/base'
6
+
7
+ class ContainerInstance < 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 'stringSetValue'
19
+ @context.pop
20
+ case @context.last
21
+ when 'remainingResources'
22
+ @remaining_resource[name] = @string_set
23
+ when 'registeredResources'
24
+ @registered_resource[name] = @string_set
25
+ end
26
+ @string_set = []
27
+ when *@contexts
28
+ @context.pop
29
+ when 'member'
30
+ case @context.last
31
+ when 'remainingResources'
32
+ @container_instance['remainingResources'] ||= []
33
+ @container_instance['remainingResources'] << @remaining_resource
34
+ @remaining_resource = {}
35
+ when 'registeredResources'
36
+ @container_instance['registeredResources'] ||= []
37
+ @container_instance['registeredResources'] << @registered_resource
38
+ @registered_resource = {}
39
+ when 'stringSetValue'
40
+ @string_set << value.to_i
41
+ end
42
+ when 'longValue', 'integerValue'
43
+ case @context.last
44
+ when 'remainingResources'
45
+ @remaining_resource[name] = value.to_i
46
+ when 'registeredResources'
47
+ @registered_resource[name] = value.to_i
48
+ end
49
+ when 'doubleValue'
50
+ case @context.last
51
+ when 'remainingResources'
52
+ @remaining_resource[name] = value.to_f
53
+ when 'registeredResources'
54
+ @registered_resource[name] = value.to_f
55
+ end
56
+ when 'name', 'type'
57
+ case @context.last
58
+ when 'remainingResources'
59
+ @remaining_resource[name] = value
60
+ when 'registeredResources'
61
+ @registered_resource[name] = value
62
+ end
63
+ when 'agentConnected'
64
+ @container_instance[name] = value == 'true'
65
+ when 'runningTasksCount', 'pendingTasksCount'
66
+ @container_instance[name] = value.to_i
67
+ when 'status', 'containerInstanceArn', 'ec2InstanceId'
68
+ @container_instance[name] = value
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,30 @@
1
+ module Fog
2
+ module Parsers
3
+ module AWS
4
+ module ECS
5
+ require 'fog/aws/parsers/ecs/base'
6
+
7
+ class CreateCluster < Fog::Parsers::AWS::ECS::Base
8
+ def reset
9
+ super
10
+ @result = 'CreateClusterResult'
11
+ @response[@result] = {}
12
+ @cluster = {}
13
+ end
14
+
15
+ def end_element(name)
16
+ super
17
+ case name
18
+ when 'clusterName', 'clusterArn', 'status'
19
+ @cluster[name] = value
20
+ when 'registeredContainerInstancesCount', 'runningTasksCount', 'pendingTasksCount'
21
+ @cluster[name] = value.to_i
22
+ when 'cluster'
23
+ @response[@result]['cluster'] = @cluster
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ 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 CreateService < Fog::Parsers::AWS::ECS::Service
8
+ def reset
9
+ super
10
+ @result = 'CreateServiceResult'
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
@@ -0,0 +1,30 @@
1
+ module Fog
2
+ module Parsers
3
+ module AWS
4
+ module ECS
5
+ require 'fog/aws/parsers/ecs/base'
6
+
7
+ class DeleteCluster < Fog::Parsers::AWS::ECS::Base
8
+ def reset
9
+ super
10
+ @result = 'DeleteClusterResult'
11
+ @response[@result] = {}
12
+ @cluster = {}
13
+ end
14
+
15
+ def end_element(name)
16
+ super
17
+ case name
18
+ when 'clusterName', 'clusterArn', 'status'
19
+ @cluster[name] = value
20
+ when 'registeredContainerInstancesCount', 'runningTasksCount', 'pendingTasksCount'
21
+ @cluster[name] = value.to_i
22
+ when 'cluster'
23
+ @response[@result]['cluster'] = @cluster
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ 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 DeleteService < Fog::Parsers::AWS::ECS::Service
8
+ def reset
9
+ super
10
+ @result = 'DeleteServiceResult'
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