Add API(v2) to delete pod 85/37485/1
authorchenjiankun <chenjiankun1@huawei.com>
Fri, 14 Jul 2017 03:54:06 +0000 (03:54 +0000)
committerchenjiankun <chenjiankun1@huawei.com>
Fri, 14 Jul 2017 08:45:31 +0000 (08:45 +0000)
JIRA: YARDSTICK-725

API: /api/v2/yardstick/pods/<pod_id>
METHOD: DELETE

Change-Id: Ib9e9f9ced455c4ee3b6e1f63d773ea2e3ee906a6
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
api/resources/v2/pods.py

index ffb8a60..ebc1312 100644 (file)
@@ -77,3 +77,24 @@ class V2Pod(ApiResource):
         content = jsonutils.loads(pod.content)
 
         return result_handler(consts.API_SUCCESS, {'pod': content})
+
+    def delete(self, pod_id):
+        try:
+            uuid.UUID(pod_id)
+        except ValueError:
+            return result_handler(consts.API_ERROR, 'invalid pod id')
+
+        pod_handler = V2PodHandler()
+        try:
+            pod = pod_handler.get_by_uuid(pod_id)
+        except ValueError:
+            return result_handler(consts.API_ERROR, 'no such pod')
+
+        LOG.info('update pod in environment')
+        environment_handler = V2EnvironmentHandler()
+        environment_handler.update_attr(pod.environment_id, {'pod_id': None})
+
+        LOG.info('delete pod in database')
+        pod_handler.delete_by_uuid(pod_id)
+
+        return result_handler(consts.API_SUCCESS, {'pod': pod_id})