From 8996240be14d6f7979a6ae02dd474b03d50e79d9 Mon Sep 17 00:00:00 2001
From: chenjiankun <chenjiankun1@huawei.com>
Date: Thu, 29 Jun 2017 02:42:56 +0000
Subject: Add API to update pod yaml file

JIRA: YARDSTICK-693

Apart from API to upload pod yaml file, we also need API to update pod
file.

API: /yardstick/env/action
method: POST
param:
{
    'action': 'update_pod_file',
    'args': {
        'pod': { pod content }
    }
}

Change-Id: I0ba168612ccc2e43c531e4b9253cf72e5c745297
Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
---
 api/resources/env_action.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

(limited to 'api/resources')

diff --git a/api/resources/env_action.py b/api/resources/env_action.py
index 62ec78640..600bd796a 100644
--- a/api/resources/env_action.py
+++ b/api/resources/env_action.py
@@ -364,6 +364,23 @@ def upload_pod_file(args):
     return result_handler(consts.API_SUCCESS, {'pod_info': data})
 
 
+def update_pod_file(args):
+    try:
+        pod_dic = args['pod']
+    except KeyError:
+        return result_handler(consts.API_ERROR, 'pod must be provided')
+    else:
+        if not isinstance(pod_dic, collections.Mapping):
+            return result_handler(consts.API_ERROR, 'pod should be a dict')
+
+    logger.info('Writing file')
+    with open(consts.POD_FILE, 'w') as f:
+        yaml.dump(pod_dic, f, default_flow_style=False)
+    logger.info('Writing finished')
+
+    return result_handler(consts.API_SUCCESS, {'pod_info': pod_dic})
+
+
 def update_hosts(hosts_ip):
     if not isinstance(hosts_ip, dict):
         return result_handler(consts.API_ERROR, 'Error, args should be a dict')
-- 
cgit