add ECS ContainerInstance register and list actions

This commit is contained in:
Riccardo M. Cefala 2016-06-11 12:52:19 +02:00 committed by Riccardo
parent 19fab4ca25
commit 115f9513f6
2 changed files with 40 additions and 0 deletions

View File

@ -113,6 +113,7 @@ class EC2ContainerServiceBackend(BaseBackend):
self.clusters = {}
self.task_definitions = {}
self.services = {}
self.container_instances = {}
def fetch_task_definition(self, task_definition_str):
task_definition_components = task_definition_str.split(':')
@ -235,6 +236,28 @@ class EC2ContainerServiceBackend(BaseBackend):
else:
raise Exception("cluster {0} or service {1} does not exist".format(cluster_name, service_name))
def register_container_instance(self, cluster_str, ec2_instance_id):
cluster_name = cluster_str.split('/')[-1]
if cluster_name in self.clusters:
cluster = self.clusters[cluster_name]
else:
raise Exception("{0} is not a cluster".format(cluster.name))
container_instance = ContainerInstance(ec2_instance_id)
if not self.container_instances.get(cluster_name):
self.container_instances[cluster_name] = {}
self.container_instances[cluster_name][container_instance.containerInstanceArn] = container_instance
return container_instance
def list_container_instances(self, cluster_str):
cluster_name = cluster_str.split('/')[-1]
return sorted(self.container_instances[cluster_name].keys())
def describe_container_instances(self, cluster_str, list_container_instances_str):
pass
def deregister_container_instance(self, cluster_str, container_instance_str):
pass
ecs_backends = {}
for region, ec2_backend in ec2_backends.items():

View File

@ -113,3 +113,20 @@ class EC2ContainerServiceResponse(BaseResponse):
return json.dumps({
'service': service.response_object
})
def register_container_instance(self):
cluster_str = self._get_param('cluster')
instance_identity_document_str = self._get_param('instanceIdentityDocument')
instance_identity_document = json.loads(instance_identity_document_str)
ec2_instance_id = instance_identity_document["instanceId"]
container_instance = self.ecs_backend.register_container_instance(cluster_str, ec2_instance_id)
return json.dumps({
'containerInstance' : container_instance.response_object
})
def list_container_instances(self):
cluster_str = self._get_param('cluster')
container_instance_arns = self.ecs_backend.list_container_instances(cluster_str)
return json.dumps({
'containerInstanceArns': container_instance_arns
})