def cluster_delete(): """Delete a cluster DELETE /cluster { id: xxx col_name: active } :return: response obj """ logger.info("/cluster action=" + r.method) request_debug(r, logger) if not r.form["id"] or not r.form["col_name"]: error_msg = "cluster operation post without enough data" logger.warning(error_msg) return make_fail_response(error=error_msg, data=r.form) else: logger.debug("cluster delete with id={0}, col_name={1}".format( r.form["id"], r.form["col_name"])) if r.form["col_name"] == "active": result = cluster_handler.delete(id=r.form["id"]) else: result = cluster_handler.delete_released(id=r.form["id"]) if result: return make_ok_response() else: error_msg = "Failed to delete cluster {}".format(r.form["id"]) logger.warning(error_msg) return make_fail_response(error=error_msg)
def cluster_delete(): """Delete a cluster DELETE /cluster { id: xxx col_name: active } :return: response obj """ logger.info("/cluster action=" + r.method) request_debug(r, logger) if not r.form["id"] or not r.form["col_name"]: error_msg = "cluster operation post without enough data" logger.warning(error_msg) return make_fail_response(error=error_msg, data=r.form) else: logger.debug("cluster delete with id={0}, col_name={1}".format( r.form["id"], r.form["col_name"])) if r.form["col_name"] == "active": result = cluster_handler.delete(id=r.form["id"]) else: result = cluster_handler.delete_released(id=r.form["id"]) if result: return make_ok_response() else: error_msg = "Failed to delete cluster {}".format(r.form["id"]) logger.warning(error_msg) return make_fail_response(error=error_msg)
def delete_cluster(cluster_id, status): if status == "active": result = cluster_handler.delete(id=cluster_id) else: result = cluster_handler.delete_released(id=cluster_id) if result: return True
def delete_cluster(self, cluster_id, status): if status == "active": result = cluster_handler.delete(id=cluster_id) else: result = cluster_handler.delete_released(id=cluster_id) if result: return True self.retry(exc=DeleteClusterException)
def cluster_delete(): """Delete a cluster DELETE /cluster { id: xxx col_name: active } :return: response obj """ logger.info("/cluster action=" + r.method) request_data = r.get_json(force=True, silent=True) if r.form: cluster_id = r.form["id"] col_name = r.form["col_name"] else: cluster_id = request_data.get("id") col_name = request_data.get("col_name") request_debug(r, logger) if not cluster_id or not col_name: error_msg = "cluster operation post without enough data" logger.warning(error_msg) return make_fail_resp(error=error_msg, data=r.form) else: logger.debug("cluster delete with id={0}, col_name={1}".format( cluster_id, col_name)) if col_name == "active": result = cluster_handler.delete(id=cluster_id) else: result = cluster_handler.delete_released(id=cluster_id) if result: return make_ok_resp() else: error_msg = "Failed to delete cluster {}".format(cluster_id) logger.warning(error_msg) return make_fail_resp(error=error_msg)
def cluster_delete(): """Delete a cluster DELETE /cluster { id: xxx col_name: active } :return: response obj """ logger.info("/cluster action=" + r.method) request_data = r.get_json(force=True, silent=True) if r.form: cluster_id = r.form["id"] col_name = r.form["col_name"] else: cluster_id = request_data.get("id") col_name = request_data.get("col_name") request_debug(r, logger) if not cluster_id or not col_name: error_msg = "cluster operation post without enough data" logger.warning(error_msg) return make_fail_resp(error=error_msg, data=r.form) else: logger.debug("cluster delete with id={0}, col_name={1}".format( cluster_id, col_name)) if col_name == "active": result = cluster_handler.delete(id=cluster_id) else: result = cluster_handler.delete_released(id=cluster_id) if result: return make_ok_resp() else: error_msg = "Failed to delete cluster {}".format(cluster_id) logger.warning(error_msg) return make_fail_resp(error=error_msg)
def cluster_api(): logger.info("/cluster action=" + r.method) request_debug(r, logger) if r.method == 'GET': if not r.form["id"]: logger.warn("cluster get without enough data") response_fail["error"] = "cluster GET without enough data" response_fail["data"] = r.form return jsonify(response_fail), CODE_BAD_REQUEST else: logger.debug("id=" + r.form['id']) result = cluster_handler.get_by_id(r.form['id']) if result: return jsonify(result), CODE_OK else: logger.warn("cluster not found with id=" + r.form['id']) response_fail["data"] = r.form return jsonify(response_fail), CODE_BAD_REQUEST elif r.method == 'POST': if not r.form["name"] or not r.form["host_id"] or not \ r.form["consensus_plugin"] or not r.form["size"]: logger.warn("cluster post without enough data") response_fail["error"] = "cluster POST without enough data" response_fail["data"] = r.form return jsonify(response_fail), CODE_BAD_REQUEST else: name, host_id, consensus_plugin, consensus_mode, size = \ r.form['name'], r.form['host_id'], r.form['consensus_plugin'],\ r.form['consensus_mode'] or CONSENSUS_MODES[0], int(r.form[ "size"]) if consensus_plugin not in CONSENSUS_PLUGINS: logger.debug( "Unknown consensus_plugin={}".format(consensus_plugin)) return jsonify(response_fail), CODE_BAD_REQUEST if consensus_plugin != CONSENSUS_PLUGINS[0] and consensus_mode \ not in CONSENSUS_MODES: logger.debug("Invalid consensus, plugin={}, mode={}".format( consensus_plugin, consensus_mode)) return jsonify(response_fail), CODE_BAD_REQUEST if size not in CLUSTER_SIZES: logger.debug("Unknown cluster size={}".format(size)) return jsonify(response_fail), CODE_BAD_REQUEST if cluster_handler.create(name=name, host_id=host_id, consensus_plugin=consensus_plugin, consensus_mode=consensus_mode, size=size): logger.debug("cluster POST successfully") return jsonify(response_ok), CODE_CREATED else: logger.debug("cluster creation failed") response_fail["error"] = "Failed to create cluster {}".format( name) return jsonify(response_fail), CODE_BAD_REQUEST elif r.method == 'DELETE': if not r.form["id"] or not r.form["col_name"]: logger.warn("cluster operation post without enough data") response_fail["error"] = "cluster delete without enough data" response_fail["data"] = r.form return jsonify(response_fail), CODE_BAD_REQUEST else: logger.debug("cluster delete with id={0}, col_name={1}".format( r.form["id"], r.form["col_name"])) if r.form["col_name"] == "active": result = cluster_handler.delete(id=r.form["id"]) else: result = cluster_handler.delete_released(id=r.form["id"]) if result: return jsonify(response_ok), CODE_OK else: logger.debug("cluster deletion failed") response_fail["error"] = "Failed to delete cluster {}".format( r.form["id"]) return jsonify(response_fail), CODE_BAD_REQUEST else: response_fail["error"] = "unknown operation method" response_fail["data"] = r.form return jsonify(response_fail), CODE_BAD_REQUEST