diff options
Diffstat (limited to 'docker/storperf-master/rest_server.py')
-rw-r--r-- | docker/storperf-master/rest_server.py | 54 |
1 files changed, 47 insertions, 7 deletions
diff --git a/docker/storperf-master/rest_server.py b/docker/storperf-master/rest_server.py index 19f87ca..0634b8f 100644 --- a/docker/storperf-master/rest_server.py +++ b/docker/storperf-master/rest_server.py @@ -13,12 +13,13 @@ import os import sys from flask import abort, Flask, request, jsonify +from flask_cors import CORS from flask_restful import Resource, Api, fields from flask_restful_swagger import swagger -from flask_cors import CORS from storperf.storperf_master import StorPerfMaster + app = Flask(__name__, static_url_path="") CORS(app) api = swagger.docs(Api(app), apiVersion='1.0') @@ -26,6 +27,35 @@ api = swagger.docs(Api(app), apiVersion='1.0') storperf = StorPerfMaster() +class Logs(Resource): + def __init__(self): + self.logger = logging.getLogger(__name__) + + @swagger.operation( + notes="Fetch logs", + parameters=[ + { + "name": "lines", + "description": "The number of lines to fetch", + "required": "False", + "type": "string", + "allowedMultiple": "False", + "paramType": "query" + } + ] + ) + def get(self): + lines = request.args.get('lines') + if lines: + try: + lines = int(lines) + except Exception: + pass + else: + lines = 35 + return jsonify({'logs': storperf.get_logs(lines)}) + + @swagger.model class ConfigurationRequestModel: resource_fields = { @@ -34,7 +64,9 @@ class ConfigurationRequestModel: 'agent_image': fields.String, 'public_network': fields.String, 'volume_size': fields.Integer, - 'availability_zone': fields.String + 'availability_zone': fields.String, + 'username': fields.String, + 'password': fields.String } @@ -107,6 +139,10 @@ class Configure(Resource): storperf.volume_size = request.json['volume_size'] if ('availability_zone' in request.json): storperf.availabilty_zone = request.json['availability_zone'] + if ('username' in request.json): + storperf.username = request.json['username'] + if ('password' in request.json): + storperf.password = request.json['password'] storperf.create_stack() if storperf.stack_id is None: @@ -194,13 +230,13 @@ class Job(Resource): ) def get(self): - metrics_type = "metrics" - if request.args.get('type'): - metrics_type = request.args.get('type') - workload_id = request.args.get('id') if workload_id: + metrics_type = "metrics" + if request.args.get('type'): + metrics_type = request.args.get('type') + if metrics_type == "metrics": return jsonify(storperf.fetch_results(workload_id)) @@ -210,7 +246,10 @@ class Job(Resource): if metrics_type == "status": return jsonify(storperf.fetch_job_status(workload_id)) else: - return jsonify({"job_ids": storperf.fetch_all_jobs()}) + metrics_type = None + if request.args.get('type'): + metrics_type = request.args.get('type') + return jsonify(storperf.fetch_all_jobs(metrics_type)) @swagger.operation( parameters=[ @@ -343,6 +382,7 @@ def setup_logging(default_path='logging.json', api.add_resource(Configure, "/api/v1.0/configurations") api.add_resource(Quota, "/api/v1.0/quotas") api.add_resource(Job, "/api/v1.0/jobs") +api.add_resource(Logs, "/api/v1.0/logs") if __name__ == "__main__": setup_logging() |