summaryrefslogtreecommitdiffstats
path: root/api/resources
diff options
context:
space:
mode:
authorJing Lu <lvjing5@huawei.com>2017-07-19 08:18:06 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-07-19 08:18:06 +0000
commitdec0be619a3968b0a30de710d83636c372f75574 (patch)
treeeee100931293077e5c87e651d81f5f575c000344 /api/resources
parentc65afc527dba2f409506aa5f723dd94593dd0dac (diff)
parent41742db0c3528f86b93cff532e5f0b571b607fc2 (diff)
Merge "Add API(v2) to get container info"
Diffstat (limited to 'api/resources')
-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})