summaryrefslogtreecommitdiffstats
path: root/api/resources
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2017-06-22 13:00:40 +0000
committerchenjiankun <chenjiankun1@huawei.com>2017-06-24 06:25:50 +0000
commitc04372b8630169a3fcc4b52e8d2b935f110519a6 (patch)
tree7848d9a53a60421ee3f659707fe350c03d4d0337 /api/resources
parentcd5bb5f2dd2ec89e6c814c2771402aa8e39e10ef (diff)
Add API to upload pod.yaml file
JIRA: YARDSTICK-687 We need a API to upload a pod.yaml file to /etc/yardstick/pod.yaml. API: /yardstick/env/action method: POST param: { 'action': 'upload_pod_file', 'file': file object } Change-Id: I3d25df364da10aaf34f995e948e1704235a40f6f Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'api/resources')
-rw-r--r--api/resources/env_action.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/api/resources/env_action.py b/api/resources/env_action.py
index 42bef8529..3536559b7 100644
--- a/api/resources/env_action.py
+++ b/api/resources/env_action.py
@@ -16,12 +16,12 @@ import threading
import time
import uuid
import glob
+import yaml
import collections
from six.moves import configparser
from oslo_serialization import jsonutils
from docker import Client
-from docker.utils import create_host_config
from api.database.handler import AsyncTaskHandler
from api.utils import influx
@@ -343,3 +343,22 @@ def update_openrc(args):
logger.info('Source openrc: Done')
return result_handler(consts.API_SUCCESS, {'openrc': openrc_vars})
+
+
+def upload_pod_file(args):
+ try:
+ pod_file = args['file']
+ except KeyError:
+ return result_handler(consts.API_ERROR, 'file must be provided')
+
+ logger.info('Checking file')
+ data = yaml.load(pod_file.read())
+ if not isinstance(data, collections.Mapping):
+ return result_handler(consts.API_ERROR, 'invalid yaml file')
+
+ logger.info('Writing file')
+ with open(consts.POD_FILE, 'w') as f:
+ yaml.dump(data, f, default_flow_style=False)
+ logger.info('Writing finished')
+
+ return result_handler(consts.API_SUCCESS, {'pod_info': data})