aboutsummaryrefslogtreecommitdiffstats
path: root/api/resources/v2/containers.py
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2017-07-17 07:54:46 +0000
committerchenjiankun <chenjiankun1@huawei.com>2017-07-17 07:54:46 +0000
commit41742db0c3528f86b93cff532e5f0b571b607fc2 (patch)
tree1edbe6b87682dc3c05ac0632d6560fe8d40c48fb /api/resources/v2/containers.py
parent6444f136ec83856e7d9beabf765124d2a6d18466 (diff)
Add API(v2) to get container info
JIRA: YARDSTICK-728 API: /api/v2/yardstick/containers/<container_id> METHOD: GET Change-Id: Iba34e6c6dd84573dc9d5914a584d920678c0de36 Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'api/resources/v2/containers.py')
-rw-r--r--api/resources/v2/containers.py27
1 files changed, 27 insertions, 0 deletions
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})