mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
Add support for ECS service
This commit is contained in:
parent
916351a353
commit
a8ea5e3ec8
58 changed files with 3692 additions and 0 deletions
|
@ -36,6 +36,7 @@ module Fog
|
|||
autoload :CloudWatch, File.expand_path('../aws/cloud_watch', __FILE__)
|
||||
autoload :DataPipeline, File.expand_path('../aws/data_pipeline', __FILE__)
|
||||
autoload :DynamoDB, File.expand_path('../aws/dynamodb', __FILE__)
|
||||
autoload :ECS, File.expand_path('../aws/ecs', __FILE__)
|
||||
autoload :ELB, File.expand_path('../aws/elb', __FILE__)
|
||||
autoload :EMR, File.expand_path('../aws/emr', __FILE__)
|
||||
autoload :ElasticBeanstalk, File.expand_path('../aws/beanstalk', __FILE__)
|
||||
|
@ -62,6 +63,7 @@ module Fog
|
|||
service(:dns, 'DNS')
|
||||
service(:dynamodb, 'DynamoDB')
|
||||
service(:elasticache, 'Elasticache')
|
||||
service(:ecs, 'ECS')
|
||||
service(:elb, 'ELB')
|
||||
service(:emr, 'EMR')
|
||||
service(:federation, 'Federation')
|
||||
|
|
187
lib/fog/aws/ecs.rb
Normal file
187
lib/fog/aws/ecs.rb
Normal file
|
@ -0,0 +1,187 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS < Fog::Service
|
||||
|
||||
requires :aws_access_key_id, :aws_secret_access_key
|
||||
recognizes :region, :host, :path, :port, :scheme, :persistent, :use_iam_profile, :aws_session_token, :aws_credentials_expire_at, :version, :instrumentor, :instrumentor_name
|
||||
|
||||
request_path 'fog/aws/requests/ecs'
|
||||
request :list_clusters
|
||||
request :create_cluster
|
||||
request :delete_cluster
|
||||
request :describe_clusters
|
||||
|
||||
request :list_task_definitions
|
||||
request :describe_task_definition
|
||||
request :deregister_task_definition
|
||||
request :register_task_definition
|
||||
request :list_task_definition_families
|
||||
|
||||
request :list_services
|
||||
request :describe_services
|
||||
request :create_service
|
||||
request :delete_service
|
||||
request :update_service
|
||||
|
||||
request :list_container_instances
|
||||
request :describe_container_instances
|
||||
request :deregister_container_instance
|
||||
|
||||
request :list_tasks
|
||||
request :describe_tasks
|
||||
request :run_task
|
||||
request :start_task
|
||||
request :stop_task
|
||||
|
||||
class Real
|
||||
attr_reader :region
|
||||
|
||||
include Fog::AWS::CredentialFetcher::ConnectionMethods
|
||||
# Initialize connection to ECS
|
||||
#
|
||||
# ==== Notes
|
||||
# options parameter must include values for :aws_access_key_id and
|
||||
# :aws_secret_access_key in order to create a connection
|
||||
#
|
||||
# ==== Examples
|
||||
# ecs = ECS.new(
|
||||
# :aws_access_key_id => your_aws_access_key_id,
|
||||
# :aws_secret_access_key => your_aws_secret_access_key
|
||||
# )
|
||||
#
|
||||
# ==== Parameters
|
||||
# * options<~Hash> - config arguments for connection. Defaults to {}.
|
||||
# * region<~String> - optional region to use. For instance, 'eu-west-1', 'us-east-1' and etc.
|
||||
#
|
||||
# ==== Returns
|
||||
# * ECS object with connection to AWS.
|
||||
def initialize(options={})
|
||||
@use_iam_profile = options[:use_iam_profile]
|
||||
@instrumentor = options[:instrumentor]
|
||||
@instrumentor_name = options[:instrumentor_name] || 'fog.aws.ecs'
|
||||
@connection_options = options[:connection_options] || {}
|
||||
|
||||
@region = options[:region] || 'us-east-1'
|
||||
@host = options[:host] || "ecs.#{@region}.amazonaws.com"
|
||||
@path = options[:path] || '/'
|
||||
@persistent = options[:persistent] || false
|
||||
@port = options[:port] || 443
|
||||
@scheme = options[:scheme] || 'https'
|
||||
@connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options)
|
||||
@version = options[:version] || '2014-11-13'
|
||||
|
||||
setup_credentials(options)
|
||||
end
|
||||
|
||||
def reload
|
||||
@connection.reset
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def setup_credentials(options)
|
||||
@aws_access_key_id = options[:aws_access_key_id]
|
||||
@aws_secret_access_key = options[:aws_secret_access_key]
|
||||
@aws_session_token = options[:aws_session_token]
|
||||
@aws_credentials_expire_at = options[:aws_credentials_expire_at]
|
||||
|
||||
@signer = Fog::AWS::SignatureV4.new( @aws_access_key_id, @aws_secret_access_key,@region,'ecs')
|
||||
end
|
||||
|
||||
def request(params)
|
||||
refresh_credentials_if_expired
|
||||
|
||||
idempotent = params.delete(:idempotent)
|
||||
parser = params.delete(:parser)
|
||||
|
||||
body, headers = Fog::AWS.signed_params_v4(
|
||||
params,
|
||||
{'Content-Type' => 'application/x-www-form-urlencoded' },
|
||||
{
|
||||
:aws_session_token => @aws_session_token,
|
||||
:signer => @signer,
|
||||
:host => @host,
|
||||
:path => @path,
|
||||
:port => @port,
|
||||
:version => @version,
|
||||
:method => 'POST'
|
||||
}
|
||||
)
|
||||
|
||||
if @instrumentor
|
||||
@instrumentor.instrument("#{@instrumentor_name}.request", params) do
|
||||
_request(body, headers, idempotent, parser)
|
||||
end
|
||||
else
|
||||
_request(body, headers, idempotent, parser)
|
||||
end
|
||||
end
|
||||
|
||||
def _request(body, headers, idempotent, parser)
|
||||
@connection.request({
|
||||
:body => body,
|
||||
:expects => 200,
|
||||
:headers => headers,
|
||||
:idempotent => idempotent,
|
||||
:method => 'POST',
|
||||
:parser => parser
|
||||
})
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
match = Fog::AWS::Errors.match_error(error)
|
||||
raise if match.empty?
|
||||
raise case match[:code]
|
||||
when 'NotFound'
|
||||
Fog::AWS::ECS::NotFound.slurp(error, match[:message])
|
||||
else
|
||||
Fog::AWS::ECS::Error.slurp(error, "#{match[:code]} => #{match[:message]}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def self.data
|
||||
@data ||= Hash.new do |hash, region|
|
||||
hash[region] = Hash.new do |region_hash, key|
|
||||
region_hash[key] = {
|
||||
:clusters => [],
|
||||
:task_definitions => [],
|
||||
:services => [],
|
||||
:container_instances => [],
|
||||
:tasks => []
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.reset
|
||||
@data = nil
|
||||
end
|
||||
|
||||
attr_accessor :region
|
||||
|
||||
def initialize(options={})
|
||||
@use_iam_profile = options[:use_iam_profile]
|
||||
@region = options[:region] || 'us-east-1'
|
||||
|
||||
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)
|
||||
raise ArgumentError, "Unknown region: #{@region.inspect}"
|
||||
end
|
||||
|
||||
setup_credentials(options)
|
||||
end
|
||||
|
||||
def data
|
||||
self.class.data[@region][@aws_access_key_id]
|
||||
end
|
||||
|
||||
def reset_data
|
||||
self.class.data[@region].delete(@aws_access_key_id)
|
||||
end
|
||||
|
||||
def setup_credentials(options)
|
||||
@aws_access_key_id = options[:aws_access_key_id]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
28
lib/fog/aws/parsers/ecs/base.rb
Normal file
28
lib/fog/aws/parsers/ecs/base.rb
Normal file
|
@ -0,0 +1,28 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
# Base parser for ResponseMetadata, RequestId
|
||||
class Base < Fog::Parsers::Base
|
||||
def reset
|
||||
super
|
||||
@response = {'ResponseMetadata' => {}}
|
||||
end
|
||||
|
||||
def start_element(name, attrs = [])
|
||||
super
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'RequestId'
|
||||
@response['ResponseMetadata'][name] = value
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
75
lib/fog/aws/parsers/ecs/container_instance.rb
Normal file
75
lib/fog/aws/parsers/ecs/container_instance.rb
Normal file
|
@ -0,0 +1,75 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/base'
|
||||
|
||||
class ContainerInstance < Fog::Parsers::AWS::ECS::Base
|
||||
def start_element(name, attrs = [])
|
||||
super
|
||||
if @contexts.include?(name)
|
||||
@context.push(name)
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'stringSetValue'
|
||||
@context.pop
|
||||
case @context.last
|
||||
when 'remainingResources'
|
||||
@remaining_resource[name] = @string_set
|
||||
when 'registeredResources'
|
||||
@registered_resource[name] = @string_set
|
||||
end
|
||||
@string_set = []
|
||||
when *@contexts
|
||||
@context.pop
|
||||
when 'member'
|
||||
case @context.last
|
||||
when 'remainingResources'
|
||||
@container_instance['remainingResources'] ||= []
|
||||
@container_instance['remainingResources'] << @remaining_resource
|
||||
@remaining_resource = {}
|
||||
when 'registeredResources'
|
||||
@container_instance['registeredResources'] ||= []
|
||||
@container_instance['registeredResources'] << @registered_resource
|
||||
@registered_resource = {}
|
||||
when 'stringSetValue'
|
||||
@string_set << value.to_i
|
||||
end
|
||||
when 'longValue', 'integerValue'
|
||||
case @context.last
|
||||
when 'remainingResources'
|
||||
@remaining_resource[name] = value.to_i
|
||||
when 'registeredResources'
|
||||
@registered_resource[name] = value.to_i
|
||||
end
|
||||
when 'doubleValue'
|
||||
case @context.last
|
||||
when 'remainingResources'
|
||||
@remaining_resource[name] = value.to_f
|
||||
when 'registeredResources'
|
||||
@registered_resource[name] = value.to_f
|
||||
end
|
||||
when 'name', 'type'
|
||||
case @context.last
|
||||
when 'remainingResources'
|
||||
@remaining_resource[name] = value
|
||||
when 'registeredResources'
|
||||
@registered_resource[name] = value
|
||||
end
|
||||
when 'agentConnected'
|
||||
@container_instance[name] = value == 'true'
|
||||
when 'runningTasksCount', 'pendingTasksCount'
|
||||
@container_instance[name] = value.to_i
|
||||
when 'status', 'containerInstanceArn', 'ec2InstanceId'
|
||||
@container_instance[name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
30
lib/fog/aws/parsers/ecs/create_cluster.rb
Normal file
30
lib/fog/aws/parsers/ecs/create_cluster.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/base'
|
||||
|
||||
class CreateCluster < Fog::Parsers::AWS::ECS::Base
|
||||
def reset
|
||||
super
|
||||
@result = 'CreateClusterResult'
|
||||
@response[@result] = {}
|
||||
@cluster = {}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'clusterName', 'clusterArn', 'status'
|
||||
@cluster[name] = value
|
||||
when 'registeredContainerInstancesCount', 'runningTasksCount', 'pendingTasksCount'
|
||||
@cluster[name] = value.to_i
|
||||
when 'cluster'
|
||||
@response[@result]['cluster'] = @cluster
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
31
lib/fog/aws/parsers/ecs/create_service.rb
Normal file
31
lib/fog/aws/parsers/ecs/create_service.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/service'
|
||||
|
||||
class CreateService < Fog::Parsers::AWS::ECS::Service
|
||||
def reset
|
||||
super
|
||||
@result = 'CreateServiceResult'
|
||||
@response[@result] = {}
|
||||
@contexts = %w(service loadBalancers events deployments)
|
||||
@service = {}
|
||||
@context = []
|
||||
@deployment = {}
|
||||
@load_balancer = {}
|
||||
@event = {}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'service'
|
||||
@response[@result]['service'] = @service
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
30
lib/fog/aws/parsers/ecs/delete_cluster.rb
Normal file
30
lib/fog/aws/parsers/ecs/delete_cluster.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/base'
|
||||
|
||||
class DeleteCluster < Fog::Parsers::AWS::ECS::Base
|
||||
def reset
|
||||
super
|
||||
@result = 'DeleteClusterResult'
|
||||
@response[@result] = {}
|
||||
@cluster = {}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'clusterName', 'clusterArn', 'status'
|
||||
@cluster[name] = value
|
||||
when 'registeredContainerInstancesCount', 'runningTasksCount', 'pendingTasksCount'
|
||||
@cluster[name] = value.to_i
|
||||
when 'cluster'
|
||||
@response[@result]['cluster'] = @cluster
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
31
lib/fog/aws/parsers/ecs/delete_service.rb
Normal file
31
lib/fog/aws/parsers/ecs/delete_service.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/service'
|
||||
|
||||
class DeleteService < Fog::Parsers::AWS::ECS::Service
|
||||
def reset
|
||||
super
|
||||
@result = 'DeleteServiceResult'
|
||||
@response[@result] = {}
|
||||
@contexts = %w(service loadBalancers events deployments)
|
||||
@service = {}
|
||||
@context = []
|
||||
@deployment = {}
|
||||
@load_balancer = {}
|
||||
@event = {}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'service'
|
||||
@response[@result]['service'] = @service
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
31
lib/fog/aws/parsers/ecs/deregister_container_instance.rb
Normal file
31
lib/fog/aws/parsers/ecs/deregister_container_instance.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/container_instance'
|
||||
|
||||
class DeregisterContainerInstance < Fog::Parsers::AWS::ECS::ContainerInstance
|
||||
def reset
|
||||
super
|
||||
@result = 'DeregisterContainerInstanceResult'
|
||||
@response[@result] = {}
|
||||
@contexts = %w(registeredResources remainingResources stringSetValue)
|
||||
@context = []
|
||||
@container_instance = {}
|
||||
@registered_resource = {}
|
||||
@remaining_resource = {}
|
||||
@string_set = []
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'containerInstance'
|
||||
@response[@result][name] = @container_instance
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
32
lib/fog/aws/parsers/ecs/deregister_task_definition.rb
Normal file
32
lib/fog/aws/parsers/ecs/deregister_task_definition.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/task_definition'
|
||||
|
||||
class DeregisterTaskDefinition < Fog::Parsers::AWS::ECS::TaskDefinition
|
||||
def reset
|
||||
@response = {}
|
||||
@result = 'DeregisterTaskDefinitionResult'
|
||||
@definition = 'taskDefinition'
|
||||
@response[@result] = {
|
||||
@definition => {
|
||||
'volumes' => [],
|
||||
'containerDefinitions' => []
|
||||
}
|
||||
}
|
||||
@contexts = %w(volumes containerDefinitions command entryPoint environment links mountPoints portMappings volumesFrom)
|
||||
@context = []
|
||||
@volume = {}
|
||||
@host = {}
|
||||
@container = {}
|
||||
@environment = {}
|
||||
@mountpoint = {}
|
||||
@portmapping = {}
|
||||
@volume_from = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
55
lib/fog/aws/parsers/ecs/describe_clusters.rb
Normal file
55
lib/fog/aws/parsers/ecs/describe_clusters.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/base'
|
||||
|
||||
class DescribeClusters < Fog::Parsers::AWS::ECS::Base
|
||||
def reset
|
||||
super
|
||||
@result = 'DescribeClustersResult'
|
||||
@response[@result] = {}
|
||||
@contexts = %w(failures clusters)
|
||||
@context = []
|
||||
@clusters = []
|
||||
@failures = []
|
||||
@cluster = {}
|
||||
@failure = {}
|
||||
end
|
||||
|
||||
def start_element(name, attrs = [])
|
||||
super
|
||||
if @contexts.include?(name)
|
||||
@context.push(name)
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'clusterName', 'clusterArn', 'status'
|
||||
@cluster[name] = value
|
||||
when 'arn', 'reason'
|
||||
@failure[name] = value
|
||||
when 'member'
|
||||
case @context.last
|
||||
when 'clusters'
|
||||
@clusters << @cluster unless @cluster.empty?
|
||||
@cluster = {}
|
||||
when 'failures'
|
||||
@failures << @failure unless @failure.empty?
|
||||
@failure = {}
|
||||
end
|
||||
when 'clusters'
|
||||
@response[@result][name] = @clusters
|
||||
@context.pop
|
||||
when 'failures'
|
||||
@response[@result][name] = @failures
|
||||
@context.pop
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
38
lib/fog/aws/parsers/ecs/describe_container_instances.rb
Normal file
38
lib/fog/aws/parsers/ecs/describe_container_instances.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/container_instance'
|
||||
|
||||
class DescribeContainerInstances < Fog::Parsers::AWS::ECS::ContainerInstance
|
||||
def reset
|
||||
super
|
||||
@result = 'DescribeContainerInstancesResult'
|
||||
@response[@result] = {
|
||||
'containerInstances' => [],
|
||||
'failures' => []
|
||||
}
|
||||
@contexts = %w(containerInstances registeredResources remainingResources stringSetValue)
|
||||
@context = []
|
||||
@container_instance = {}
|
||||
@registered_resource = {}
|
||||
@remaining_resource = {}
|
||||
@string_set = []
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'member'
|
||||
case @context.last
|
||||
when 'containerInstances'
|
||||
@response[@result]['containerInstances'] << @container_instance
|
||||
@container_instance = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
24
lib/fog/aws/parsers/ecs/describe_services.rb
Normal file
24
lib/fog/aws/parsers/ecs/describe_services.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/service'
|
||||
|
||||
class DescribeServices < Fog::Parsers::AWS::ECS::Service
|
||||
def reset
|
||||
super
|
||||
@result = 'DescribeServicesResult'
|
||||
@response[@result] = { 'services' => [], 'failures' => [] }
|
||||
@service = {}
|
||||
@failure = {}
|
||||
@contexts = %w(failures services loadBalancers events deployments)
|
||||
@context = []
|
||||
@deployment = {}
|
||||
@load_balancer = {}
|
||||
@event = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
32
lib/fog/aws/parsers/ecs/describe_task_definition.rb
Normal file
32
lib/fog/aws/parsers/ecs/describe_task_definition.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/task_definition'
|
||||
|
||||
class DescribeTaskDefinition < Fog::Parsers::AWS::ECS::TaskDefinition
|
||||
def reset
|
||||
super
|
||||
@result = 'DescribeTaskDefinitionResult'
|
||||
@definition = 'taskDefinition'
|
||||
@response[@result] = {
|
||||
@definition => {
|
||||
'volumes' => [],
|
||||
'containerDefinitions' => []
|
||||
}
|
||||
}
|
||||
@contexts = %w(volumes containerDefinitions command entryPoint environment links mountPoints portMappings volumesFrom)
|
||||
@context = []
|
||||
@volume = {}
|
||||
@host = {}
|
||||
@container = {}
|
||||
@environment = {}
|
||||
@mountpoint = {}
|
||||
@portmapping = {}
|
||||
@volume_from = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
24
lib/fog/aws/parsers/ecs/describe_tasks.rb
Normal file
24
lib/fog/aws/parsers/ecs/describe_tasks.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/task'
|
||||
|
||||
class DescribeTasks < Fog::Parsers::AWS::ECS::Task
|
||||
def reset
|
||||
super
|
||||
@result = 'DescribeTasksResult'
|
||||
@response[@result] = {'failures' => [], 'tasks' => []}
|
||||
@contexts = %w(failures tasks containers overrides networkBindings containerOverrides)
|
||||
@context = []
|
||||
@task = {}
|
||||
@failure = {}
|
||||
@container = {}
|
||||
@net_binding = {}
|
||||
@container_overrides = []
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
27
lib/fog/aws/parsers/ecs/list_clusters.rb
Normal file
27
lib/fog/aws/parsers/ecs/list_clusters.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/base'
|
||||
|
||||
class ListClusters < Fog::Parsers::AWS::ECS::Base
|
||||
def reset
|
||||
super
|
||||
@result = 'ListClustersResult'
|
||||
@response[@result] = {'clusterArns' => []}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'member'
|
||||
@response[@result]['clusterArns'] << value
|
||||
when 'NextToken'
|
||||
@response[@result][name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
27
lib/fog/aws/parsers/ecs/list_container_instances.rb
Normal file
27
lib/fog/aws/parsers/ecs/list_container_instances.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/base'
|
||||
|
||||
class ListContainerInstances < Fog::Parsers::AWS::ECS::Base
|
||||
def reset
|
||||
super
|
||||
@result = 'ListContainerInstancesResult'
|
||||
@response[@result] = {'containerInstanceArns' => []}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'member'
|
||||
@response[@result]['containerInstanceArns'] << value
|
||||
when 'NextToken'
|
||||
@response[@result][name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
27
lib/fog/aws/parsers/ecs/list_services.rb
Normal file
27
lib/fog/aws/parsers/ecs/list_services.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/base'
|
||||
|
||||
class ListServices < Fog::Parsers::AWS::ECS::Base
|
||||
def reset
|
||||
super
|
||||
@result = 'ListServicesResult'
|
||||
@response[@result] = {'serviceArns' => []}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'member'
|
||||
@response[@result]['serviceArns'] << value
|
||||
when 'NextToken'
|
||||
@response[@result][name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
27
lib/fog/aws/parsers/ecs/list_task_definition_families.rb
Normal file
27
lib/fog/aws/parsers/ecs/list_task_definition_families.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/base'
|
||||
|
||||
class ListTaskDefinitionFamilies < Fog::Parsers::AWS::ECS::Base
|
||||
def reset
|
||||
super
|
||||
@result = 'ListTaskDefinitionFamiliesResult'
|
||||
@response[@result] = {'families' => []}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'member'
|
||||
@response[@result]['families'] << value
|
||||
when 'NextToken'
|
||||
@response[@result][name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
27
lib/fog/aws/parsers/ecs/list_task_definitions.rb
Normal file
27
lib/fog/aws/parsers/ecs/list_task_definitions.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/base'
|
||||
|
||||
class ListTaskDefinitions < Fog::Parsers::AWS::ECS::Base
|
||||
def reset
|
||||
super
|
||||
@result = 'ListTaskDefinitionsResult'
|
||||
@response[@result] = {'taskDefinitionArns' => []}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'member'
|
||||
@response[@result]['taskDefinitionArns'] << value
|
||||
when 'NextToken'
|
||||
@response[@result][name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
27
lib/fog/aws/parsers/ecs/list_tasks.rb
Normal file
27
lib/fog/aws/parsers/ecs/list_tasks.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/base'
|
||||
|
||||
class ListTasks < Fog::Parsers::AWS::ECS::Base
|
||||
def reset
|
||||
super
|
||||
@result = 'ListTasksResult'
|
||||
@response[@result] = {'taskArns' => []}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'member'
|
||||
@response[@result]['taskArns'] << value
|
||||
when 'NextToken'
|
||||
@response[@result][name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
32
lib/fog/aws/parsers/ecs/register_task_definition.rb
Normal file
32
lib/fog/aws/parsers/ecs/register_task_definition.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/task_definition'
|
||||
|
||||
class RegisterTaskDefinition < Fog::Parsers::AWS::ECS::TaskDefinition
|
||||
def reset
|
||||
super
|
||||
@result = 'RegisterTaskDefinitionResult'
|
||||
@definition = 'taskDefinition'
|
||||
@response[@result] = {
|
||||
@definition => {
|
||||
'volumes' => [],
|
||||
'containerDefinitions' => []
|
||||
}
|
||||
}
|
||||
@contexts = %w(volumes containerDefinitions command entryPoint environment links mountPoints portMappings volumesFrom)
|
||||
@context = []
|
||||
@volume = {}
|
||||
@host = {}
|
||||
@container = {}
|
||||
@environment = {}
|
||||
@mountpoint = {}
|
||||
@portmapping = {}
|
||||
@volume_from = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
24
lib/fog/aws/parsers/ecs/run_task.rb
Normal file
24
lib/fog/aws/parsers/ecs/run_task.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/task'
|
||||
|
||||
class RunTask < Fog::Parsers::AWS::ECS::Task
|
||||
def reset
|
||||
super
|
||||
@result = 'RunTaskResult'
|
||||
@response[@result] = {'failures' => [], 'tasks' => []}
|
||||
@contexts = %w(failures tasks containers overrides networkBindings containerOverrides)
|
||||
@context = []
|
||||
@task = {}
|
||||
@failure = {}
|
||||
@container = {}
|
||||
@net_binding = {}
|
||||
@container_overrides = []
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
82
lib/fog/aws/parsers/ecs/service.rb
Normal file
82
lib/fog/aws/parsers/ecs/service.rb
Normal file
|
@ -0,0 +1,82 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/base'
|
||||
|
||||
class Service < Fog::Parsers::AWS::ECS::Base
|
||||
def start_element(name, attrs = [])
|
||||
super
|
||||
if @contexts.include?(name)
|
||||
@context.push(name)
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when *@contexts
|
||||
@context.pop
|
||||
when 'member'
|
||||
case @context.last
|
||||
when 'services'
|
||||
@response[@result]['services'] << @service
|
||||
@service = {}
|
||||
when 'loadBalancers'
|
||||
@service['loadBalancers'] ||= []
|
||||
@service['loadBalancers'] << @load_balancer
|
||||
@load_balancer = {}
|
||||
when 'events'
|
||||
@service['events'] ||= []
|
||||
@service['events'] << @event
|
||||
@event = {}
|
||||
when 'deployments'
|
||||
@service['deployments'] ||= []
|
||||
@service['deployments'] << @deployment
|
||||
@deployment = {}
|
||||
end
|
||||
when 'clusterArn', 'roleArn', 'serviceArn', 'serviceName'
|
||||
@service[name] = value
|
||||
when 'taskDefinition', 'status'
|
||||
case @context.last
|
||||
when 'service', 'services'
|
||||
@service[name] = value
|
||||
when 'deployments'
|
||||
@deployment[name] = value
|
||||
end
|
||||
when 'desiredCount', 'pendingCount', 'runningCount'
|
||||
case @context.last
|
||||
when 'service', 'services'
|
||||
@service[name] = value.to_i
|
||||
when 'deployments'
|
||||
@deployment[name] = value.to_i
|
||||
end
|
||||
when 'loadBalancerName', 'containerName'
|
||||
@load_balancer[name] = value
|
||||
when 'containerPort'
|
||||
@load_balancer[name] = value.to_i
|
||||
when 'createdAt'
|
||||
case @context.last
|
||||
when 'events'
|
||||
@event[name] = Time.parse(value)
|
||||
when 'deployments'
|
||||
@deployment[name] = Time.parse(value)
|
||||
end
|
||||
when 'id'
|
||||
case @context.last
|
||||
when 'events'
|
||||
@event[name] = value
|
||||
when 'deployments'
|
||||
@deployment[name] = value
|
||||
end
|
||||
when 'message'
|
||||
@event[name] = value
|
||||
when 'updatedAt'
|
||||
@deployment[name] = Time.parse(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
24
lib/fog/aws/parsers/ecs/start_task.rb
Normal file
24
lib/fog/aws/parsers/ecs/start_task.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/task'
|
||||
|
||||
class StartTask < Fog::Parsers::AWS::ECS::Task
|
||||
def reset
|
||||
super
|
||||
@result = 'StartTaskResult'
|
||||
@response[@result] = {'failures' => [], 'tasks' => []}
|
||||
@contexts = %w(failures tasks containers overrides networkBindings containerOverrides)
|
||||
@context = []
|
||||
@task = {}
|
||||
@failure = {}
|
||||
@container = {}
|
||||
@net_binding = {}
|
||||
@container_overrides = []
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
23
lib/fog/aws/parsers/ecs/stop_task.rb
Normal file
23
lib/fog/aws/parsers/ecs/stop_task.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/task'
|
||||
|
||||
class StopTask < Fog::Parsers::AWS::ECS::Task
|
||||
def reset
|
||||
super
|
||||
@result = 'StopTaskResult'
|
||||
@response[@result] = {'task' => {}}
|
||||
@contexts = %w(task containers overrides networkBindings containerOverrides)
|
||||
@context = []
|
||||
@task = {}
|
||||
@container = {}
|
||||
@net_binding = {}
|
||||
@container_overrides = []
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
77
lib/fog/aws/parsers/ecs/task.rb
Normal file
77
lib/fog/aws/parsers/ecs/task.rb
Normal file
|
@ -0,0 +1,77 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/base'
|
||||
|
||||
class Task < Fog::Parsers::AWS::ECS::Base
|
||||
def start_element(name, attrs = [])
|
||||
super
|
||||
if @contexts.include?(name)
|
||||
@context.push(name)
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'containerOverrides'
|
||||
@task['overrides'] ||= {}
|
||||
@task['overrides'][name] = @container_overrides
|
||||
@context.pop
|
||||
when 'task'
|
||||
@response[@result][name] = @task
|
||||
when *@contexts
|
||||
@context.pop
|
||||
when 'member'
|
||||
case @context.last
|
||||
when 'tasks'
|
||||
@response[@result]['tasks'] << @task
|
||||
@task = {}
|
||||
when 'containers'
|
||||
@task['containers'] ||= []
|
||||
@task['containers'] << @container
|
||||
@container = {}
|
||||
when 'networkBindings'
|
||||
@container['networkBindings'] ||= []
|
||||
@container['networkBindings'] << @net_binding
|
||||
@net_binding = {}
|
||||
when 'failures'
|
||||
@response[@result]['failures'] << @failure
|
||||
@failure = {}
|
||||
end
|
||||
when 'clusterArn', 'desiredStatus', 'startedBy', 'containerInstanceArn', 'taskDefinitionArn'
|
||||
@task[name] = value
|
||||
when 'taskArn', 'lastStatus'
|
||||
case @context.last
|
||||
when 'tasks'
|
||||
@task[name] = value
|
||||
when 'containers'
|
||||
@container[name] = value
|
||||
end
|
||||
when 'containerArn'
|
||||
@container[name] = value
|
||||
when 'exitCode'
|
||||
@container[name] = value.to_i
|
||||
when 'name'
|
||||
case @context.last
|
||||
when 'containers'
|
||||
@container[name] = value
|
||||
when 'containerOverrides'
|
||||
@container_overrides << value
|
||||
end
|
||||
when 'networkBindings'
|
||||
@container[name] = @net_bindings
|
||||
when 'bindIP'
|
||||
@net_binding[name] = value
|
||||
when 'hostPort', 'containerPort'
|
||||
@net_binding[name] = value.to_i
|
||||
when 'arn', 'reason'
|
||||
@failure[name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
95
lib/fog/aws/parsers/ecs/task_definition.rb
Normal file
95
lib/fog/aws/parsers/ecs/task_definition.rb
Normal file
|
@ -0,0 +1,95 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/base'
|
||||
|
||||
class TaskDefinition < Fog::Parsers::AWS::ECS::Base
|
||||
def start_element(name, attrs = [])
|
||||
super
|
||||
if @contexts.include?(name)
|
||||
@context.push(name)
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'taskDefinitionArn'
|
||||
@response[@result][@definition][name] = value
|
||||
when 'revision'
|
||||
@response[@result][@definition][name] = value.to_i
|
||||
when *@contexts
|
||||
@context.pop
|
||||
when 'member'
|
||||
case @context.last
|
||||
when 'volumes'
|
||||
@response[@result][@definition]['volumes'] << @volume
|
||||
@volume = {}
|
||||
when 'containerDefinitions'
|
||||
@response[@result][@definition]['containerDefinitions'] << @container
|
||||
@container = {}
|
||||
when 'command'
|
||||
@container['command'] ||= []
|
||||
@container['command'] << value
|
||||
when 'entryPoint'
|
||||
@container['entryPoint'] ||= []
|
||||
@container['entryPoint'] << value
|
||||
when 'links'
|
||||
@container['links'] ||= []
|
||||
@container['links'] << value
|
||||
when 'environment'
|
||||
@container['environment'] ||= []
|
||||
@container['environment'] << @environment
|
||||
@environment = {}
|
||||
when 'mountPoints'
|
||||
@container['mountPoints'] ||= []
|
||||
@container['mountPoints'] << @mountpoint
|
||||
@mountpoint = {}
|
||||
when 'portMappings'
|
||||
@container['portMappings'] ||= []
|
||||
@container['portMappings'] << @portmapping
|
||||
@portmapping = {}
|
||||
end
|
||||
when 'name'
|
||||
case @context.last
|
||||
when 'volumes'
|
||||
@volume[name] = value
|
||||
when 'containerDefinitions'
|
||||
@container[name] = value
|
||||
when 'environment'
|
||||
@environment[name] = value
|
||||
end
|
||||
when 'host'
|
||||
@volume[name] = @host
|
||||
@host = {}
|
||||
when 'sourcePath'
|
||||
@host[name] = value
|
||||
when 'cpu', 'memory'
|
||||
@container[name] = value.to_i
|
||||
when 'essential'
|
||||
@container[name] = value == 'true'
|
||||
when 'image'
|
||||
@container[name] = value
|
||||
when 'value'
|
||||
@environment[name] = value
|
||||
when 'readOnly'
|
||||
case @context.last
|
||||
when 'mountPoints'
|
||||
@mountpoint[name] = value == 'true'
|
||||
when 'volumesFrom'
|
||||
@volume_from[name] = value == 'true'
|
||||
end
|
||||
when 'containerPath', 'sourceVolume'
|
||||
@mountpoint[name] = value
|
||||
when 'containerPort', 'hostPort'
|
||||
@portmapping[name] = value.to_i
|
||||
when 'sourceContainer'
|
||||
@volume_from[name] = value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
31
lib/fog/aws/parsers/ecs/update_service.rb
Normal file
31
lib/fog/aws/parsers/ecs/update_service.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
module Fog
|
||||
module Parsers
|
||||
module AWS
|
||||
module ECS
|
||||
require 'fog/aws/parsers/ecs/service'
|
||||
|
||||
class UpdateService < Fog::Parsers::AWS::ECS::Service
|
||||
def reset
|
||||
super
|
||||
@result = 'UpdateServiceResult'
|
||||
@response[@result] = {}
|
||||
@contexts = %w(service loadBalancers events deployments)
|
||||
@service = {}
|
||||
@context = []
|
||||
@deployment = {}
|
||||
@load_balancer = {}
|
||||
@event = {}
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
super
|
||||
case name
|
||||
when 'service'
|
||||
@response[@result]['service'] = @service
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
64
lib/fog/aws/requests/ecs/create_cluster.rb
Normal file
64
lib/fog/aws/requests/ecs/create_cluster.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/create_cluster'
|
||||
|
||||
# Creates a new Amazon ECS cluster
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_CreateCluster.html
|
||||
# ==== Parameters
|
||||
# * clusterName <~String> - The name of your cluster.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'Cluster' <~Hash> - The full description of your new cluster
|
||||
def create_cluster(params={})
|
||||
request({
|
||||
'Action' => 'CreateCluster',
|
||||
:parser => Fog::Parsers::AWS::ECS::CreateCluster.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def create_cluster(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
params.has_key?('clusterName') || params['clusterName'] = 'default'
|
||||
|
||||
owner_id = Fog::AWS::Mock.owner_id
|
||||
cluster_name = params['clusterName']
|
||||
cluster_path = "cluster/#{cluster_name}"
|
||||
cluster_arn = Fog::AWS::Mock.arn('ecs', owner_id, cluster_path, region)
|
||||
cluster = {}
|
||||
|
||||
search_cluster_result = self.data[:clusters].select { |c| c['clusterName'].eql?(cluster_name) }
|
||||
if search_cluster_result.empty?
|
||||
cluster = {
|
||||
'clusterName' => cluster_name,
|
||||
'clusterArn' => cluster_arn,
|
||||
'status' => 'ACTIVE',
|
||||
'registeredContainerInstancesCount' => 0,
|
||||
'runningTasksCount' => 0,
|
||||
'pendingTasksCount' => 0
|
||||
}
|
||||
self.data[:clusters] << cluster
|
||||
else
|
||||
cluster = search_cluster_result.first
|
||||
end
|
||||
|
||||
response.body = {
|
||||
'CreateClusterResult' => {
|
||||
'cluster' => cluster
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
118
lib/fog/aws/requests/ecs/create_service.rb
Normal file
118
lib/fog/aws/requests/ecs/create_service.rb
Normal file
|
@ -0,0 +1,118 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/create_service'
|
||||
|
||||
# Runs and maintains a desired number of tasks from a specified task definition.
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_CreateService.html
|
||||
# ==== Parameters
|
||||
# * clientToken <~String> - unique, case-sensitive identifier you provide to ensure the idempotency of the request.
|
||||
# * cluster <~String> - short name or full Amazon Resource Name (ARN) of the cluster that you want to run your service on.
|
||||
# * desiredCount <~Integer> - number of instantiations of the specified task definition that you would like to place and keep running on your cluster.
|
||||
# * 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.
|
||||
# * 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.
|
||||
# * serviceName <~String> - name of your service
|
||||
# * 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
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'Service' <~Hash> - The full description of your new service
|
||||
def create_service(params={})
|
||||
if load_balancers = params.delete('loadBalancers')
|
||||
params.merge!(Fog::AWS.indexed_param('loadBalancers.member', [*load_balancers]))
|
||||
end
|
||||
request({
|
||||
'Action' => 'CreateService',
|
||||
:parser => Fog::Parsers::AWS::ECS::CreateService.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def create_service(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
e = Fog::AWS::ECS::Error
|
||||
msg = 'ClientException => desiredCount cannot be empty.'
|
||||
raise e, msg unless desired_count = params['desiredCount']
|
||||
msg = 'ClientException => serviceName cannot be empty.'
|
||||
raise e unless service_name = params['serviceName']
|
||||
msg = 'ClientException => taskDefinition cannot be empty.'
|
||||
raise e unless task_definition = params['taskDefinition']
|
||||
|
||||
owner_id = Fog::AWS::Mock.owner_id
|
||||
|
||||
service_path = "service/#{service_name}"
|
||||
service_arn = Fog::AWS::Mock.arn('ecs', owner_id, service_path, region)
|
||||
|
||||
cluster = params['cluster'] || 'default'
|
||||
if !cluster.match(/^arn:aws:ecs:.+:.+:cluster\/(.+)$/)
|
||||
cluster_path = "cluster/#{cluster}"
|
||||
cluster_arn = Fog::AWS::Mock.arn('ecs', owner_id, cluster_path, region)
|
||||
else
|
||||
cluster_arn = cluster
|
||||
end
|
||||
|
||||
if params['role']
|
||||
role = params['role'] if params['role']
|
||||
if !role.match(/^arn:aws:iam:.*:.*:role\/(.+)$/)
|
||||
role_path = "role/#{role}"
|
||||
role_arn = Fog::AWS::Mock.arn('iam', owner_id, role_path, region)
|
||||
else
|
||||
role_arn = role
|
||||
end
|
||||
end
|
||||
|
||||
if !task_definition.match(/^arn:aws:ecs:.+:.+:task-definition\/.+$/)
|
||||
task_def_path = "task-definition\/#{task_definition}"
|
||||
task_def_arn = Fog::AWS::Mock.arn('ecs', owner_id, task_def_path, region)
|
||||
else
|
||||
task_def_arn = task_definition
|
||||
end
|
||||
|
||||
load_balancers = params['loadBalancers'] || []
|
||||
|
||||
service = {
|
||||
'events' => [],
|
||||
'serviceName' => service_name,
|
||||
'serviceArn' => service_arn,
|
||||
'taskDefinition' => task_def_arn,
|
||||
'clusterArn' => cluster_arn,
|
||||
'status' => 'ACTIVE',
|
||||
'roleArn' => role_arn,
|
||||
'loadBalancers' => [*load_balancers],
|
||||
'deployments' => [],
|
||||
'desiredCount' => desired_count,
|
||||
'pendingCount' => 0,
|
||||
'runningCount' => 0
|
||||
}
|
||||
|
||||
service['deployments'] << {
|
||||
'updatedAt' => Time.now.utc,
|
||||
'id' => "ecs-svc/#{Fog::Mock.random_numbers(19)}",
|
||||
'taskDefinition' => task_def_arn,
|
||||
'status' => 'PRIMARY',
|
||||
'desiredCount' => desired_count,
|
||||
'createdAt' => Time.now.utc,
|
||||
'pendingCount' => 0,
|
||||
'runningCount' => 0
|
||||
}
|
||||
|
||||
self.data[:services] << service
|
||||
|
||||
response.body = {
|
||||
'CreateServiceResult' => {
|
||||
'service' => service,
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
61
lib/fog/aws/requests/ecs/delete_cluster.rb
Normal file
61
lib/fog/aws/requests/ecs/delete_cluster.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/delete_cluster'
|
||||
|
||||
# Deletes the specified cluster
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DeleteCluster.html
|
||||
# ==== Parameters
|
||||
# * cluster <~String> - The short name or full Amazon Resource Name (ARN) of the cluster that you want to delete
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'Cluster'<~Hash> - The full description of the deleted cluster
|
||||
def delete_cluster(params={})
|
||||
request({
|
||||
'Action' => 'DeleteCluster',
|
||||
:parser => Fog::Parsers::AWS::ECS::DeleteCluster.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def delete_cluster(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
cluster_id = params.delete('cluster')
|
||||
|
||||
if !cluster_id
|
||||
message = 'ClientException => Cluster can not be blank.'
|
||||
raise Fog::AWS::ECS::Error, message
|
||||
end
|
||||
|
||||
if match = cluster_id.match(/^arn:aws:ecs:.+:\d{1,12}:cluster\/(.+)$/)
|
||||
i = self.data[:clusters].index { |c| c['clusterArn'].eql?(cluster_id) }
|
||||
else
|
||||
i = self.data[:clusters].index { |c| c['clusterName'].eql?(cluster_id) }
|
||||
end
|
||||
|
||||
if i
|
||||
cluster = self.data[:clusters].delete_at(i)
|
||||
else
|
||||
raise Fog::AWS::ECS::NotFound, 'Cluster not found.'
|
||||
end
|
||||
|
||||
cluster['status'] = 'INACTIVE'
|
||||
response.body = {
|
||||
'DeleteClusterResult' => {
|
||||
'cluster' => cluster
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
72
lib/fog/aws/requests/ecs/delete_service.rb
Normal file
72
lib/fog/aws/requests/ecs/delete_service.rb
Normal file
|
@ -0,0 +1,72 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/delete_service'
|
||||
|
||||
# Deletes a specified service within a cluster.
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DeleteService.html
|
||||
# ==== Parameters
|
||||
# * cluster <~String> - name of the cluster that hosts the service you want to delete.
|
||||
# * service <~String> - name of the service you want to delete.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'Service'<~Hash> - The full description of the deleted service
|
||||
def delete_service(params={})
|
||||
request({
|
||||
'Action' => 'DeleteService',
|
||||
:parser => Fog::Parsers::AWS::ECS::DeleteService.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def delete_service(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
service_id = params.delete('service')
|
||||
msg = 'ClientException => Service cannot be empty.'
|
||||
raise Fog::AWS::ECS::Error, msg unless service_id
|
||||
|
||||
owner_id = Fog::AWS::Mock.owner_id
|
||||
|
||||
cluster = params.delete('cluster') || 'default'
|
||||
if !cluster.match(/^arn:aws:ecs:.+:.+:cluster\/(.+)$/)
|
||||
cluster_path = "cluster/#{cluster}"
|
||||
cluster_arn = Fog::AWS::Mock.arn('ecs', owner_id, cluster_path, region)
|
||||
else
|
||||
cluster_arn = cluster
|
||||
end
|
||||
|
||||
if match = service_id.match(/^arn:aws:ecs:.+:\d{1,12}:service\/(.+)$/)
|
||||
i = self.data[:services].index do |s|
|
||||
s['clusterArn'].eql?(cluster_arn) && s['serviceArn'].eql?(service_id)
|
||||
end
|
||||
else
|
||||
i = self.data[:services].index do |s|
|
||||
s['clusterArn'].eql?(cluster_arn) && s['serviceName'].eql?(service_id)
|
||||
end
|
||||
end
|
||||
|
||||
msg = "ServiceNotFoundException => Service not found."
|
||||
raise Fog::AWS::ECS::Error, msg unless i
|
||||
|
||||
service = self.data[:services][i]
|
||||
self.data[:services].delete_at(i)
|
||||
|
||||
response.body = {
|
||||
'DeleteServiceResult' => {
|
||||
'service' => service
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
63
lib/fog/aws/requests/ecs/deregister_container_instance.rb
Normal file
63
lib/fog/aws/requests/ecs/deregister_container_instance.rb
Normal file
|
@ -0,0 +1,63 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/deregister_container_instance'
|
||||
|
||||
# Deregisters an Amazon ECS container instance from the specified cluster.
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DeregisterContainerInstance.html
|
||||
# ==== Parameters
|
||||
# * cluster <~String> - short name or full ARN of the cluster that hosts the container instance you want to deregister.
|
||||
# * containerInstance <~String> - container instance UUID or full Amazon Resource Name (ARN) of the container instance you want to deregister.
|
||||
# * force <~Boolean> - Force the deregistration of the container instance.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'ContainerInstance' <~Hash> - full description of the deregistered container instance
|
||||
def deregister_container_instance(params={})
|
||||
request({
|
||||
'Action' => 'DeregisterContainerInstance',
|
||||
:parser => Fog::Parsers::AWS::ECS::DeregisterContainerInstance.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def deregister_container_instance(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
instance_id = params.delete('containerInstance')
|
||||
instance_error = "ClientException => Container instance can not be blank."
|
||||
raise Fog::AWS::ECS::Error, instance_error unless instance_id
|
||||
|
||||
if match = instance_id.match(/^arn:aws:ecs:.+:\d{1,12}:container-instance\/(.+)$/)
|
||||
i = self.data[:container_instances].index do |inst|
|
||||
inst['containerInstanceArn'].eql?(instance_id)
|
||||
end
|
||||
else
|
||||
i = self.data[:container_instances].index do |inst|
|
||||
inst['containerInstanceArn'].match(/#{instance_id}$/)
|
||||
end
|
||||
end
|
||||
|
||||
msg = "ClientException => Referenced container instance #{instance_id} not found."
|
||||
raise Fog::AWS::ECS::Error, msg unless i
|
||||
|
||||
instance = self.data[:container_instances][i]
|
||||
self.data[:container_instances].delete_at(i)
|
||||
|
||||
response.body = {
|
||||
'DeregisterContainerInstanceResult' => {
|
||||
'containerInstance' => instance
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
58
lib/fog/aws/requests/ecs/deregister_task_definition.rb
Normal file
58
lib/fog/aws/requests/ecs/deregister_task_definition.rb
Normal file
|
@ -0,0 +1,58 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/deregister_task_definition'
|
||||
|
||||
# Deregisters the specified task definition.
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DeregisterTaskDefinition.html
|
||||
# ==== Parameters
|
||||
# * taskDefinition <~String> - The family and revision (family:revision) or full Amazon Resource Name (ARN) of the task definition that you want to deregister.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'TaskDefinition' <~Hash> - full description of the deregistered task
|
||||
def deregister_task_definition(params={})
|
||||
request({
|
||||
'Action' => 'DeregisterTaskDefinition',
|
||||
:parser => Fog::Parsers::AWS::ECS::DeregisterTaskDefinition.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def deregister_task_definition(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
taskdef_error = "ClientException => Task Definition can not be blank."
|
||||
raise Fog::AWS::ECS::Error, taskdef_error unless params['taskDefinition']
|
||||
|
||||
task_def_name = params['taskDefinition']
|
||||
|
||||
case task_def_name
|
||||
when /^arn:aws:ecs:.+:\d{1,12}:task-definition\/(.+:.+)$/
|
||||
i = self.data[:task_definitions].index { |t| t['taskDefinitionArn'].eql?(task_def_name) }
|
||||
when /^(.+:.+)$/
|
||||
i = self.data[:task_definitions].index { |t| t['taskDefinitionArn'].match(/task-definition\/#{task_def_name}$/) }
|
||||
else
|
||||
raise Fog::AWS::ECS::Error, 'Invalid task definition'
|
||||
end
|
||||
|
||||
raise Fog::AWS::ECS::NotFound, 'Task definition not found.' unless i
|
||||
task_definition = self.data[:task_definitions].delete_at(i)
|
||||
|
||||
response.body = {
|
||||
'DeregisterTaskDefinitionResult' => {
|
||||
'taskDefinition' => task_definition
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
83
lib/fog/aws/requests/ecs/describe_clusters.rb
Normal file
83
lib/fog/aws/requests/ecs/describe_clusters.rb
Normal file
|
@ -0,0 +1,83 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/describe_clusters'
|
||||
|
||||
# Describes one or more of your clusters.
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeClusters.html
|
||||
# ==== Parameters
|
||||
# * clusters <~Array> - list of cluster names or full cluster Amazon Resource Name (ARN) entries
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'clusters' <~Array> - The list of clusters
|
||||
# * 'failures' <~Array> - The list of failures (if any)
|
||||
def describe_clusters(params={})
|
||||
if members = params.delete('clusters')
|
||||
params.merge!(Fog::AWS.indexed_param('clusters.member', [*members]))
|
||||
end
|
||||
|
||||
request({
|
||||
'Action' => 'DescribeClusters',
|
||||
:parser => Fog::Parsers::AWS::ECS::DescribeClusters.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def describe_clusters(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
members = params.delete('clusters')
|
||||
members = 'default' unless members
|
||||
clusters = []
|
||||
failures = []
|
||||
|
||||
[*members].each do |c|
|
||||
if match = c.match(/^arn:aws:ecs:.+:\d{1,12}:cluster\/(.+)$/)
|
||||
result = self.data[:clusters].select { |cl| cl['clusterArn'].eql?(c) }
|
||||
else
|
||||
result = self.data[:clusters].select { |cl| cl['clusterName'].eql?(c) }
|
||||
end
|
||||
if result.empty?
|
||||
cluster_name = match[1] if match
|
||||
cluster_name = c unless match
|
||||
failures << { 'name' => cluster_name }
|
||||
else
|
||||
clusters << result.first
|
||||
end
|
||||
end
|
||||
|
||||
owner_id = Fog::AWS::Mock.owner_id
|
||||
|
||||
failures.map! do |f|
|
||||
{
|
||||
'arn' => Fog::AWS::Mock.arn('ecs', owner_id, "cluster/#{f['name']}", region),
|
||||
'reason' => 'MISSING'
|
||||
}
|
||||
end
|
||||
clusters.map! do |c|
|
||||
{
|
||||
'clusterName' => c['clusterName'],
|
||||
'clusterArn' => c['clusterArn'],
|
||||
'status' => c['status']
|
||||
}
|
||||
end
|
||||
|
||||
response.body = {
|
||||
'DescribeClustersResult' => {
|
||||
'failures' => failures,
|
||||
'clusters' => clusters
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
64
lib/fog/aws/requests/ecs/describe_container_instances.rb
Normal file
64
lib/fog/aws/requests/ecs/describe_container_instances.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/describe_container_instances'
|
||||
|
||||
# Describes Amazon EC2 Container Service container instances.
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeContainerInstances.html
|
||||
# ==== Parameters
|
||||
# * cluster <~String> - short name or full ARN of the cluster that hosts the container instances you want to describe.
|
||||
# * containerInstances <~Array> - list of container instance UUIDs or full Amazon Resource Name (ARN) entries.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'containerInstances' <~Array> - list of container instances.
|
||||
# * 'failures' <~Array> - list of failures (if any)
|
||||
def describe_container_instances(params={})
|
||||
if instances = params.delete('containerInstances')
|
||||
params.merge!(Fog::AWS.indexed_param('containerInstances.member', [*instances]))
|
||||
end
|
||||
|
||||
request({
|
||||
'Action' => 'DescribeContainerInstances',
|
||||
:parser => Fog::Parsers::AWS::ECS::DescribeContainerInstances.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def describe_container_instances(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
cluster = params.delete('cluster') || 'default'
|
||||
|
||||
instances_id = params.delete('containerInstances')
|
||||
msg = 'ClientException => Container instance cannot be empty.'
|
||||
raise Fog::AWS::ECS::Error, msg unless instances_id
|
||||
|
||||
result = []
|
||||
[*instances_id].each do |inst|
|
||||
if match = inst.match(/^arn:aws:ecs:.+:\d{1,12}:container-instance\/(.+)$/)
|
||||
result = self.data[:container_instances].select { |i| i['containerInstanceArn'].eql?(inst) }
|
||||
else
|
||||
result = self.data[:container_instances].select { |i| i['containerInstanceArn'].match(/#{inst}$/) }
|
||||
end
|
||||
end
|
||||
|
||||
instances = result
|
||||
response.body = {
|
||||
'DescribeContainerInstancesResult' => {
|
||||
'containerInstances' => instances,
|
||||
'failures' => []
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
76
lib/fog/aws/requests/ecs/describe_services.rb
Normal file
76
lib/fog/aws/requests/ecs/describe_services.rb
Normal file
|
@ -0,0 +1,76 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/describe_services'
|
||||
|
||||
# Describes the specified services running in your cluster.
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeServices.html
|
||||
# ==== Parameters
|
||||
# * cluster <~String> - name of the cluster that hosts the service you want to describe.
|
||||
# * services <~Array> - list of services you want to describe.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'services' <~Array> - The list of services described.
|
||||
# * 'failures' <~Array> - The list of failures associated with the call (if any).
|
||||
def describe_services(params={})
|
||||
if services = params.delete('services')
|
||||
params.merge!(Fog::AWS.indexed_param('services.member', [*services]))
|
||||
end
|
||||
|
||||
request({
|
||||
'Action' => 'DescribeServices',
|
||||
:parser => Fog::Parsers::AWS::ECS::DescribeServices.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def describe_services(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
cluster = params.delete('cluster') || 'default'
|
||||
services = params.delete('services')
|
||||
msg = 'InvalidParameterException => Services cannot be empty.'
|
||||
raise Fog::AWS::ECS::Error, msg unless services
|
||||
|
||||
owner_id = Fog::AWS::Mock.owner_id
|
||||
|
||||
if !cluster.match(/^arn:aws:ecs:.+:.+:cluster\/(.+)$/)
|
||||
cluster_path = "cluster/#{cluster}"
|
||||
cluster_arn = Fog::AWS::Mock.arn('ecs', owner_id, cluster_path, region)
|
||||
else
|
||||
cluster_arn = cluster
|
||||
end
|
||||
|
||||
result = []
|
||||
([*services].select { |s| s.match(/^arn:/) }).each do |ds|
|
||||
result.concat(self.data[:services].select do |sv|
|
||||
sv['serviceArn'].eql?(ds) && sv['clusterArn'].eql?(cluster_arn)
|
||||
end)
|
||||
end
|
||||
([*services].select { |s| !s.match(/^arn:/) }).each do |ds|
|
||||
result.concat(self.data[:services].select do |sv|
|
||||
sv['serviceName'].eql?(ds) && sv['clusterArn'].eql?(cluster_arn)
|
||||
end)
|
||||
end
|
||||
|
||||
response.body = {
|
||||
'DescribeServicesResult' => {
|
||||
'services' => result,
|
||||
'failures' => []
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
64
lib/fog/aws/requests/ecs/describe_task_definition.rb
Normal file
64
lib/fog/aws/requests/ecs/describe_task_definition.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/describe_task_definition'
|
||||
|
||||
# Describes a task definition
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeTaskDefinition.html
|
||||
# ==== Parameters
|
||||
# * 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.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'taskDefinition' <~Hash> - full task definition description
|
||||
def describe_task_definition(params={})
|
||||
request({
|
||||
'Action' => 'DescribeTaskDefinition',
|
||||
:parser => Fog::Parsers::AWS::ECS::DescribeTaskDefinition.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def describe_task_definition(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
taskdef_error = "ClientException => Task Definition can not be blank."
|
||||
raise Fog::AWS::ECS::Error, taskdef_error unless params['taskDefinition']
|
||||
|
||||
task_def_name = params['taskDefinition']
|
||||
|
||||
case task_def_name
|
||||
when /^arn:aws:ecs:.+:\d{1,12}:task-definition\/(.+:.+)$/
|
||||
result = self.data[:task_definitions].select { |t| t['taskDefinitionArn'].eql?(task_def_name) }
|
||||
when /^(.+:.+)$/
|
||||
result = self.data[:task_definitions].select { |t| t['taskDefinitionArn'].match(/task-definition\/#{task_def_name}/) }
|
||||
else
|
||||
result = self.data[:task_definitions].select { |t| t['family'].eql?(task_def_name) }
|
||||
if !result.empty?
|
||||
result = [] << (result.max_by { |t| t['revision'] })
|
||||
end
|
||||
end
|
||||
|
||||
if result.empty?
|
||||
raise Fog::AWS::ECS::Error, 'ClientException => Unable to describe task definition.'
|
||||
end
|
||||
|
||||
task_definition = result.first
|
||||
|
||||
response.body = {
|
||||
'DescribeTaskDefinitionResult' => {
|
||||
'taskDefinition' => task_definition
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
65
lib/fog/aws/requests/ecs/describe_tasks.rb
Normal file
65
lib/fog/aws/requests/ecs/describe_tasks.rb
Normal file
|
@ -0,0 +1,65 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/describe_tasks'
|
||||
|
||||
# Describes a specified task or tasks.
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeTasks.html
|
||||
# ==== Parameters
|
||||
# * cluster <~String> - short name or full Amazon Resource Name (ARN) of the cluster that hosts the task you want to describe
|
||||
# * tasks <~Array> - space-separated list of task UUIDs or full Amazon Resource Name (ARN) entries
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'tasks' <~Array> - The list of tasks
|
||||
# * 'failures' <~Array> - The list of failures (if any)
|
||||
def describe_tasks(params={})
|
||||
if tasks = params.delete('tasks')
|
||||
params.merge!(Fog::AWS.indexed_param('tasks.member', [*tasks]))
|
||||
end
|
||||
|
||||
request({
|
||||
'Action' => 'DescribeTasks',
|
||||
:parser => Fog::Parsers::AWS::ECS::DescribeTasks.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def describe_tasks(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
unless tasks = params.delete('tasks')
|
||||
msg = 'InvalidParameterException => Tasks cannot be empty.'
|
||||
raise Fog::AWS::ECS::Error, msg
|
||||
end
|
||||
|
||||
cluster = params.delete('cluster') || 'default'
|
||||
|
||||
result = []
|
||||
[*tasks].each do |tid|
|
||||
if match = tid.match(/^arn:aws:ecs:.+:\d{1,12}:task\/(.+)$/)
|
||||
result = self.data[:tasks].select { |t| t['taskArn'].eql?(tid) }
|
||||
else
|
||||
result = self.data[:tasks].select { |t| t['taskArn'].match(/#{tid}$/) }
|
||||
end
|
||||
end
|
||||
|
||||
tasks = result
|
||||
response.body = {
|
||||
'DescribeTasksResult' => {
|
||||
'failures' => [],
|
||||
'tasks' => tasks
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
45
lib/fog/aws/requests/ecs/list_clusters.rb
Normal file
45
lib/fog/aws/requests/ecs/list_clusters.rb
Normal file
|
@ -0,0 +1,45 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/list_clusters'
|
||||
|
||||
# Returns a list of existing clusters
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListClusters.html
|
||||
# ==== Parameters
|
||||
# * maxResults <~Integer> - The maximum number of cluster results returned by ListClusters in paginated output.
|
||||
# * nextToken <~String> - The nextToken value returned from a previous paginated ListClusters request where maxResults was used.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'ClusterArns' <~Array> - list of full Amazon Resource Name (ARN) entries for each cluster associated with your account.
|
||||
# * 'NextToken' <~String> - nextToken value to include in a future ListClusters request.
|
||||
def list_clusters(params={})
|
||||
request({
|
||||
'Action' => 'ListClusters',
|
||||
:parser => Fog::Parsers::AWS::ECS::ListClusters.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_clusters(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
cluster_arns = self.data[:clusters].map { |c| c['clusterArn'] }
|
||||
|
||||
response.body = {
|
||||
'ListClustersResult' => {
|
||||
'clusterArns' => cluster_arns
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
46
lib/fog/aws/requests/ecs/list_container_instances.rb
Normal file
46
lib/fog/aws/requests/ecs/list_container_instances.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/list_container_instances'
|
||||
|
||||
# Returns a list of container instances in a specified cluster.
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListContainerInstances.html
|
||||
# ==== Parameters
|
||||
# * cluster <~String> - short name or full Amazon Resource Name (ARN) of the cluster that hosts the container instances you want to list.
|
||||
# * maxResults <~Integer> - maximum number of container instance results returned by ListContainerInstances in paginated output.
|
||||
# * nextToken <~String> - nextToken value returned from a previous paginated ListContainerInstances request where maxResults was used.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'ContainerInstanceArns' <~Array> - list of container instance full ARN entries for each container instance associated with the specified cluster.
|
||||
# * 'NextToken' <~String> - nextToken value to include in a future ListContainerInstances request.
|
||||
def list_container_instances(params={})
|
||||
request({
|
||||
'Action' => 'ListContainerInstances',
|
||||
:parser => Fog::Parsers::AWS::ECS::ListContainerInstances.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_container_instances(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
instance_arns = self.data[:container_instances].map { |i| i['containerInstanceArn'] }
|
||||
|
||||
response.body = {
|
||||
'ListContainerInstancesResult' => {
|
||||
'containerInstanceArns' => instance_arns
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
59
lib/fog/aws/requests/ecs/list_services.rb
Normal file
59
lib/fog/aws/requests/ecs/list_services.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/list_services'
|
||||
|
||||
# Lists the services that are running in a specified cluster.
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListServices.html
|
||||
# ==== Parameters
|
||||
# * cluster <~String> - The short name or full Amazon Resource Name (ARN) of the cluster that hosts the services you want to list.
|
||||
# * maxResults <~Integer> - The maximum number of container instance results returned by ListServices in paginated output.
|
||||
# * nextToken <~String> - The nextToken value returned from a previous paginated ListServices request where maxResults was used.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'ServiceArns' <~Array> - list of full Amazon Resource Name (ARN) entries for each service associated with the specified cluster.
|
||||
# * 'NextToken' <~String> - nextToken value to include in a future ListServices request.
|
||||
def list_services(params={})
|
||||
request({
|
||||
'Action' => 'ListServices',
|
||||
:parser => Fog::Parsers::AWS::ECS::ListServices.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_services(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
owner_id = Fog::AWS::Mock.owner_id
|
||||
|
||||
cluster = params.delete('cluster') || 'default'
|
||||
if !cluster.match(/^arn:aws:ecs:.+:.+:cluster\/(.+)$/)
|
||||
cluster_path = "cluster/#{cluster}"
|
||||
cluster_arn = Fog::AWS::Mock.arn('ecs', owner_id, cluster_path, region)
|
||||
else
|
||||
cluster_arn = cluster
|
||||
end
|
||||
|
||||
result = self.data[:services].select do |s|
|
||||
s['clusterArn'].eql?(cluster_arn)
|
||||
end
|
||||
service_arns = result.map { |s| s['serviceArn'] }
|
||||
|
||||
response.body = {
|
||||
'ListServicesResult' => {
|
||||
'serviceArns' => service_arns
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
56
lib/fog/aws/requests/ecs/list_task_definition_families.rb
Normal file
56
lib/fog/aws/requests/ecs/list_task_definition_families.rb
Normal file
|
@ -0,0 +1,56 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/list_task_definition_families'
|
||||
|
||||
# Returns a list of task definition families that are registered to your account.
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListTaskDefinitionFamilies.html
|
||||
# ==== Parameters
|
||||
# * familyPrefix <~String> - familyPrefix is a string that is used to filter the results of ListTaskDefinitionFamilies.
|
||||
# * maxResults <~Integer> - maximum number of task definition family results returned by ListTaskDefinitionFamilies in paginated output.
|
||||
# * nextToken <~String> - nextToken value returned from a previous paginated ListTaskDefinitionFamilies request where maxResults was used.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'Families' <~Array> - list of task definition family names that match the ListTaskDefinitionFamilies request.
|
||||
# * 'NextToken' <~String> - nextToken value to include in a future ListTaskDefinitionFamilies request.
|
||||
def list_task_definition_families(params={})
|
||||
request({
|
||||
'Action' => 'ListTaskDefinitionFamilies',
|
||||
:parser => Fog::Parsers::AWS::ECS::ListTaskDefinitionFamilies.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_task_definition_families(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
family_prefix = params['familyPrefix']
|
||||
|
||||
if family_prefix
|
||||
result = self.data[:task_definitions].select do |t|
|
||||
t['family'].match(/^#{family_prefix}/)
|
||||
end
|
||||
else
|
||||
result = self.data[:task_definitions].dup
|
||||
end
|
||||
result.map! { |t| t['family'] }
|
||||
result.uniq!
|
||||
|
||||
response.body = {
|
||||
'ListTaskDefinitionFamiliesResult' => {
|
||||
'families' => result
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
55
lib/fog/aws/requests/ecs/list_task_definitions.rb
Normal file
55
lib/fog/aws/requests/ecs/list_task_definitions.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/list_task_definitions'
|
||||
|
||||
# Returns a list of task definitions that are registered to your account
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListTaskDefinitions.html
|
||||
# ==== Parameters
|
||||
# * familyPrefix <~String> - The full family name that you want to filter the ListTaskDefinitions results with.
|
||||
# * maxResults <~Integer> - The maximum number of task definition results returned by ListTaskDefinitions in paginated output.
|
||||
# * nextToken <~String> - The nextToken value returned from a previous paginated ListTaskDefinitions request.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'TaskDefinitionArns' <~Array> - list of task definition Amazon Resource Name (ARN) entries for the ListTaskDefintions request.
|
||||
# * 'NextToken' <~String> - nextToken value to include in a future ListTaskDefinitions request
|
||||
def list_task_definitions(params={})
|
||||
request({
|
||||
'Action' => 'ListTaskDefinitions',
|
||||
:parser => Fog::Parsers::AWS::ECS::ListTaskDefinitions.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_task_definitions(params={})
|
||||
if %w(
|
||||
familyPrefix
|
||||
maxResults
|
||||
nextToken
|
||||
).any? { |k| params.has_key?(k) }
|
||||
Fog::Logger.warning("list_task_definitions filters are not yet mocked [light_black](#{caller.first})[/]")
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
taskdef_arns = self.data[:task_definitions].map { |c| c['taskDefinitionArn'] }
|
||||
|
||||
response.body = {
|
||||
'ListTaskDefinitionsResult' => {
|
||||
'taskDefinitionArns' => taskdef_arns
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
50
lib/fog/aws/requests/ecs/list_tasks.rb
Normal file
50
lib/fog/aws/requests/ecs/list_tasks.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/list_tasks'
|
||||
|
||||
# Returns a list of tasks for a specified cluster.
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ListTasks.html
|
||||
# ==== Parameters
|
||||
# * cluster <~String> - short name or full Amazon Resource Name (ARN) of the cluster that hosts the tasks you want to list.
|
||||
# * containerInstance <~String> - container instance UUID or full Amazon Resource Name (ARN) of the container instance that you want to filter the ListTasks results with.
|
||||
# * family <~String> - name of the family that you want to filter the ListTasks results with.
|
||||
# * maxResults <~Integer> - maximum number of task results returned by ListTasks in paginated output.
|
||||
# * nextToken <~String> - nextToken value returned from a previous paginated ListTasks request where maxResults was used.
|
||||
# * serviceName <~String> - name of the service that you want to filter the ListTasks results with.
|
||||
# * startedBy <~String> - startedBy value that you want to filter the task results with.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'TaskArns' <~Array> - list of task Amazon Resource Name (ARN) entries for the ListTasks request.
|
||||
# * 'NextToken' <~String> - nextToken value to include in a future ListTasks request.
|
||||
def list_tasks(params={})
|
||||
request({
|
||||
'Action' => 'ListTasks',
|
||||
:parser => Fog::Parsers::AWS::ECS::ListTasks.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def list_tasks(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
task_arns = self.data[:tasks].map { |t| t['taskArn'] }
|
||||
|
||||
response.body = {
|
||||
'ListTasksResult' => {
|
||||
'taskArns' => task_arns
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
68
lib/fog/aws/requests/ecs/register_task_definition.rb
Normal file
68
lib/fog/aws/requests/ecs/register_task_definition.rb
Normal file
|
@ -0,0 +1,68 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/register_task_definition'
|
||||
|
||||
# Registers a new task definition from the supplied family and containerDefinitions.
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_RegisterTaskDefinition.html
|
||||
# ==== Parameters
|
||||
# * containerDefinitions <~Array> - list of container definitions in JSON format that describe the different containers that make up your task.
|
||||
# * family <~String> - family for a task definition, which allows you to track multiple versions of the same task definition.
|
||||
# * volumes <~String> - list of volume definitions in JSON format that containers in your task may use.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'TaskDefinition' <~Array> - full task definition description registered
|
||||
def register_task_definition(params={})
|
||||
serialized_params = {}
|
||||
params.each_pair do |k,v|
|
||||
serialized_params.merge!(Fog::AWS.serialize_keys(k, v))
|
||||
end
|
||||
request({
|
||||
'Action' => 'RegisterTaskDefinition',
|
||||
:parser => Fog::Parsers::AWS::ECS::RegisterTaskDefinition.new
|
||||
}.merge(serialized_params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def register_task_definition(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
family_error = 'ClientException => Family can not be blank.'
|
||||
container_error = 'ClientException => Container list cannot be empty.'
|
||||
raise Fog::AWS::ECS::Error, family_error unless params['family']
|
||||
raise Fog::AWS::ECS::Error, container_error unless params['containerDefinitions']
|
||||
|
||||
owner_id = Fog::AWS::Mock.owner_id
|
||||
taskdef_name = params['family']
|
||||
taskdef_rev = (1..9).to_a.shuffle.first
|
||||
taskdef_path = "task-definition/#{taskdef_name}:#{taskdef_rev}"
|
||||
taskdef_arn = Fog::AWS::Mock.arn('ecs', owner_id, taskdef_path, region)
|
||||
|
||||
task_definition = {
|
||||
'revision' => taskdef_rev,
|
||||
'taskDefinitionArn' => taskdef_arn,
|
||||
'family' => params['family'],
|
||||
'containerDefinitions' => params['containerDefinitions']
|
||||
}
|
||||
task_definition['volumes'] = params['volumes'] if params['volumes']
|
||||
|
||||
self.data[:task_definitions] << task_definition
|
||||
|
||||
response.body = {
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
},
|
||||
'RegisterTaskDefinitionResult' => {
|
||||
'taskDefinition' => task_definition
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
114
lib/fog/aws/requests/ecs/run_task.rb
Normal file
114
lib/fog/aws/requests/ecs/run_task.rb
Normal file
|
@ -0,0 +1,114 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/run_task'
|
||||
|
||||
# Start a task using random placement and the default Amazon ECS scheduler.
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_RunTask.html
|
||||
# ==== Parameters
|
||||
# * cluster <~String> - short name or full Amazon Resource Name (ARN) of the cluster that you want to run your task on.
|
||||
# * count <~Integer> - number of instantiations of the specified task that you would like to place on your cluster.
|
||||
# * overrides <~Hash> - list of container overrides.
|
||||
# * startedBy <~String> - optional tag specified when a task is started
|
||||
# * taskDefinition <~String> - family and revision (family:revision) or full ARN of the task definition that you want to run.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'tasks' <~Array> - full description of the tasks that were run.
|
||||
# * 'failures' <~Array> - Any failed tasks from your RunTask action are listed here.
|
||||
def run_task(params={})
|
||||
if overrides = params.delete('overrides')
|
||||
serialized_overrides = {}
|
||||
if overrides.is_a?(Hash)
|
||||
overrides.each_pair do |k,v|
|
||||
serialized_overrides.merge!(Fog::AWS.serialize_keys(k, v))
|
||||
end
|
||||
end
|
||||
params.merge!('overrides' => serialized_overrides)
|
||||
end
|
||||
|
||||
request({
|
||||
'Action' => 'RunTask',
|
||||
:parser => Fog::Parsers::AWS::ECS::RunTask.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def run_task(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
unless task_def_id = params.delete('taskDefinition')
|
||||
msg = 'ClientException => TaskDefinition cannot be empty.'
|
||||
raise Fog::AWS::ECS::Error, msg
|
||||
end
|
||||
|
||||
begin
|
||||
result = describe_task_definition('taskDefinition' => task_def_id).body
|
||||
task_def = result["DescribeTaskDefinitionResult"]["taskDefinition"]
|
||||
task_def_arn = task_def["taskDefinitionArn"]
|
||||
rescue Fog::AWS::ECS::Error => e
|
||||
msg = 'ClientException => TaskDefinition not found.'
|
||||
raise Fog::AWS::ECS::Error, msg
|
||||
end
|
||||
|
||||
if %w(count overrides).any? { |k| params.has_key?(k) }
|
||||
Fog::Logger.warning("you used parameters not mocked yet [light_black](#{caller.first})[/]")
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
cluster_id = params.delete('cluster') || 'default'
|
||||
cluster_arn = nil
|
||||
owner_id = Fog::AWS::Mock.owner_id
|
||||
|
||||
if cluster_id.match(/^arn:aws:ecs:.+:\d{1,12}:cluster\/(.+)$/)
|
||||
cluster_arn = cluster_id
|
||||
else
|
||||
cluster_path = "cluster/#{cluster_id}"
|
||||
cluster_arn = Fog::AWS::Mock.arn('ecs', owner_id, cluster_path, region)
|
||||
end
|
||||
|
||||
task_path = "task/#{UUID.uuid}"
|
||||
task_arn = Fog::AWS::Mock.arn('ecs', owner_id, task_path, region)
|
||||
instance_path = "container-instance/#{UUID.uuid}"
|
||||
container_instance_arn = Fog::AWS::Mock.arn('ecs', owner_id, instance_path, region)
|
||||
|
||||
containers = []
|
||||
task_def["containerDefinitions"].each do |c|
|
||||
container_path = "container/#{UUID.uuid}"
|
||||
containers << {
|
||||
'name' => c['name'],
|
||||
'taskArn' => task_arn,
|
||||
'lastStatus' => 'PENDING',
|
||||
'containerArn' => Fog::AWS::Mock.arn('ecs', owner_id, container_path, region)
|
||||
}
|
||||
end
|
||||
|
||||
task = {
|
||||
'clusterArn' => cluster_arn,
|
||||
'desiredStatus' => 'RUNNING',
|
||||
'taskDefinitionArn' => task_def_arn,
|
||||
'lastStatus' => 'PENDING',
|
||||
'taskArn' => task_arn,
|
||||
'containerInstanceArn' => container_instance_arn,
|
||||
'containers' => containers
|
||||
}
|
||||
self.data[:tasks] << task
|
||||
|
||||
response.body = {
|
||||
'RunTaskResult' => {
|
||||
'failures' => [],
|
||||
'tasks' => [] << task
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
130
lib/fog/aws/requests/ecs/start_task.rb
Normal file
130
lib/fog/aws/requests/ecs/start_task.rb
Normal file
|
@ -0,0 +1,130 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/start_task'
|
||||
|
||||
# Starts a new task from the specified task definition on the specified container instance or instances.
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_StartTask.html
|
||||
# ==== Parameters
|
||||
# * cluster <~String> - short name or full Amazon Resource Name (ARN) of the cluster that you want to start your task on.
|
||||
# * containerInstances <~Array> - container instance UUIDs or full ARN entries for the container instances on which you would like to place your task.
|
||||
# * overrides <~Hash> - list of container overrides.
|
||||
# * startedBy <~String> - optional tag specified when a task is started
|
||||
# * taskDefinition <~String> - family and revision (family:revision) or full ARN of the task definition that you want to start.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'tasks' <~Array> - full description of the tasks that were started.
|
||||
# * 'failures' <~Array> - Any failed tasks from your StartTask action are listed here.
|
||||
def start_task(params={})
|
||||
if container_instances = params.delete('containerInstances')
|
||||
params.merge!(Fog::AWS.indexed_param('containerInstances.member', [*container_instances]))
|
||||
end
|
||||
|
||||
if overrides = params.delete('overrides')
|
||||
serialized_overrides = {}
|
||||
if overrides.is_a?(Hash)
|
||||
overrides.each_pair do |k,v|
|
||||
serialized_overrides.merge!(Fog::AWS.serialize_keys(k, v))
|
||||
end
|
||||
end
|
||||
params.merge!('overrides' => serialized_overrides)
|
||||
end
|
||||
|
||||
request({
|
||||
'Action' => 'StartTask',
|
||||
:parser => Fog::Parsers::AWS::ECS::StartTask.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def start_task(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
unless task_def_id = params.delete('taskDefinition')
|
||||
msg = 'ClientException => TaskDefinition cannot be empty.'
|
||||
raise Fog::AWS::ECS::Error, msg
|
||||
end
|
||||
|
||||
unless instances_id = params.delete('containerInstances')
|
||||
msg = 'ClientException => Container instances cannot be empty.'
|
||||
raise Fog::AWS::ECS::Error, msg
|
||||
end
|
||||
|
||||
begin
|
||||
result = describe_task_definition('taskDefinition' => task_def_id).body
|
||||
task_def = result["DescribeTaskDefinitionResult"]["taskDefinition"]
|
||||
task_def_arn = task_def["taskDefinitionArn"]
|
||||
rescue Fog::AWS::ECS::Error => e
|
||||
msg = 'ClientException => TaskDefinition not found.'
|
||||
raise Fog::AWS::ECS::Error, msg
|
||||
end
|
||||
|
||||
if %w(startedBy overrides).any? { |k| params.has_key?(k) }
|
||||
Fog::Logger.warning("you used parameters not mocked yet [light_black](#{caller.first})[/]")
|
||||
Fog::Mock.not_implemented
|
||||
end
|
||||
|
||||
cluster_id = params.delete('cluster') || 'default'
|
||||
cluster_arn = nil
|
||||
owner_id = Fog::AWS::Mock.owner_id
|
||||
|
||||
if cluster_id.match(/^arn:aws:ecs:.+:\d{1,12}:cluster\/(.+)$/)
|
||||
cluster_arn = cluster_id
|
||||
else
|
||||
cluster_path = "cluster/#{cluster_id}"
|
||||
cluster_arn = Fog::AWS::Mock.arn('ecs', owner_id, cluster_path, region)
|
||||
end
|
||||
|
||||
task_path = "task/#{UUID.uuid}"
|
||||
task_arn = Fog::AWS::Mock.arn('ecs', owner_id, task_path, region)
|
||||
instance_path = "container-instance/#{UUID.uuid}"
|
||||
|
||||
instance_id = [*instances_id].first
|
||||
if instance_id.match(/^arn:aws:ecs:.+:\d{1,12}:container-instance\/(.+)$/)
|
||||
container_instance_arn = instance_id
|
||||
else
|
||||
instance_path = "container-instance/#{instance_id}"
|
||||
container_instance_arn = Fog::AWS::Mock.arn('ecs', owner_id, instance_path, region)
|
||||
end
|
||||
|
||||
containers = []
|
||||
task_def["containerDefinitions"].each do |c|
|
||||
container_path = "container/#{UUID.uuid}"
|
||||
containers << {
|
||||
'name' => c['name'],
|
||||
'taskArn' => task_arn,
|
||||
'lastStatus' => 'PENDING',
|
||||
'containerArn' => Fog::AWS::Mock.arn('ecs', owner_id, container_path, region)
|
||||
}
|
||||
end
|
||||
|
||||
task = {
|
||||
'clusterArn' => cluster_arn,
|
||||
'desiredStatus' => 'RUNNING',
|
||||
'taskDefinitionArn' => task_def_arn,
|
||||
'lastStatus' => 'PENDING',
|
||||
'taskArn' => task_arn,
|
||||
'containerInstanceArn' => container_instance_arn,
|
||||
'containers' => containers
|
||||
}
|
||||
self.data[:tasks] << task
|
||||
|
||||
response.body = {
|
||||
'StartTaskResult' => {
|
||||
'failures' => [],
|
||||
'tasks' => [] << task
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
64
lib/fog/aws/requests/ecs/stop_task.rb
Normal file
64
lib/fog/aws/requests/ecs/stop_task.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/stop_task'
|
||||
|
||||
# Stops a running task.
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_StopTask.html
|
||||
# ==== Parameters
|
||||
# * cluster <~String> - short name or full Amazon Resource Name (ARN) of the cluster that hosts the task you want to stop.
|
||||
# * task <~String> - task UUIDs or full Amazon Resource Name (ARN) entry of the task you would like to stop.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'Task' <~Hash> - The full description of the stopped task.
|
||||
def stop_task(params={})
|
||||
request({
|
||||
'Action' => 'StopTask',
|
||||
:parser => Fog::Parsers::AWS::ECS::StopTask.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def stop_task(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
unless task_id = params.delete('task')
|
||||
msg = "InvalidParameterException => Task can not be blank."
|
||||
raise Fog::AWS::ECS::Error, msg
|
||||
end
|
||||
|
||||
if cluster = params.delete('cluster')
|
||||
Fog::Logger.warning("you used parameters not mocked yet [light_black](#{caller.first})[/]")
|
||||
end
|
||||
|
||||
if match = task_id.match(/^arn:aws:ecs:.+:\d{1,12}:task\/(.+)$/)
|
||||
i = self.data[:tasks].index { |t| t['taskArn'].eql?(task_id) }
|
||||
else
|
||||
i = self.data[:tasks].index { |t| t['taskArn'].match(/#{task_id}$/) }
|
||||
end
|
||||
|
||||
msg = "ClientException => The referenced task was not found."
|
||||
raise Fog::AWS::ECS::Error, msg unless i
|
||||
|
||||
task = self.data[:tasks][i]
|
||||
task['desiredStatus'] = 'STOPPED'
|
||||
self.data[:tasks].delete_at(i)
|
||||
|
||||
response.body = {
|
||||
'StopTaskResult' => {
|
||||
'task' => task
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
80
lib/fog/aws/requests/ecs/update_service.rb
Normal file
80
lib/fog/aws/requests/ecs/update_service.rb
Normal file
|
@ -0,0 +1,80 @@
|
|||
module Fog
|
||||
module AWS
|
||||
class ECS
|
||||
class Real
|
||||
require 'fog/aws/parsers/ecs/update_service'
|
||||
|
||||
# Modify the desired count or task definition used in a service.
|
||||
# http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_UpdateService.html
|
||||
# ==== Parameters
|
||||
# * cluster <~String> - short name or full Amazon Resource Name (ARN) of the cluster that your service is running on.
|
||||
# * desiredCount <~Integer> - number of instantiations of the task that you would like to place and keep running in your service.
|
||||
# * 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.
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'Service'<~Hash> - The full description of the updated cluster
|
||||
def update_service(params={})
|
||||
request({
|
||||
'Action' => 'UpdateService',
|
||||
:parser => Fog::Parsers::AWS::ECS::UpdateService.new
|
||||
}.merge(params))
|
||||
end
|
||||
end
|
||||
|
||||
class Mock
|
||||
def update_service(params={})
|
||||
response = Excon::Response.new
|
||||
response.status = 200
|
||||
|
||||
service_id = params.delete('service')
|
||||
msg = 'ClientException => Service cannot be empty.'
|
||||
raise Fog::AWS::ECS::Error, msg unless service_id
|
||||
|
||||
owner_id = Fog::AWS::Mock.owner_id
|
||||
|
||||
cluster = params.delete('cluster') || 'default'
|
||||
if !cluster.match(/^arn:aws:ecs:.+:.+:cluster\/(.+)$/)
|
||||
cluster_path = "cluster/#{cluster}"
|
||||
cluster_arn = Fog::AWS::Mock.arn('ecs', owner_id, cluster_path, region)
|
||||
else
|
||||
cluster_arn = cluster
|
||||
end
|
||||
|
||||
if match = service_id.match(/^arn:aws:ecs:.+:\d{1,12}:service\/(.+)$/)
|
||||
i = self.data[:services].index do |s|
|
||||
s['clusterArn'].eql?(cluster_arn) && s['serviceArn'].eql?(service_id)
|
||||
end
|
||||
else
|
||||
i = self.data[:services].index do |s|
|
||||
s['clusterArn'].eql?(cluster_arn) && s['serviceName'].eql?(service_id)
|
||||
end
|
||||
end
|
||||
|
||||
msg = "ServiceNotFoundException => Service not found."
|
||||
raise Fog::AWS::ECS::Error, msg unless i
|
||||
|
||||
service = self.data[:services][i]
|
||||
|
||||
if desired_count = params.delete('desiredCount')
|
||||
# ignore
|
||||
end
|
||||
|
||||
if task_definition = params.delete('taskDefinition')
|
||||
service['taskDefinition'] = task_definition
|
||||
end
|
||||
|
||||
response.body = {
|
||||
'UpdateServiceResult' => {
|
||||
'service' => service
|
||||
},
|
||||
'ResponseMetadata' => {
|
||||
'RequestId' => Fog::AWS::Mock.request_id
|
||||
}
|
||||
}
|
||||
response
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
112
tests/requests/ecs/cluster_tests.rb
Normal file
112
tests/requests/ecs/cluster_tests.rb
Normal file
|
@ -0,0 +1,112 @@
|
|||
Shindo.tests('AWS::ECS | cluster requests', ['aws', 'ecs']) do
|
||||
|
||||
Fog::AWS[:ecs].reset_data
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests("#create_cluster").formats(AWS::ECS::Formats::CREATE_CLUSTER) do
|
||||
result = Fog::AWS[:ecs].create_cluster('clusterName' => 'cluster1').body
|
||||
cluster = result['CreateClusterResult']['cluster']
|
||||
returns('cluster1') { cluster['clusterName'] }
|
||||
returns('ACTIVE') { cluster['status'] }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#create_cluster another").formats(AWS::ECS::Formats::CREATE_CLUSTER) do
|
||||
result = Fog::AWS[:ecs].create_cluster('clusterName' => 'foobar').body
|
||||
cluster = result['CreateClusterResult']['cluster']
|
||||
returns('foobar') { cluster['clusterName'] }
|
||||
returns('ACTIVE') { cluster['status'] }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#create_cluster without params").formats(AWS::ECS::Formats::CREATE_CLUSTER) do
|
||||
result = Fog::AWS[:ecs].create_cluster.body
|
||||
cluster = result['CreateClusterResult']['cluster']
|
||||
returns('default') { cluster['clusterName'] }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#list_clusters").formats(AWS::ECS::Formats::LIST_CLUSTERS) do
|
||||
result = Fog::AWS[:ecs].list_clusters.body
|
||||
clusters = result['ListClustersResult']['clusterArns']
|
||||
returns(true) { clusters.size.eql?(3) }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#describe_clusters with name").formats(AWS::ECS::Formats::DESCRIBE_CLUSTERS) do
|
||||
result = Fog::AWS[:ecs].describe_clusters('clusters' => 'cluster1').body
|
||||
clusters = result['DescribeClustersResult']['clusters']
|
||||
failures = result['DescribeClustersResult']['failures']
|
||||
returns(true) { clusters.size.eql?(1) }
|
||||
returns('cluster1') { clusters.first['clusterName'] }
|
||||
returns(true) { failures.empty? }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#describe_clusters without params").formats(AWS::ECS::Formats::DESCRIBE_CLUSTERS) do
|
||||
result = Fog::AWS[:ecs].describe_clusters.body
|
||||
clusters = result['DescribeClustersResult']['clusters']
|
||||
failures = result['DescribeClustersResult']['failures']
|
||||
returns(true) { clusters.size.eql?(1) }
|
||||
returns('default') { clusters.first['clusterName'] }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#describe_clusters several with name").formats(AWS::ECS::Formats::DESCRIBE_CLUSTERS) do
|
||||
result = Fog::AWS[:ecs].describe_clusters('clusters' => %w(cluster1 foobar)).body
|
||||
clusters = result['DescribeClustersResult']['clusters']
|
||||
cluster_names = clusters.map { |c| c['clusterName'] }.sort
|
||||
returns(true) { clusters.size.eql?(2) }
|
||||
returns('cluster1') { cluster_names.first }
|
||||
returns('foobar') { cluster_names[1] }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#describe_clusters with errors").formats(AWS::ECS::Formats::DESCRIBE_CLUSTERS) do
|
||||
result = Fog::AWS[:ecs].describe_clusters('clusters' => %w(foobar not_here wtf)).body
|
||||
clusters = result['DescribeClustersResult']['clusters']
|
||||
failures = result['DescribeClustersResult']['failures']
|
||||
returns(true) { failures.size.eql?(2) }
|
||||
returns('MISSING') { failures.first['reason'] }
|
||||
returns(true) { clusters.size.eql?(1) }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#delete_cluster").formats(AWS::ECS::Formats::DELETE_CLUSTER) do
|
||||
cluster_name = 'foobar'
|
||||
result = Fog::AWS[:ecs].delete_cluster('cluster' => cluster_name).body
|
||||
cluster = result['DeleteClusterResult']['cluster']
|
||||
returns(true) { cluster['clusterName'].eql?(cluster_name) }
|
||||
returns('INACTIVE') { cluster['status'] }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#list_clusters after one delete").formats(AWS::ECS::Formats::LIST_CLUSTERS) do
|
||||
result = Fog::AWS[:ecs].list_clusters.body
|
||||
clusters = result['ListClustersResult']['clusterArns']
|
||||
returns(true) { clusters.size.eql?(2) }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#delete_cluster by arn").formats(AWS::ECS::Formats::DELETE_CLUSTER) do
|
||||
result1 = Fog::AWS[:ecs].describe_clusters.body
|
||||
cluster1 = result1['DescribeClustersResult']['clusters'].first
|
||||
result2 = Fog::AWS[:ecs].delete_cluster('cluster' => cluster1['clusterArn']).body
|
||||
cluster2 = result2['DeleteClusterResult']['cluster']
|
||||
returns('default') { cluster2['clusterName'] }
|
||||
returns('INACTIVE') { cluster2['status'] }
|
||||
result2
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failures') do
|
||||
|
||||
tests('#delete_cluster without params').raises(Fog::AWS::ECS::Error) do
|
||||
response = Fog::AWS[:ecs].delete_cluster.body
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
119
tests/requests/ecs/container_instance_tests.rb
Normal file
119
tests/requests/ecs/container_instance_tests.rb
Normal file
|
@ -0,0 +1,119 @@
|
|||
Shindo.tests('AWS::ECS | container instance requests', ['aws', 'ecs']) do
|
||||
|
||||
Fog::AWS[:ecs].reset_data
|
||||
|
||||
container_instance_arn = 'arn:aws:ecs:us-west-2:738152598183:container-instance/eff1068d-5fcb-4804-89f0-7d18ffc6879c'
|
||||
ec2_instance_id = 'i-58f4b4ae'
|
||||
|
||||
Fog::AWS[:ecs].data[:container_instances] << {
|
||||
'remainingResources' => [
|
||||
{
|
||||
'longValue' => 0,
|
||||
'name' => 'CPU',
|
||||
'integerValue' => 1004,
|
||||
'doubleValue' => 0.0,
|
||||
'type' => 'INTEGER'
|
||||
},
|
||||
{
|
||||
'longValue' => 0,
|
||||
'name' => 'MEMORY',
|
||||
'integerValue' => 496,
|
||||
'doubleValue' => 0.0,
|
||||
'type' => 'INTEGER'
|
||||
},
|
||||
{
|
||||
'stringSetValue' => [2376, 22, 80, 51678, 2375],
|
||||
'longValue' => 0,
|
||||
'name' => 'PORTS',
|
||||
'integerValue' => 0,
|
||||
'doubleValue' => 0.0,
|
||||
'type' => 'STRINGSET'
|
||||
}
|
||||
],
|
||||
'agentConnected' => true,
|
||||
'runningTasksCount' => 1,
|
||||
'status' => 'ACTIVE',
|
||||
'registeredResources' => [
|
||||
{
|
||||
'longValue' => 0,
|
||||
'name' => 'CPU',
|
||||
'integerValue' => 1024,
|
||||
'doubleValue' => 0.0,
|
||||
'type' => 'INTEGER'
|
||||
},
|
||||
{
|
||||
'longValue' => 0,
|
||||
'name' => 'MEMORY',
|
||||
'integerValue' => 996,
|
||||
'doubleValue' => 0.0,
|
||||
'type' => 'INTEGER'
|
||||
},
|
||||
{
|
||||
'stringSetValue' => [2376, 22, 80, 51678, 2375],
|
||||
'longValue' => 0,
|
||||
'name' => 'PORTS',
|
||||
'integerValue' => 0,
|
||||
'doubleValue' => 0.0,
|
||||
'type' => 'STRINGSET'
|
||||
}
|
||||
],
|
||||
'containerInstanceArn' => container_instance_arn,
|
||||
'pendingTasksCount' => 0,
|
||||
'ec2InstanceId' => ec2_instance_id
|
||||
}
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests("#list_container_instances").formats(AWS::ECS::Formats::LIST_CONTAINER_INSTANCES) do
|
||||
result = Fog::AWS[:ecs].list_container_instances.body
|
||||
list_instances_arns = result['ListContainerInstancesResult']['containerInstanceArns']
|
||||
returns(false) { list_instances_arns.empty? }
|
||||
returns(true) { list_instances_arns.first.eql?(container_instance_arn) }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#describe_container_instances").formats(AWS::ECS::Formats::DESCRIBE_CONTAINER_INSTANCES) do
|
||||
result = Fog::AWS[:ecs].describe_container_instances('containerInstances' => container_instance_arn).body
|
||||
instance = result['DescribeContainerInstancesResult']['containerInstances'].first
|
||||
returns(true) { instance['containerInstanceArn'].eql?(container_instance_arn) }
|
||||
returns(true) { instance['ec2InstanceId'].eql?(ec2_instance_id) }
|
||||
returns(true) { instance['status'].eql?('ACTIVE') }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#deregister_container_instance").formats(AWS::ECS::Formats::DEREGISTER_CONTAINER_INSTANCE) do
|
||||
result = Fog::AWS[:ecs].deregister_container_instance('containerInstance' => container_instance_arn).body
|
||||
instance = result['DeregisterContainerInstanceResult']['containerInstance']
|
||||
returns(true) { instance['containerInstanceArn'].eql?(container_instance_arn) }
|
||||
returns(true) { instance['ec2InstanceId'].eql?(ec2_instance_id) }
|
||||
returns(true) { instance['pendingTasksCount'].eql?(0) }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#list_container_instances again").formats(AWS::ECS::Formats::LIST_CONTAINER_INSTANCES) do
|
||||
result = Fog::AWS[:ecs].list_container_instances.body
|
||||
list_instances_arns = result['ListContainerInstancesResult']['containerInstanceArns']
|
||||
returns(true) { list_instances_arns.empty? }
|
||||
result
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failures') do
|
||||
|
||||
tests('#describe_container_instances without params').raises(Fog::AWS::ECS::Error) do
|
||||
response = Fog::AWS[:ecs].describe_container_instances.body
|
||||
end
|
||||
|
||||
tests('#deregister_container_instance without params').raises(Fog::AWS::ECS::Error) do
|
||||
response = Fog::AWS[:ecs].deregister_container_instance.body
|
||||
end
|
||||
|
||||
tests('#deregister_container_instance nonexistent').raises(Fog::AWS::ECS::Error) do
|
||||
instance_uuid = 'ffffffff-ffff-0000-ffff-deadbeefff'
|
||||
response = Fog::AWS[:ecs].deregister_container_instance('containerInstance' => instance_uuid).body
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
276
tests/requests/ecs/helper.rb
Normal file
276
tests/requests/ecs/helper.rb
Normal file
|
@ -0,0 +1,276 @@
|
|||
class AWS
|
||||
module ECS
|
||||
module Formats
|
||||
BASIC = {
|
||||
'ResponseMetadata' => { 'RequestId' => String }
|
||||
}
|
||||
CREATE_CLUSTER = BASIC.merge({
|
||||
'CreateClusterResult' => {
|
||||
'cluster' => {
|
||||
'clusterName' => String,
|
||||
'clusterArn' => String,
|
||||
'status' => String,
|
||||
'registeredContainerInstancesCount' => Integer,
|
||||
'runningTasksCount' => Integer,
|
||||
'pendingTasksCount' => Integer
|
||||
}
|
||||
}
|
||||
})
|
||||
LIST_CLUSTERS = BASIC.merge({
|
||||
'ListClustersResult' => {
|
||||
'clusterArns' => [String],
|
||||
'nextToken' => Fog::Nullable::String
|
||||
}
|
||||
})
|
||||
DELETE_CLUSTER = BASIC.merge({
|
||||
'DeleteClusterResult' => {
|
||||
'cluster' => {
|
||||
'clusterName' => String,
|
||||
'clusterArn' => String,
|
||||
'status' => String,
|
||||
'registeredContainerInstancesCount' => Integer,
|
||||
'runningTasksCount' => Integer,
|
||||
'pendingTasksCount' => Integer
|
||||
}
|
||||
}
|
||||
})
|
||||
DESCRIBE_CLUSTERS = BASIC.merge({
|
||||
'DescribeClustersResult' => {
|
||||
'failures' => [Fog::Nullable::Hash],
|
||||
'clusters' => [Fog::Nullable::Hash]
|
||||
}
|
||||
})
|
||||
REGISTER_TASK_DEFINITION = BASIC.merge({
|
||||
'RegisterTaskDefinitionResult' => {
|
||||
'taskDefinition' => {
|
||||
'revision' => Integer,
|
||||
'taskDefinitionArn' => String,
|
||||
'family' => String,
|
||||
'containerDefinitions' => [Hash],
|
||||
'volumes' => Fog::Nullable::Array
|
||||
}
|
||||
}
|
||||
})
|
||||
LIST_TASK_DEFINITIONS = BASIC.merge({
|
||||
'ListTaskDefinitionsResult' => {
|
||||
'taskDefinitionArns' => [String]
|
||||
}
|
||||
})
|
||||
DESCRIBE_TASK_DEFINITION = BASIC.merge({
|
||||
'DescribeTaskDefinitionResult' => {
|
||||
'taskDefinition' => {
|
||||
'revision' => Integer,
|
||||
'taskDefinitionArn' => String,
|
||||
'family' => String,
|
||||
'containerDefinitions' => [Hash],
|
||||
'volumes' => Fog::Nullable::Array
|
||||
}
|
||||
}
|
||||
})
|
||||
DEREGISTER_TASK_DEFINITION = BASIC.merge({
|
||||
'DeregisterTaskDefinitionResult' => {
|
||||
'taskDefinition' => {
|
||||
'revision' => Integer,
|
||||
'taskDefinitionArn' => String,
|
||||
'family' => String,
|
||||
'containerDefinitions' => [Hash],
|
||||
'volumes' => Fog::Nullable::Array
|
||||
}
|
||||
}
|
||||
})
|
||||
LIST_TASK_DEFINITION_FAMILIES = BASIC.merge({
|
||||
'ListTaskDefinitionFamiliesResult' => {
|
||||
'families' => [String]
|
||||
}
|
||||
})
|
||||
CREATE_SERVICE = BASIC.merge({
|
||||
'CreateServiceResult' => {
|
||||
'service' => {
|
||||
'events' => [Fog::Nullable::Hash],
|
||||
'serviceName' => String,
|
||||
'serviceArn' => String,
|
||||
'taskDefinition' => String,
|
||||
'clusterArn' => String,
|
||||
'status' => String,
|
||||
'roleArn' => Fog::Nullable::String,
|
||||
'loadBalancers' => [Fog::Nullable::Hash],
|
||||
'deployments' => [Fog::Nullable::Hash],
|
||||
'desiredCount' => Integer,
|
||||
'pendingCount' => Integer,
|
||||
'runningCount' => Integer
|
||||
}
|
||||
}
|
||||
})
|
||||
DELETE_SERVICE = BASIC.merge({
|
||||
'DeleteServiceResult' => {
|
||||
'service' => {
|
||||
'events' => [Fog::Nullable::Hash],
|
||||
'serviceName' => String,
|
||||
'serviceArn' => String,
|
||||
'taskDefinition' => String,
|
||||
'clusterArn' => String,
|
||||
'status' => String,
|
||||
'roleArn' => Fog::Nullable::String,
|
||||
'loadBalancers' => [Fog::Nullable::Hash],
|
||||
'deployments' => [Fog::Nullable::Hash],
|
||||
'desiredCount' => Integer,
|
||||
'pendingCount' => Integer,
|
||||
'runningCount' => Integer
|
||||
}
|
||||
}
|
||||
})
|
||||
DESCRIBE_SERVICES = BASIC.merge({
|
||||
'DescribeServicesResult' => {
|
||||
'failures' => [Fog::Nullable::Hash],
|
||||
'services' => [{
|
||||
'events' => [Fog::Nullable::Hash],
|
||||
'serviceName' => String,
|
||||
'serviceArn' => String,
|
||||
'taskDefinition' => String,
|
||||
'clusterArn' => String,
|
||||
'status' => String,
|
||||
'roleArn' => Fog::Nullable::String,
|
||||
'loadBalancers' => [Fog::Nullable::Hash],
|
||||
'deployments' => [Fog::Nullable::Hash],
|
||||
'desiredCount' => Integer,
|
||||
'pendingCount' => Integer,
|
||||
'runningCount' => Integer
|
||||
}]
|
||||
}
|
||||
})
|
||||
LIST_SERVICES = BASIC.merge({
|
||||
'ListServicesResult' => {
|
||||
'serviceArns' => [Fog::Nullable::String],
|
||||
'nextToken' => Fog::Nullable::String
|
||||
}
|
||||
})
|
||||
UPDATE_SERVICE = BASIC.merge({
|
||||
'UpdateServiceResult' => {
|
||||
'service' => {
|
||||
'events' => [Fog::Nullable::Hash],
|
||||
'serviceName' => String,
|
||||
'serviceArn' => String,
|
||||
'taskDefinition' => String,
|
||||
'clusterArn' => String,
|
||||
'status' => String,
|
||||
'roleArn' => Fog::Nullable::String,
|
||||
'loadBalancers' => [Fog::Nullable::Hash],
|
||||
'deployments' => [Fog::Nullable::Hash],
|
||||
'desiredCount' => Integer,
|
||||
'pendingCount' => Integer,
|
||||
'runningCount' => Integer
|
||||
}
|
||||
}
|
||||
})
|
||||
LIST_CONTAINER_INSTANCES = BASIC.merge({
|
||||
'ListContainerInstancesResult' => {
|
||||
'containerInstanceArns' => [Fog::Nullable::String]
|
||||
}
|
||||
})
|
||||
DESCRIBE_CONTAINER_INSTANCES = BASIC.merge({
|
||||
'DescribeContainerInstancesResult' => {
|
||||
'containerInstances' => [{
|
||||
'remainingResources' => [Hash],
|
||||
'agentConnected' => Fog::Boolean,
|
||||
'runningTasksCount' => Integer,
|
||||
'status' => String,
|
||||
'registeredResources' => [Hash],
|
||||
'containerInstanceArn' => String,
|
||||
'pendingTasksCount' => Integer,
|
||||
'ec2InstanceId' => String
|
||||
}],
|
||||
'failures' => [Fog::Nullable::Hash],
|
||||
}
|
||||
})
|
||||
DEREGISTER_CONTAINER_INSTANCE = BASIC.merge({
|
||||
'DeregisterContainerInstanceResult' => {
|
||||
'containerInstance' => {
|
||||
'remainingResources' => [Hash],
|
||||
'agentConnected' => Fog::Boolean,
|
||||
'runningTasksCount' => Integer,
|
||||
'status' => String,
|
||||
'registeredResources' => [Hash],
|
||||
'containerInstanceArn' => String,
|
||||
'pendingTasksCount' => Integer,
|
||||
'ec2InstanceId' => String
|
||||
}
|
||||
}
|
||||
})
|
||||
LIST_TASKS = BASIC.merge({
|
||||
'ListTasksResult' => {
|
||||
'taskArns' => [Fog::Nullable::String]
|
||||
}
|
||||
})
|
||||
DESCRIBE_TASKS = BASIC.merge({
|
||||
'DescribeTasksResult' => {
|
||||
'failures' => [Fog::Nullable::Hash],
|
||||
'tasks' => [
|
||||
{
|
||||
'clusterArn' => String,
|
||||
'containers' => Array,
|
||||
'overrides' => Fog::Nullable::Hash,
|
||||
'startedBy' => Fog::Nullable::String,
|
||||
'desiredStatus' => String,
|
||||
'taskArn' => String,
|
||||
'containerInstanceArn' => String,
|
||||
'lastStatus' => String,
|
||||
'taskDefinitionArn' => String
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
RUN_TASK = BASIC.merge({
|
||||
'RunTaskResult' => {
|
||||
'failures' => [Fog::Nullable::Hash],
|
||||
'tasks' => [
|
||||
{
|
||||
'clusterArn' => String,
|
||||
'containers' => [Hash],
|
||||
'overrides' => Fog::Nullable::Hash,
|
||||
'desiredStatus' => String,
|
||||
'taskArn' => String,
|
||||
'containerInstanceArn' => String,
|
||||
'lastStatus' => String,
|
||||
'taskDefinitionArn' => String
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
STOP_TASK = BASIC.merge({
|
||||
'StopTaskResult' => {
|
||||
'task' => {
|
||||
'clusterArn' => String,
|
||||
'containers' => [Hash],
|
||||
'overrides' => Fog::Nullable::Hash,
|
||||
'desiredStatus' => String,
|
||||
'taskArn' => String,
|
||||
'startedBy' => Fog::Nullable::String,
|
||||
'containerInstanceArn' => String,
|
||||
'lastStatus' => String,
|
||||
'taskDefinitionArn' => String
|
||||
}
|
||||
}
|
||||
})
|
||||
START_TASK = BASIC.merge({
|
||||
'StartTaskResult' => {
|
||||
'failures' => [Fog::Nullable::Hash],
|
||||
'tasks' => [
|
||||
{
|
||||
'clusterArn' => String,
|
||||
'containers' => [Hash],
|
||||
'overrides' => Fog::Nullable::Hash,
|
||||
'desiredStatus' => String,
|
||||
'taskArn' => String,
|
||||
'containerInstanceArn' => String,
|
||||
'lastStatus' => String,
|
||||
'taskDefinitionArn' => String
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
end
|
||||
module Samples
|
||||
TASK_DEFINITION_1 = File.dirname(__FILE__) + '/sample_task_definition1.json'
|
||||
end
|
||||
end
|
||||
end
|
56
tests/requests/ecs/sample_task_definition1.json
Normal file
56
tests/requests/ecs/sample_task_definition1.json
Normal file
|
@ -0,0 +1,56 @@
|
|||
{
|
||||
"family": "console-sample-app-static",
|
||||
"containerDefinitions": [
|
||||
{
|
||||
"name": "simple-app",
|
||||
"image": "httpd:2.4",
|
||||
"cpu": 10,
|
||||
"memory": 300,
|
||||
"environment": [],
|
||||
"portMappings": [
|
||||
{
|
||||
"hostPort": 80,
|
||||
"containerPort": 80
|
||||
}
|
||||
],
|
||||
"volumesFrom": [],
|
||||
"links": [],
|
||||
"mountPoints": [
|
||||
{
|
||||
"sourceVolume": "my-vol",
|
||||
"containerPath": "/usr/local/apache2/htdocs"
|
||||
}
|
||||
],
|
||||
"essential": true
|
||||
},
|
||||
{
|
||||
"name": "busybox",
|
||||
"image": "busybox",
|
||||
"cpu": 10,
|
||||
"memory": 200,
|
||||
"entryPoint": [
|
||||
"sh",
|
||||
"-c"
|
||||
],
|
||||
"environment": [],
|
||||
"command": [
|
||||
"/bin/sh -c \"while true; do echo '<html> <head> <title>Amazon ECS Sample App</title> <style>body {margin-top: 40px; background-color: #333;} </style> </head><body> <div style=color:white;text-align:center> <h1>Amazon ECS Sample App</h1> <h2>Congratulations!</h2> <p>Your application is now running on a container in Amazon ECS.</p>' > top; /bin/date > date ; echo '</div></body></html>' > bottom; cat top date bottom > /usr/local/apache2/htdocs/index.html ; sleep 1; done\""
|
||||
],
|
||||
"portMappings": [],
|
||||
"volumesFrom": [
|
||||
{
|
||||
"sourceContainer": "simple-app"
|
||||
}
|
||||
],
|
||||
"links": [],
|
||||
"mountPoints": [],
|
||||
"essential": false
|
||||
}
|
||||
],
|
||||
"volumes": [
|
||||
{
|
||||
"name": "my-vol",
|
||||
"host": {}
|
||||
}
|
||||
]
|
||||
}
|
132
tests/requests/ecs/service_tests.rb
Normal file
132
tests/requests/ecs/service_tests.rb
Normal file
|
@ -0,0 +1,132 @@
|
|||
Shindo.tests('AWS::ECS | service requests', ['aws', 'ecs']) do
|
||||
|
||||
Fog::AWS[:ecs].reset_data
|
||||
|
||||
cluster = 'arn:aws:ecs:us-east-1:994922842243:cluster/default'
|
||||
desired_count = 1
|
||||
role = 'arn:aws:iam::806753142346:role/ecsServiceRole'
|
||||
service_name = 'sample-webapp'
|
||||
task_definition = 'console-sample-app-static:18'
|
||||
load_balancers = [{
|
||||
'containerName' => 'simple-app',
|
||||
'containerPort' => 80,
|
||||
'loadBalancerName' => 'ecsunittests-EcsElastic-OI09IAP3PVIP'
|
||||
}]
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests("#list_services").formats(AWS::ECS::Formats::LIST_SERVICES) do
|
||||
result = Fog::AWS[:ecs].list_services('cluster' => cluster).body
|
||||
list_services_arns = result['ListServicesResult']['serviceArns']
|
||||
returns(true) { list_services_arns.empty? }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#create_service").formats(AWS::ECS::Formats::CREATE_SERVICE) do
|
||||
params = {
|
||||
'cluster' => cluster,
|
||||
'desiredCount' => desired_count,
|
||||
'loadBalancers' => load_balancers,
|
||||
'role' => role,
|
||||
'serviceName' => service_name,
|
||||
'taskDefinition' => task_definition
|
||||
}
|
||||
result = Fog::AWS[:ecs].create_service(params).body
|
||||
service = result['CreateServiceResult']['service']
|
||||
returns('sample-webapp') { service['serviceName'] }
|
||||
returns(false) { service['serviceArn'].match(/^arn:aws:ecs:.+:.+:service\/.+$/).nil? }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#list_services again").formats(AWS::ECS::Formats::LIST_SERVICES) do
|
||||
result = Fog::AWS[:ecs].list_services('cluster' => cluster).body
|
||||
list_services_arns = result['ListServicesResult']['serviceArns']
|
||||
returns(false) { list_services_arns.empty? }
|
||||
returns(true) { !list_services_arns.first.match(/#{service_name}/).nil? }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#describe_services").formats(AWS::ECS::Formats::DESCRIBE_SERVICES) do
|
||||
result1 = Fog::AWS[:ecs].list_services('cluster' => cluster).body
|
||||
service_arn = result1['ListServicesResult']['serviceArns'].first
|
||||
result2 = Fog::AWS[:ecs].describe_services(
|
||||
'services' => service_arn,
|
||||
'cluster' => cluster
|
||||
).body
|
||||
returns(true) { result2['DescribeServicesResult']['services'].size.eql?(1) }
|
||||
service = result2['DescribeServicesResult']['services'].first
|
||||
returns(true) { service['serviceName'].eql?(service_name) }
|
||||
returns(true) { service['status'].eql?('ACTIVE') }
|
||||
returns(false) { service['deployments'].empty? }
|
||||
returns(true) { service['desiredCount'].eql?(desired_count) }
|
||||
result2
|
||||
end
|
||||
|
||||
tests("#update_service").formats(AWS::ECS::Formats::UPDATE_SERVICE) do
|
||||
new_task_def = 'arn:aws:ecs:us-east-1:994922842243:task-definitions/foobar-app:32'
|
||||
result1 = Fog::AWS[:ecs].list_services('cluster' => cluster).body
|
||||
service_arn = result1['ListServicesResult']['serviceArns'].first
|
||||
|
||||
result2 = Fog::AWS[:ecs].update_service(
|
||||
'service' => service_arn,
|
||||
'cluster' => cluster,
|
||||
'taskDefinition' => new_task_def
|
||||
).body
|
||||
service = result2['UpdateServiceResult']['service']
|
||||
returns(true) { service['serviceName'].eql?(service_name) }
|
||||
returns(true) { service['taskDefinition'].eql?(new_task_def) }
|
||||
result2
|
||||
end
|
||||
|
||||
|
||||
tests("#delete_service").formats(AWS::ECS::Formats::DELETE_SERVICE) do
|
||||
result1 = Fog::AWS[:ecs].list_services('cluster' => cluster).body
|
||||
service_arn = result1['ListServicesResult']['serviceArns'].first
|
||||
|
||||
result2 = Fog::AWS[:ecs].delete_service(
|
||||
'service' => service_arn,
|
||||
'cluster' => cluster
|
||||
).body
|
||||
service = result2['DeleteServiceResult']['service']
|
||||
returns(true) { service['serviceName'].eql?(service_name) }
|
||||
result2
|
||||
end
|
||||
|
||||
tests("#list_services yet again").formats(AWS::ECS::Formats::LIST_SERVICES) do
|
||||
result = Fog::AWS[:ecs].list_services('cluster' => cluster).body
|
||||
list_services_arns = result['ListServicesResult']['serviceArns']
|
||||
returns(true) { list_services_arns.empty? }
|
||||
result
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failures') do
|
||||
|
||||
tests('#describe_services without params').raises(Fog::AWS::ECS::Error) do
|
||||
response = Fog::AWS[:ecs].describe_services.body
|
||||
end
|
||||
|
||||
tests('#create_service without params').raises(Fog::AWS::ECS::Error) do
|
||||
response = Fog::AWS[:ecs].create_service.body
|
||||
end
|
||||
|
||||
tests('#update_service without params').raises(Fog::AWS::ECS::Error) do
|
||||
response = Fog::AWS[:ecs].update_service.body
|
||||
end
|
||||
|
||||
tests('#update_service nonexistent').raises(Fog::AWS::ECS::Error) do
|
||||
response = Fog::AWS[:ecs].update_service('service' => 'whatever2329').body
|
||||
end
|
||||
|
||||
tests('#delete_service without params').raises(Fog::AWS::ECS::Error) do
|
||||
response = Fog::AWS[:ecs].delete_service.body
|
||||
end
|
||||
|
||||
tests('#delete_service nonexistent').raises(Fog::AWS::ECS::Error) do
|
||||
response = Fog::AWS[:ecs].delete_service('service' => 'foobar787383').body
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
97
tests/requests/ecs/task_definitions_tests.rb
Normal file
97
tests/requests/ecs/task_definitions_tests.rb
Normal file
|
@ -0,0 +1,97 @@
|
|||
require 'fog/json'
|
||||
|
||||
Shindo.tests('AWS::ECS | task definitions requests', ['aws', 'ecs']) do
|
||||
|
||||
Fog::AWS[:ecs].reset_data
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests("#list_task_definitions").formats(AWS::ECS::Formats::LIST_TASK_DEFINITIONS) do
|
||||
result = Fog::AWS[:ecs].list_task_definitions.body
|
||||
list_task_def_arns = result['ListTaskDefinitionsResult']['taskDefinitionArns']
|
||||
returns(true) { list_task_def_arns.empty? }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#register_task_definition").formats(AWS::ECS::Formats::REGISTER_TASK_DEFINITION) do
|
||||
task_def_params = Fog::JSON.decode(IO.read(AWS::ECS::Samples::TASK_DEFINITION_1))
|
||||
result = Fog::AWS[:ecs].register_task_definition(task_def_params).body
|
||||
task_def = result['RegisterTaskDefinitionResult']['taskDefinition']
|
||||
returns('console-sample-app-static') { task_def['family'] }
|
||||
returns(true) { task_def['revision'] > 0 }
|
||||
returns(false) { task_def['taskDefinitionArn'].match(/^arn:aws:ecs:.+:.+:task-definition\/.+:\d+$/).nil? }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#list_task_definition_families").formats(AWS::ECS::Formats::LIST_TASK_DEFINITION_FAMILIES) do
|
||||
result = Fog::AWS[:ecs].list_task_definition_families.body
|
||||
families = result['ListTaskDefinitionFamiliesResult']['families']
|
||||
returns(false) { families.empty? }
|
||||
returns(true) { families.include?('console-sample-app-static') }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#list_task_definitions again").formats(AWS::ECS::Formats::LIST_TASK_DEFINITIONS) do
|
||||
result = Fog::AWS[:ecs].list_task_definitions.body
|
||||
list_task_def_arns = result['ListTaskDefinitionsResult']['taskDefinitionArns']
|
||||
returns(true) { list_task_def_arns.size.eql?(1) }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#describe_task_definition").formats(AWS::ECS::Formats::DESCRIBE_TASK_DEFINITION) do
|
||||
result1 = Fog::AWS[:ecs].list_task_definitions.body
|
||||
task_def_arn = result1['ListTaskDefinitionsResult']['taskDefinitionArns'].first
|
||||
result2 = Fog::AWS[:ecs].describe_task_definition('taskDefinition' => task_def_arn).body
|
||||
task_def = result2['DescribeTaskDefinitionResult']['taskDefinition']
|
||||
returns(true) { task_def['taskDefinitionArn'].eql?(task_def_arn) }
|
||||
returns(true) { task_def['containerDefinitions'].size > 0 }
|
||||
result2
|
||||
end
|
||||
|
||||
tests("#deregister_task_definition").formats(AWS::ECS::Formats::DEREGISTER_TASK_DEFINITION) do
|
||||
result1 = Fog::AWS[:ecs].list_task_definitions.body
|
||||
task_def_arn = result1['ListTaskDefinitionsResult']['taskDefinitionArns'].first
|
||||
result2 = Fog::AWS[:ecs].deregister_task_definition('taskDefinition' => task_def_arn).body
|
||||
task_def = result2['DeregisterTaskDefinitionResult']['taskDefinition']
|
||||
returns(true) { task_def['taskDefinitionArn'].eql?(task_def_arn) }
|
||||
result2
|
||||
end
|
||||
|
||||
tests("#list_task_definitions yet again").formats(AWS::ECS::Formats::LIST_TASK_DEFINITIONS) do
|
||||
result = Fog::AWS[:ecs].list_task_definitions.body
|
||||
list_task_def_arns = result['ListTaskDefinitionsResult']['taskDefinitionArns']
|
||||
returns(true) { list_task_def_arns.empty? }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#list_task_definition_families again").formats(AWS::ECS::Formats::LIST_TASK_DEFINITION_FAMILIES) do
|
||||
result = Fog::AWS[:ecs].list_task_definition_families.body
|
||||
families = result['ListTaskDefinitionFamiliesResult']['families']
|
||||
returns(true) { families.empty? }
|
||||
returns(false) { families.include?('console-sample-app-static') }
|
||||
result
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failures') do
|
||||
|
||||
tests('#describe_task_definition without params').raises(Fog::AWS::ECS::Error) do
|
||||
response = Fog::AWS[:ecs].describe_task_definition.body
|
||||
end
|
||||
|
||||
tests('#describe_task_definition nonexistent').raises(Fog::AWS::ECS::Error) do
|
||||
response = Fog::AWS[:ecs].describe_task_definition('taskDefinition' => 'foobar').body
|
||||
end
|
||||
|
||||
tests('#deregister_task_definition without params').raises(Fog::AWS::ECS::Error) do
|
||||
response = Fog::AWS[:ecs].deregister_task_definition.body
|
||||
end
|
||||
|
||||
tests('#deregister_task_definition nonexistent').raises(Fog::AWS::ECS::NotFound) do
|
||||
response = Fog::AWS[:ecs].deregister_task_definition('taskDefinition' => 'foobar:7873287283').body
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
145
tests/requests/ecs/task_tests.rb
Normal file
145
tests/requests/ecs/task_tests.rb
Normal file
|
@ -0,0 +1,145 @@
|
|||
require 'fog/json'
|
||||
|
||||
Shindo.tests('AWS::ECS | task requests', ['aws', 'ecs']) do
|
||||
|
||||
Fog::AWS[:ecs].reset_data
|
||||
|
||||
tests('success') do
|
||||
|
||||
tests("#list_tasks").formats(AWS::ECS::Formats::LIST_TASKS) do
|
||||
result = Fog::AWS[:ecs].list_tasks.body
|
||||
list_instances_arns = result['ListTasksResult']['taskArns']
|
||||
returns(true) { list_instances_arns.empty? }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#run_task").formats(AWS::ECS::Formats::RUN_TASK) do
|
||||
task_def_params = Fog::JSON.decode(IO.read(AWS::ECS::Samples::TASK_DEFINITION_1))
|
||||
result1 = Fog::AWS[:ecs].register_task_definition(task_def_params).body
|
||||
task_def = result1['RegisterTaskDefinitionResult']['taskDefinition']
|
||||
task_def_arn = task_def['taskDefinitionArn']
|
||||
|
||||
result2 = Fog::AWS[:ecs].run_task('taskDefinition' => task_def_arn).body
|
||||
task = result2['RunTaskResult']['tasks'].first
|
||||
returns(true) { task.has_key?('containerInstanceArn') }
|
||||
returns(true) { task['containers'].size.eql?(2) }
|
||||
returns(true) { task['desiredStatus'].eql?('RUNNING') }
|
||||
returns(true) { task['taskDefinitionArn'].eql?(task_def_arn) }
|
||||
result2
|
||||
end
|
||||
|
||||
tests("#describe_tasks").formats(AWS::ECS::Formats::DESCRIBE_TASKS) do
|
||||
result1 = Fog::AWS[:ecs].list_tasks.body
|
||||
task_arn = result1['ListTasksResult']['taskArns'].first
|
||||
|
||||
result2 = Fog::AWS[:ecs].describe_tasks('tasks' => task_arn).body
|
||||
task = result2['DescribeTasksResult']['tasks'].first
|
||||
returns(true) { task['taskArn'].eql?(task_arn) }
|
||||
returns(true) { task['containers'].size.eql?(2) }
|
||||
returns(true) { task['desiredStatus'].eql?('RUNNING') }
|
||||
result2
|
||||
end
|
||||
|
||||
tests("#list_tasks").formats(AWS::ECS::Formats::LIST_TASKS) do
|
||||
result = Fog::AWS[:ecs].list_tasks.body
|
||||
list_instances_arns = result['ListTasksResult']['taskArns']
|
||||
returns(false) { list_instances_arns.empty? }
|
||||
result
|
||||
end
|
||||
|
||||
tests("#stop_task").formats(AWS::ECS::Formats::STOP_TASK) do
|
||||
result1 = Fog::AWS[:ecs].list_tasks.body
|
||||
task_arn = result1['ListTasksResult']['taskArns'].first
|
||||
|
||||
result2 = Fog::AWS[:ecs].stop_task('task' => task_arn).body
|
||||
task = result2['StopTaskResult']['task']
|
||||
returns(true) { task['taskArn'].eql?(task_arn) }
|
||||
returns(true) { task['containers'].size.eql?(2) }
|
||||
returns(true) { task['desiredStatus'].eql?('STOPPED') }
|
||||
result2
|
||||
end
|
||||
|
||||
tests("#start_task").formats(AWS::ECS::Formats::START_TASK) do
|
||||
owner_id = Fog::AWS::Mock.owner_id
|
||||
container_instance_path = "container-instance/#{Fog::UUID.uuid}"
|
||||
region = "us-east-1"
|
||||
container_instance_arn = Fog::AWS::Mock.arn('ecs', owner_id, container_instance_path, region)
|
||||
|
||||
task_def_params = Fog::JSON.decode(IO.read(AWS::ECS::Samples::TASK_DEFINITION_1))
|
||||
result1 = Fog::AWS[:ecs].register_task_definition(task_def_params).body
|
||||
task_def = result1['RegisterTaskDefinitionResult']['taskDefinition']
|
||||
task_def_arn = task_def['taskDefinitionArn']
|
||||
|
||||
result2 = Fog::AWS[:ecs].start_task(
|
||||
'taskDefinition' => task_def_arn,
|
||||
'containerInstances' => container_instance_arn
|
||||
).body
|
||||
task = result2['StartTaskResult']['tasks'].first
|
||||
|
||||
returns(true) { task['containerInstanceArn'].eql?(container_instance_arn) }
|
||||
returns(true) { task['containers'].size.eql?(2) }
|
||||
returns(true) { task['desiredStatus'].eql?('RUNNING') }
|
||||
returns(true) { task['taskDefinitionArn'].eql?(task_def_arn) }
|
||||
|
||||
result2
|
||||
end
|
||||
|
||||
tests("#list_tasks").formats(AWS::ECS::Formats::LIST_TASKS) do
|
||||
result = Fog::AWS[:ecs].list_tasks.body
|
||||
list_instances_arns = result['ListTasksResult']['taskArns']
|
||||
returns(false) { list_instances_arns.empty? }
|
||||
result
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
tests('failures') do
|
||||
|
||||
tests("#describe_tasks nonexistent") do
|
||||
task_arn = "arn:aws:ecs:us-west-2:938269302734:task/6893440f-2165-47aa-8cfa-b2f413a26f00"
|
||||
result = Fog::AWS[:ecs].describe_tasks('tasks' => task_arn).body
|
||||
end
|
||||
|
||||
tests('describe_tasks without params').raises(Fog::AWS::ECS::Error) do
|
||||
response = Fog::AWS[:ecs].describe_tasks.body
|
||||
end
|
||||
|
||||
tests('#run_task without params').raises(Fog::AWS::ECS::Error) do
|
||||
response = Fog::AWS[:ecs].run_task.body
|
||||
end
|
||||
|
||||
tests('#run_task nonexistent').raises(Fog::AWS::ECS::Error) do
|
||||
task_def_arn = "arn:aws:ecs:us-west-2:539573770077:task-definition/foo-xanadu-app-static:33"
|
||||
response = Fog::AWS[:ecs].run_task('taskDefinition' => task_def_arn).body
|
||||
end
|
||||
|
||||
tests('#start_task without params').raises(Fog::AWS::ECS::Error) do
|
||||
response = Fog::AWS[:ecs].start_task.body
|
||||
end
|
||||
|
||||
tests('#start_task with missing params').raises(Fog::AWS::ECS::Error) do
|
||||
task_def_arn = "arn:aws:ecs:us-west-2:539573770077:task-definition/foo-xanadu-app-static:33"
|
||||
response = Fog::AWS[:ecs].start_task('taskDefinition' => task_def_arn).body
|
||||
end
|
||||
|
||||
tests('#start_task nonexistent').raises(Fog::AWS::ECS::Error) do
|
||||
task_def_arn = "arn:aws:ecs:us-west-2:539573770077:task-definition/foo-xanadu-app-static:33"
|
||||
container_instance_arn = "arn:aws:ecs:us-west-2:938269302734:container-instance/6893440f-2165-47aa-8cfa-b2f413a26f00"
|
||||
response = Fog::AWS[:ecs].start_task(
|
||||
'taskDefinition' => task_def_arn,
|
||||
'containerInstances' => container_instance_arn
|
||||
).body
|
||||
end
|
||||
|
||||
tests('#stop_task without params').raises(Fog::AWS::ECS::Error) do
|
||||
response = Fog::AWS[:ecs].stop_task.body
|
||||
end
|
||||
|
||||
tests('#stop_task nonexistent params').raises(Fog::AWS::ECS::Error) do
|
||||
task_arn = "arn:aws:ecs:us-west-2:938269302734:task/6893440f-2165-47aa-8cfa-b2f413a26f00"
|
||||
response = Fog::AWS[:ecs].stop_task('task' => task_arn).body
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue