def api_proc_high_permit(request, appname, procname): if request.method == 'DELETE': status_code, view_object, msg, url = ProcApi.delete_app_proc(appname, procname) return render_json_response(status_code, 'proc', view_object, msg, url) elif request.method == 'PATCH': try: options = json.loads(request.body) except Exception: return render_json_response(400, 'proc', None, 'invalid request: should be json body with num_instances(integer) or cpu(integer) or memory(str)', reverse('api_docs')) status_code, view_object, msg, url = ProcApi.update_app_proc(appname, procname, options) return render_json_response(status_code, 'proc', view_object, msg, url)
def api_proc_history_get(request, appname, procname, instance): try: status_code, view_object, msg, url = ProcApi.get_proc_history( appname, procname, instance) return render_json_response(status_code, 'proc', view_object, msg, url) except Exception: return render_json_response(400, 'proc history', None, 'invalid request: should be json body with procname(detail string) instance(int)', reverse('api_docs'))
def api_procs_post(request, appname): try: options = json.loads(request.body) procname = options['procname'] except Exception: return render_json_response(400, 'proc', None, 'invalid request: should be json body with procname(string)', reverse('api_docs')) status_code, view_object, msg, url = ProcApi.create_app_proc(appname, procname, options) return render_json_response(status_code, 'proc', view_object, msg, url)
def api_proc_history_get(request, appname, procname, instance): try: status_code, view_object, msg, url = ProcApi.get_proc_history( appname, procname, instance) return render_json_response(status_code, 'proc', view_object, msg, url) except Exception: return render_json_response( 400, 'proc history', None, 'invalid request: should be json body with procname(detail string) instance(int)', reverse('api_docs'))
def api_proc_high_permit(request, appname, procname): if request.method == 'DELETE': status_code, view_object, msg, url = ProcApi.delete_app_proc( appname, procname) return render_json_response(status_code, 'proc', view_object, msg, url) elif request.method == 'PATCH': try: options = json.loads(request.body) operation = options.get('operation', 'schedule') access_token = request.META.get('HTTP_ACCESS_TOKEN', 'unknown') if operation == 'schedule': status_code, view_object, msg, url = ProcApi.update_app_proc( access_token, appname, procname, options) else: status_code, view_object, msg, url = ProcApi.operate_proc( appname, procname, operation, options) except Exception: return render_json_response(400, 'proc', None, 'invalid request: should be json body with num_instances(integer) or cpu(integer) or memory(str)', reverse('api_docs')) return render_json_response(status_code, 'proc', view_object, msg, url)
def api_proc_high_permit(request, appname, procname): if request.method == 'DELETE': status_code, view_object, msg, url = ProcApi.delete_app_proc( appname, procname) return render_json_response(status_code, 'proc', view_object, msg, url) elif request.method == 'PATCH': try: options = json.loads(request.body) operation = options.get('operation', 'schedule') access_token = request.META.get('HTTP_ACCESS_TOKEN', 'unknown') if operation == 'schedule': status_code, view_object, msg, url = ProcApi.update_app_proc( access_token, appname, procname, options) else: status_code, view_object, msg, url = ProcApi.operate_proc( appname, procname, operation, options) except Exception: return render_json_response( 400, 'proc', None, 'invalid request: should be json body with num_instances(integer) or cpu(integer) or memory(str)', reverse('api_docs')) return render_json_response(status_code, 'proc', view_object, msg, url)
def api_proc_get(request, appname, procname): status_code, view_object, msg, url = ProcApi.get_app_proc( appname, procname) return render_json_response(status_code, 'proc', view_object, msg, url)
def test_ProcApi_render_pod_data_with_value_error(pod): with pytest.raises(ValueError): ProcApi.render_pod_data(pod)
def test_ProcApi_render_pod_data_with_type_error(pod): with pytest.raises(TypeError): ProcApi.render_pod_data(pod)
def test_ProcApi_render_pod_data(pod, want): got = ProcApi.render_pod_data(pod) assert got == want