From 41742db0c3528f86b93cff532e5f0b571b607fc2 Mon Sep 17 00:00:00 2001 From: chenjiankun Date: Mon, 17 Jul 2017 07:54:46 +0000 Subject: Add API(v2) to get container info JIRA: YARDSTICK-728 API: /api/v2/yardstick/containers/ METHOD: GET Change-Id: Iba34e6c6dd84573dc9d5914a584d920678c0de36 Signed-off-by: chenjiankun --- api/resources/v2/containers.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/api/resources/v2/containers.py b/api/resources/v2/containers.py index 5042e0592..556477df7 100644 --- a/api/resources/v2/containers.py +++ b/api/resources/v2/containers.py @@ -318,3 +318,30 @@ class V2Containers(ApiResource): LOG.info('Starting container') client.start(container) return container + + +class V2Container(ApiResource): + + def get(self, container_id): + try: + uuid.UUID(container_id) + except ValueError: + result_handler(consts.API_ERROR, 'invalid container id') + + try: + container = container_handler.get_by_uuid(container_id) + except ValueError: + result_handler(consts.API_ERROR, 'no such container id') + + name = container.name + client = Client(base_url=consts.DOCKER_URL) + info = client.inspect_container(name) + + data = { + 'name': name, + 'status': info.get('State', {}).get('Status', 'error'), + 'time': info.get('Created'), + 'port': container.port + } + + return result_handler(consts.API_SUCCESS, {'container': data}) -- cgit 1.2.3-korg