Add API(v2) to delete openrc 47/37447/2
authorchenjiankun <chenjiankun1@huawei.com>
Fri, 14 Jul 2017 01:49:52 +0000 (01:49 +0000)
committerchenjiankun <chenjiankun1@huawei.com>
Fri, 14 Jul 2017 05:04:53 +0000 (05:04 +0000)
JIRA: YARDSTICK-722

API: /api/v2/yardstick/environments/openrcs/<openrc_id>
METHOD: DELETE

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

index afabcde..5f3b938 100644 (file)
@@ -188,3 +188,24 @@ class V2Openrc(ApiResource):
         content = jsonutils.loads(openrc.content)
 
         return result_handler(consts.API_ERROR, {'openrc': content})
+
+    def delete(self, openrc_id):
+        try:
+            uuid.UUID(openrc_id)
+        except ValueError:
+            return result_handler(consts.API_ERROR, 'invalid openrc id')
+
+        LOG.info('Geting openrc: %s', openrc_id)
+        openrc_handler = V2OpenrcHandler()
+        try:
+            openrc = openrc_handler.get_by_uuid(openrc_id)
+        except ValueError:
+            return result_handler(consts.API_ERROR, 'no such openrc id')
+
+        LOG.info('update openrc in environment')
+        environment_handler = V2EnvironmentHandler()
+        environment_handler.update_attr(openrc.environment_id, {'openrc_id': None})
+
+        openrc_handler.delete_by_uuid(openrc_id)
+
+        return result_handler(consts.API_SUCCESS, {'openrc': openrc_id})