Skip to content

Commit

Permalink
Edit file Workload metric
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanBoronat committed Oct 23, 2017
1 parent b1172fb commit 1810464
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion api/metrics/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,31 @@ class MetricModuleData(APIView):
Upload or download a metric module data.
"""
parser_classes = (MultiPartParser, FormParser,)

def put(self, request, metric_module_id):
data = {}

try:
r = get_redis_connection()
except RedisError:
return JSONResponse('Error connecting with DB', status=status.HTTP_500_INTERNAL_SERVER_ERROR)

try:
file_obj = request.FILES['file']

make_sure_path_exists(settings.WORKLOAD_METRICS_DIR)
path = save_file(file_obj, settings.WORKLOAD_METRICS_DIR)
data['metric_name'] = os.path.basename(path)

r.hmset('workload_metric:' + str(metric_module_id), data)

return JSONResponse("Data updated", status=status.HTTP_201_CREATED)
except DataError:
return JSONResponse("Error updating data", status=status.HTTP_400_BAD_REQUEST)
except ValueError:
return JSONResponse("Error starting controller", status=status.HTTP_400_BAD_REQUEST)

def put(self, request):
def post(self, request):
try:
r = get_redis_connection()
except RedisError:
Expand Down

0 comments on commit 1810464

Please sign in to comment.