1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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
|