Updated fixtures for ECS from further field testing. updated docs with an example of how to deploy.
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/c5edd3a2 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/c5edd3a2 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/c5edd3a2 Branch: refs/heads/trunk Commit: c5edd3a2513c370648f8540c16a173a09adc1b26 Parents: 9274450 Author: anthony-shaw <[email protected]> Authored: Sun Jan 3 21:41:05 2016 +1100 Committer: anthony-shaw <[email protected]> Committed: Sun Jan 3 21:41:05 2016 +1100 ---------------------------------------------------------------------- docs/container/drivers/ecs.rst | 6 +++ docs/examples/container/ecs/deploy_container.py | 20 +++++++ libcloud/container/drivers/ecs.py | 50 +++++++---------- .../container/fixtures/ecs/createcluster.json | 18 +++---- .../container/fixtures/ecs/deletecluster.json | 18 +++---- .../container/fixtures/ecs/listclusters.json | 1 + .../fixtures/ecs/registertaskdefinition.json | 41 +++++++------- .../test/container/fixtures/ecs/runtask.json | 57 ++++++++------------ libcloud/test/container/test_ecs.py | 7 +-- 9 files changed, 109 insertions(+), 109 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/c5edd3a2/docs/container/drivers/ecs.rst ---------------------------------------------------------------------- diff --git a/docs/container/drivers/ecs.rst b/docs/container/drivers/ecs.rst index 138eceb..20ab400 100644 --- a/docs/container/drivers/ecs.rst +++ b/docs/container/drivers/ecs.rst @@ -17,6 +17,12 @@ Instantiating the driver .. literalinclude:: /examples/container/ecs/instantiate_driver.py :language: python + +Deploying a container +--------------------- + +.. literalinclude:: /examples/container/ecs/deploy_container.py + :language: python API Docs -------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/c5edd3a2/docs/examples/container/ecs/deploy_container.py ---------------------------------------------------------------------- diff --git a/docs/examples/container/ecs/deploy_container.py b/docs/examples/container/ecs/deploy_container.py new file mode 100644 index 0000000..f9bc9df --- /dev/null +++ b/docs/examples/container/ecs/deploy_container.py @@ -0,0 +1,20 @@ +from libcloud.container.base import ContainerImage +from libcloud.container.types import Provider +from libcloud.container.providers import get_driver + +cls = get_driver(Provider.ECS) + +conn = cls(access_id='AKIAI7OR4GWEEPRIFBBA', + secret='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', + region='ap-southeast-2') + +container = conn.deploy_container( + name='my-simple-app', + image=ContainerImage( + id=None, + name='simple-app', + path='simple-app', + version=None, + driver=conn + ) +) http://git-wip-us.apache.org/repos/asf/libcloud/blob/c5edd3a2/libcloud/container/drivers/ecs.py ---------------------------------------------------------------------- diff --git a/libcloud/container/drivers/ecs.py b/libcloud/container/drivers/ecs.py index 746c176..d390201 100644 --- a/libcloud/container/drivers/ecs.py +++ b/libcloud/container/drivers/ecs.py @@ -68,12 +68,18 @@ class ElasticContainerDriver(ContainerDriver): :rtype: ``list`` of :class:`ContainerCluster` """ - params = {'Action': 'DescribeClusters'} - data = self.connection.request( + listdata = self.connection.request( ROOT, method='POST', data=json.dumps({}), - headers=self._get_headers(params['Action']) + headers=self._get_headers('ListClusters') + ).object + request = {'clusters': listdata['clusterArns']} + data = self.connection.request( + ROOT, + method='POST', + data=json.dumps(request), + headers=self._get_headers('DescribeClusters') ).object return self._to_clusters(data) @@ -114,28 +120,6 @@ class ElasticContainerDriver(ContainerDriver): ).object return data['cluster']['status'] == 'INACTIVE' - def install_image(self, path): - """ - Install a container image from a remote path. - - :param path: Path to the container image - :type path: ``str`` - - :rtype: :class:`ContainerImage` - """ - raise NotImplementedError( - 'install_image not implemented for this driver') - - def list_images(self): - """ - List the installed container images, in ECS these are - equivalent to the containers within task definitions. - - :rtype: ``list`` of :class:`ContainerImage` - """ - raise NotImplementedError( - 'list_images not implemented for this driver') - def list_containers(self, image=None, cluster=None): """ List the deployed container images @@ -188,6 +172,15 @@ class ElasticContainerDriver(ContainerDriver): :rtype: :class:`Container` """ data = {} + if ex_container_port is None and ex_host_port is None: + port_maps = [] + else: + port_maps = [ + { + "containerPort": ex_container_port, + "hostPort": ex_host_port + } + ] data['containerDefinitions'] = [ { "mountPoints": [], @@ -196,12 +189,7 @@ class ElasticContainerDriver(ContainerDriver): "cpu": ex_cpu, "environment": [], "memory": ex_memory, - "portMappings": [ - { - "containerPort": ex_container_port, - "hostPort": ex_host_port - } - ], + "portMappings": port_maps, "essential": True, "volumesFrom": [] } http://git-wip-us.apache.org/repos/asf/libcloud/blob/c5edd3a2/libcloud/test/container/fixtures/ecs/createcluster.json ---------------------------------------------------------------------- diff --git a/libcloud/test/container/fixtures/ecs/createcluster.json b/libcloud/test/container/fixtures/ecs/createcluster.json index 1fb35e6..eb6ced3 100644 --- a/libcloud/test/container/fixtures/ecs/createcluster.json +++ b/libcloud/test/container/fixtures/ecs/createcluster.json @@ -1,11 +1,11 @@ { - "cluster": { - "activeServicesCount": 0, - "clusterArn": "arn:aws:ecs:us-east-1:012345678910:cluster/jim", - "clusterName": "jim", - "pendingTasksCount": 0, - "registeredContainerInstancesCount": 0, - "runningTasksCount": 0, - "status": "ACTIVE" - } + "cluster": { + "activeServicesCount": 0, + "clusterArn": "arn:aws:ecs:ap-southeast-2:647433528374:cluster/my-cluster", + "clusterName": "my-cluster", + "pendingTasksCount": 0, + "registeredContainerInstancesCount": 0, + "runningTasksCount": 0, + "status": "ACTIVE" + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/libcloud/blob/c5edd3a2/libcloud/test/container/fixtures/ecs/deletecluster.json ---------------------------------------------------------------------- diff --git a/libcloud/test/container/fixtures/ecs/deletecluster.json b/libcloud/test/container/fixtures/ecs/deletecluster.json index 94d5aa2..9c8c0cd 100644 --- a/libcloud/test/container/fixtures/ecs/deletecluster.json +++ b/libcloud/test/container/fixtures/ecs/deletecluster.json @@ -1,11 +1,11 @@ { - "cluster": { - "activeServicesCount": 0, - "clusterArn": "arn:aws:ecs:us-east-1:012345678910:cluster/jim", - "clusterName": "jim", - "pendingTasksCount": 0, - "registeredContainerInstancesCount": 0, - "runningTasksCount": 0, - "status": "INACTIVE" - } + "cluster": { + "activeServicesCount": 0, + "clusterArn": "arn:aws:ecs:ap-southeast-2:647433528374:cluster/my-cluster", + "clusterName": "my-cluster", + "pendingTasksCount": 0, + "registeredContainerInstancesCount": 0, + "runningTasksCount": 0, + "status": "INACTIVE" + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/libcloud/blob/c5edd3a2/libcloud/test/container/fixtures/ecs/listclusters.json ---------------------------------------------------------------------- diff --git a/libcloud/test/container/fixtures/ecs/listclusters.json b/libcloud/test/container/fixtures/ecs/listclusters.json new file mode 100644 index 0000000..11c0d0e --- /dev/null +++ b/libcloud/test/container/fixtures/ecs/listclusters.json @@ -0,0 +1 @@ +{"clusterArns":["arn:aws:ecs:ap-southeast-2:647433528374:cluster/my-cluster","arn:aws:ecs:ap-southeast-2:647433528374:cluster/default"]} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/libcloud/blob/c5edd3a2/libcloud/test/container/fixtures/ecs/registertaskdefinition.json ---------------------------------------------------------------------- diff --git a/libcloud/test/container/fixtures/ecs/registertaskdefinition.json b/libcloud/test/container/fixtures/ecs/registertaskdefinition.json index 163061d..fd53f9d 100644 --- a/libcloud/test/container/fixtures/ecs/registertaskdefinition.json +++ b/libcloud/test/container/fixtures/ecs/registertaskdefinition.json @@ -1,26 +1,21 @@ { - "taskDefinition": { - "containerDefinitions": [ - { - "cpu": 10, - "environment": [ - { - "name": "MYSQL_ROOT_PASSWORD", - "value": "password" - } + "taskDefinition": { + "containerDefinitions": [{ + "cpu": 10, + "environment": [], + "essential": true, + "image": "simple-app", + "memory": 500, + "mountPoints": [], + "name": "my-simple-app", + "portMappings": [], + "volumesFrom": [] + } ], - "essential": true, - "image": "mysql", - "memory": 500, - "mountPoints": [], - "name": "mysql", - "portMappings": [], - "volumesFrom": [] - } - ], - "family": "jim", - "revision": 11, - "taskDefinitionArn": "arn:aws:ecs:us-east-1:012345678910:task-definition/hello_world:11", - "volumes": [] - } + "family": "my-simple-app", + "revision": 1, + "status": "ACTIVE", + "taskDefinitionArn": "arn:aws:ecs:ap-southeast-2:647433528374:task-definition/my-simple-app:1", + "volumes": [] + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/libcloud/blob/c5edd3a2/libcloud/test/container/fixtures/ecs/runtask.json ---------------------------------------------------------------------- diff --git a/libcloud/test/container/fixtures/ecs/runtask.json b/libcloud/test/container/fixtures/ecs/runtask.json index 70896e5..d53c97a 100644 --- a/libcloud/test/container/fixtures/ecs/runtask.json +++ b/libcloud/test/container/fixtures/ecs/runtask.json @@ -1,37 +1,26 @@ { - "failures": [], - "tasks": [ - { - "clusterArn": "arn:aws:ecs:us-east-1:012345678910:cluster/default", - "containerInstanceArn": "arn:aws:ecs:us-east-1:012345678910:container-instance/cf447635-790d-477d-be24-58a9cb819d45", - "containers": [ - { - "containerArn": "arn:aws:ecs:us-east-1:012345678910:container/e1ed7aac-d9b2-4315-8726-d2432bf11868", - "lastStatus": "PENDING", - "name": "wordpress", - "taskArn": "arn:aws:ecs:us-east-1:012345678910:task/d8c67b3c-ac87-4ffe-a847-4785bc3a8b55" - }, - { - "containerArn": "arn:aws:ecs:us-east-1:012345678910:container/4b69fabd-991d-4781-bbf9-7efa03c754aa", - "lastStatus": "PENDING", - "name": "mysql", - "taskArn": "arn:aws:ecs:us-east-1:012345678910:task/d8c67b3c-ac87-4ffe-a847-4785bc3a8b55" + "failures": [], + "tasks": [{ + "clusterArn": "arn:aws:ecs:ap-southeast-2:647433528374:cluster/default", + "containerInstanceArn": "arn:aws:ecs:ap-southeast-2:647433528374:container-instance/13b83f4b-d557-48a6-a4d7-2b0e8068e62b", + "containers": [{ + "containerArn": "arn:aws:ecs:ap-southeast-2:647433528374:container/e443d10f-dea3-481e-8a1e-966b9ad4e498", + "lastStatus": "PENDING", + "name": "my-simple-app", + "taskArn": "arn:aws:ecs:ap-southeast-2:647433528374:task/b7c76236-b96f-4de1-93c8-9da3c30ccc23" + } + ], + "createdAt": 1.45181726008E9, + "desiredStatus": "RUNNING", + "lastStatus": "PENDING", + "overrides": { + "containerOverrides": [{ + "name": "my-simple-app" + } + ] + }, + "taskArn": "arn:aws:ecs:ap-southeast-2:647433528374:task/b7c76236-b96f-4de1-93c8-9da3c30ccc23", + "taskDefinitionArn": "arn:aws:ecs:ap-southeast-2:647433528374:task-definition/my-simple-app:1" } - ], - "desiredStatus": "RUNNING", - "lastStatus": "PENDING", - "overrides": { - "containerOverrides": [ - { - "name": "wordpress" - }, - { - "name": "mysql" - } - ] - }, - "taskArn": "arn:aws:ecs:us-east-1:012345678910:task/d8c67b3c-ac87-4ffe-a847-4785bc3a8b55", - "taskDefinitionArn": "arn:aws:ecs:us-east-1:012345678910:task-definition/hello_world:11" - } - ] + ] } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/libcloud/blob/c5edd3a2/libcloud/test/container/test_ecs.py ---------------------------------------------------------------------- diff --git a/libcloud/test/container/test_ecs.py b/libcloud/test/container/test_ecs.py index f0e8937..e2fdb3f 100644 --- a/libcloud/test/container/test_ecs.py +++ b/libcloud/test/container/test_ecs.py @@ -42,8 +42,8 @@ class ElasticContainerDriverTestCase(unittest.TestCase): self.assertEqual(clusters[0].name, 'default') def test_create_cluster(self): - cluster = self.driver.create_cluster('jim') - self.assertEqual(cluster.name, 'jim') + cluster = self.driver.create_cluster('my-cluster') + self.assertEqual(cluster.name, 'my-cluster') def test_destroy_cluster(self): self.assertTrue( @@ -73,7 +73,7 @@ class ElasticContainerDriverTestCase(unittest.TestCase): driver=self.driver ) ) - self.assertEqual(container.id, 'arn:aws:ecs:us-east-1:012345678910:container/e1ed7aac-d9b2-4315-8726-d2432bf11868') + self.assertEqual(container.id, 'arn:aws:ecs:ap-southeast-2:647433528374:container/e443d10f-dea3-481e-8a1e-966b9ad4e498') def test_get_container(self): container = self.driver.get_container( @@ -142,6 +142,7 @@ class ECSMockHttp(MockHttp): 'DeleteCluster': 'deletecluster.json', 'DescribeTasks': 'describetasks.json', 'ListTasks': 'listtasks.json', + 'ListClusters': 'listclusters.json', 'RegisterTaskDefinition': 'registertaskdefinition.json', 'RunTask': 'runtask.json', 'StopTask': 'stoptask.json'
