def cluster_apply(): """ Return a Cluster json body. """ request_debug(r, logger) def make_response_invalid(msg=""): response_fail["error"] = msg or "Invalid request data" response_fail["data"] = request_json_body(r) return jsonify(response_fail), CODE_BAD_REQUEST user_id = request_get(r, "user_id") if not user_id: logger.warning("cluster_apply without user_id") return make_response_invalid("cluster_apply without user_id") allow_multiple, condition = request_get(r, "allow_multiple"), {} consensus_plugin = request_get(r, "consensus_plugin") consensus_mode = request_get(r, "consensus_mode") cluster_size = int(request_get(r, "size") or -1) if consensus_plugin: if consensus_plugin not in CONSENSUS_PLUGINS: logger.warning("Invalid consensus_plugin") return make_response_invalid("Invalid consensus_plugin") else: condition["consensus_plugin"] = consensus_plugin if consensus_mode: if consensus_mode not in CONSENSUS_MODES: logger.warning("Invalid consensus_mode") return make_response_invalid("Invalid consensus_mode") else: condition["consensus_mode"] = consensus_mode if cluster_size >= 0: if cluster_size not in CLUSTER_SIZES: logger.warning("Invalid cluster_size") return make_response_invalid("Invalid cluster_size") else: condition["size"] = cluster_size logger.debug("condition={}".format(condition)) c = cluster_handler.apply_cluster(user_id=user_id, condition=condition, allow_multiple=allow_multiple) if not c: logger.warning("cluster_apply failed") return make_response_invalid("No available res for {}".format(user_id)) else: response_ok["data"] = c return jsonify(response_ok), CODE_OK
def cluster_apply_dep(): """ Return a Cluster json body. """ request_debug(r, logger) user_id = request_get(r, "user_id") if not user_id: error_msg = "cluster_apply without user_id" logger.warning(error_msg) return make_fail_resp(error=error_msg) allow_multiple, condition = request_get(r, "allow_multiple"), {} consensus_plugin = request_get(r, "consensus_plugin") consensus_mode = request_get(r, "consensus_mode") cluster_size = int(request_get(r, "size") or -1) if consensus_plugin: if consensus_plugin not in CONSENSUS_PLUGINS: error_msg = "Invalid consensus_plugin" logger.warning(error_msg) return make_fail_resp(error=error_msg) else: condition["consensus_plugin"] = consensus_plugin if consensus_mode: if consensus_mode not in CONSENSUS_MODES: error_msg = "Invalid consensus_mode" logger.warning(error_msg) return make_fail_resp(error=error_msg) else: condition["consensus_mode"] = consensus_mode if cluster_size >= 0: if cluster_size not in NETWORK_SIZE_FABRIC_PRE_V1: error_msg = "Invalid cluster_size" logger.warning(error_msg) return make_fail_resp(error=error_msg) else: condition["size"] = cluster_size logger.debug("condition={}".format(condition)) c = cluster_handler.apply_cluster(user_id=user_id, condition=condition, allow_multiple=allow_multiple) if not c: error_msg = "No available res for {}".format(user_id) logger.warning(error_msg) return make_fail_resp(error=error_msg) else: return make_ok_resp(data=c)
def cluster_apply_dep(): """ Return a Cluster json body. """ request_debug(r, logger) user_id = request_get(r, "user_id") if not user_id: error_msg = "cluster_apply without user_id" logger.warning(error_msg) return make_fail_response(error=error_msg) allow_multiple, condition = request_get(r, "allow_multiple"), {} consensus_plugin = request_get(r, "consensus_plugin") consensus_mode = request_get(r, "consensus_mode") cluster_size = int(request_get(r, "size") or -1) if consensus_plugin: if consensus_plugin not in CONSENSUS_PLUGINS: error_msg = "Invalid consensus_plugin" logger.warning(error_msg) return make_fail_response(error=error_msg) else: condition["consensus_plugin"] = consensus_plugin if consensus_mode: if consensus_mode not in CONSENSUS_MODES: error_msg = "Invalid consensus_mode" logger.warning(error_msg) return make_fail_response(error=error_msg) else: condition["consensus_mode"] = consensus_mode if cluster_size >= 0: if cluster_size not in CLUSTER_SIZES: error_msg = "Invalid cluster_size" logger.warning(error_msg) return make_fail_response(error=error_msg) else: condition["size"] = cluster_size logger.debug("condition={}".format(condition)) c = cluster_handler.apply_cluster(user_id=user_id, condition=condition, allow_multiple=allow_multiple) if not c: error_msg = "No available res for {}".format(user_id) logger.warning(error_msg) return make_fail_response(error=error_msg) else: return make_ok_response(data=c)
def cluster_apply(r): """Apply a cluster. Return a Cluster json body. """ request_debug(r, logger) user_id = request_get(r, "user_id") if not user_id: logger.warning("cluster_apply without user_id") return make_fail_response("cluster_apply without user_id") allow_multiple, condition = request_get(r, "allow_multiple"), {} consensus_plugin = request_get(r, "consensus_plugin") consensus_mode = request_get(r, "consensus_mode") cluster_size = int(request_get(r, "size") or -1) if consensus_plugin: if consensus_plugin not in CONSENSUS_PLUGINS: logger.warning("Invalid consensus_plugin") return make_fail_response("Invalid consensus_plugin") else: condition["consensus_plugin"] = consensus_plugin if consensus_mode: if consensus_mode not in CONSENSUS_MODES: logger.warning("Invalid consensus_mode") return make_fail_response("Invalid consensus_mode") else: condition["consensus_mode"] = consensus_mode if cluster_size >= 0: if cluster_size not in CLUSTER_SIZES: logger.warning("Invalid cluster_size") return make_fail_response("Invalid cluster_size") else: condition["size"] = cluster_size logger.debug("condition={}".format(condition)) c = cluster_handler.apply_cluster(user_id=user_id, condition=condition, allow_multiple=allow_multiple) if not c: logger.warning("cluster_apply failed") return make_fail_response("No available res for {}".format(user_id)) else: return make_ok_response(data=c)
def cluster_apply(r): """Apply a cluster. Return a Cluster json body. """ request_debug(r, logger) user_id = request_get(r, "user_id") if not user_id: logger.warning("cluster_apply without user_id") return make_fail_resp("cluster_apply without user_id") allow_multiple, condition = request_get(r, "allow_multiple"), {} consensus_plugin = request_get(r, "consensus_plugin") consensus_mode = request_get(r, "consensus_mode") cluster_size = int(request_get(r, "size") or -1) if consensus_plugin: if consensus_plugin not in CONSENSUS_PLUGINS_FABRIC_V1: logger.warning("Invalid consensus_plugin") return make_fail_resp("Invalid consensus_plugin") else: condition["consensus_plugin"] = consensus_plugin if consensus_mode: if consensus_mode not in CONSENSUS_MODES: logger.warning("Invalid consensus_mode") return make_fail_resp("Invalid consensus_mode") else: condition["consensus_mode"] = consensus_mode if cluster_size >= 0: if cluster_size not in NETWORK_SIZE_FABRIC_PRE_V1: logger.warning("Invalid cluster_size") return make_fail_resp("Invalid cluster_size") else: condition["size"] = cluster_size logger.debug("condition={}".format(condition)) c = cluster_handler.apply_cluster(user_id=user_id, condition=condition, allow_multiple=allow_multiple) if not c: logger.warning("cluster_apply failed") return make_fail_resp("No available res for {}".format(user_id)) else: return make_ok_resp(data=c)