def getAllToolSets(): limit = int(request.args.get('perpage', '30')) page = int(request.args.get('page', "0")) skip = page * limit finalData = [] tags_filter = [] toolName_filter = [] name_filter = None if request.args.get('tags', None): tags_filter = request.args.get('tags', None).split(",") if request.args.get('toolname', None): toolName_filter = request.args.get('toolname', None).split(",") id_list = teamService.get_user_permissions( authService.get_userid_by_auth_token())[ "parent_entity_set_id_list"] # TOOL SET IDS if request.args.get('name', None): name_filter = request.args.get('name', None) filter_required = {"_id": {"$in": id_list}} if name_filter: filter_required.update( {"name": { "$regex": str(name_filter), "$options": "i" }}) total_count = len( list(toolsetdb.get_all_tool_set({"_id": { "$in": id_list }}))) if name_filter: skip = limit = 0 toolsets = toolsetdb.get_all_tool_set(filter_required, skip, limit) for record in toolsets: if (HelperServices.filter_handler(record, tags_filter, record.get("tag", []), "tag")): continue if len(toolName_filter) > 0: tool_list = [] for eachTool in record.get("tool_set"): if eachTool.get("tool_id"): tool_list.append(str(eachTool["tool_id"])) if tool_list and "any" not in toolName_filter: if toolName_filter and len(toolName_filter) > 0 and len( list(set(toolName_filter) & set(tool_list))) < 1: continue finalData.append(record) return jsonify( json.loads( dumps({ "result": "success", "data": { "data": finalData, "page": page, "total": total_count, "page_total": len(finalData) } }))), 200
def GetMachineGroups(): limit = int(request.args.get('perpage', "30")) page = int(request.args.get('page', "0")) skip = page * limit machine_group_name_filter = request.args.get('machine_group_name', None) machine_id_filter = request.args.get('machine_id_list', None) if not machine_id_filter or "any" in machine_id_filter: machine_id_filter = None else: machine_id_filter = machine_id_filter.split(",") if machine_group_name_filter: machine_group_name_filter = machine_group_name_filter.split(",") id_list = teamService.get_user_permissions( authService.get_userid_by_auth_token())["machine_group_id_list"] final_machine_group_list = [] for machine_group in machinegroupsDB.get_all_machine_groups( {"_id": { "$in": id_list }}): if(HelperServices.filter_handler(machine_group, machine_id_filter,\ machine_group.get("machine_id_list",[]),"machine_id_list")): continue if machine_group_name_filter: if len([ f for f in machine_group_name_filter if re.compile(f.lower(), re.IGNORECASE).match( machine_group.get("group_name").lower()) ]) == 0: continue final_machine_group_list.append(machine_group) total_machine_groups = list( machinegroupsDB.get_all_machine_groups({"_id": { "$in": id_list }})) return jsonify(json.loads(dumps({"result": "success", "data":{"data": final_machine_group_list, "page": page,\ "total": len(total_machine_groups), "page_total": len(final_machine_group_list)} }))), 200
def get_all_states(): type_filter = [] approval_status_filter = [] parent_filter = [] du_filter = [] build_id_filter = [] state_name_filter = [] if request.args.get('type', None): type_filter = request.args.get('type', None).split(",") if "any" in type_filter: type_filter = None if request.args.get('build_id', None): build_id_filter = request.args.get('build_id', None).split(",") if "any" in build_id_filter: build_id_filter = None if request.args.get('name', None): state_name_filter = request.args.get('name', None).split(",") if "any" in state_name_filter: state_name_filter = None if request.args.get('approval_status', None): approval_status_filter = request.args.get('approval_status', None).split(",") if "any" in approval_status_filter: approval_status_filter = None if request.args.get('parent_entity_id', None): parent_filter = request.args.get('parent_entity_id', None).split(",") if "any" in parent_filter: parent_filter = None if request.args.get('du_id', None): du_filter = request.args.get('du_id', None).split(",") if "any" in du_filter: du_filter = None limit = int(request.args.get('perpage', "30")) page = int(request.args.get('page', "0")) skip = page * limit filter_req = {} if state_name_filter: list_of_names = [] for name in state_name_filter: list_of_names.append(re.compile(name, re.IGNORECASE)) filter_req.update({"name": {"$in": list_of_names}}) if build_id_filter: filter_req.update({"build_id": {"$in": build_id_filter}}) states = statedb.get_state_all(False, type_filter, parent_filter, skip, limit, filter_req) total_count_of_state_in_page = 0 total_count_of_state_in_db = len( list(statedb.get_state_all(False, type_filter))) final_data = [] for state in states: if (HelperServices.filter_handler(state, approval_status_filter, [state.get("approval_status")], "approval_status")): continue StateHelperService.get_names_from_ids(state, False) total_count_of_state_in_page += 1 if len(du_filter) > 0: for state_id in state["states"]: state_data = statedb.get_state_by_id(state_id, True) if state_data["parent_entity_id"] in du_filter: if state not in final_data: final_data.append(state) else: final_data.append(state) return jsonify( json.loads( dumps({ "result": "success", "data": { "data": final_data, "page": page, "total": total_count_of_state_in_db, "page_total": total_count_of_state_in_page } }))), 200
def getAllDeploymentUnitSets(): limit = int(request.args.get('perpage', '30')) page = int(request.args.get('page', "0")) skip = page * limit tags_filter = [] duName_filter = [] approval_status_filter = [] name_filter = None if request.args.get('tags', None): tags_filter = request.args.get('tags', None).split(",") if request.args.get('duname', None): duName_filter = request.args.get('duname', None).split(",") if request.args.get('approval_status', None): approval_status_filter = request.args.get('approval_status', None).split(",") id_list = teamService.get_user_permissions( authService.get_userid_by_auth_token())["parent_entity_set_id_list"] if request.args.get('name', None): name_filter = request.args.get('name', None) filter_required = {"_id": {"$in": id_list}} if name_filter: filter_required.update( {"name": re.compile(name_filter, re.IGNORECASE)}) deploymentUnitSets = deploymentUnitSetDB.GetAllDeploymentUnitSet( False, filter_required, skip, limit) # total_count=len(id_list) total_count = len( list( deploymentUnitSetDB.GetAllDeploymentUnitSet( False, {"_id": { "$in": id_list }}))) ###########GROUP by DeploymentUnitType############################# finalData = [] if len(tags_filter) > 0 or len(approval_status_filter) > 0 or len( duName_filter) > 0: for dus in deploymentUnitSets: #FILTER BY TAGS if len(tags_filter) > 0: if (HelperServices.filter_handler(dus, tags_filter, dus.get("tag", []), "tag")): continue #Filter by state approval status if len(approval_status_filter) > 0: approval_sts_of_states = [] for state in stateDB.get_state_by_parent_entity_id( str(dus["_id"]), True): if state.get("approval_status"): approval_sts_of_states.append( state.get("approval_status")) if(HelperServices.filter_handler({"approval_status":True},\ approval_status_filter,approval_sts_of_states , "approval_status")): continue if len(duName_filter) > 0: du_list = [] for eachTool in dus.get("du_set"): if eachTool.get("du_id"): du_list.append(eachTool["du_id"]) if du_list and "any" not in duName_filter: if duName_filter and len(duName_filter) > 0 and len( list(set(duName_filter) & set(du_list))) < 1: continue finalData.append(dus) return jsonify( json.loads( dumps({ "result": "success", "data": { "data": finalData, "page": page, "total": total_count, "page_total": len(finalData) } }))), 200 else: return jsonify( json.loads( dumps({ "result": "success", "data": { "data": list(deploymentUnitSets), "page": page, "total": total_count, "page_total": len(deploymentUnitSets) } }))), 200
def get_all_machines(): limit = int(request.args.get('perpage', "30")) page = int(request.args.get('page', "0")) skip = page * limit tags_filter = request.args.get('tags', None) if not tags_filter or "any" in tags_filter: tags_filter = None else: tags_filter = tags_filter.split(",") machine_type_filter = request.args.get('machine_type', None) if not machine_type_filter or "any" in machine_type_filter: machine_type_filter = None else: machine_type_filter = machine_type_filter.split(",") machine_name_filter = request.args.get('machine_name', None) if machine_name_filter: machine_name_filter = machine_name_filter.split(",") host_filter = request.args.get('host', "") machine_id_filter = request.args.get('machine_id_list', None) if not machine_id_filter or "any" in machine_id_filter: machine_id_filter = None else: machine_id_filter = machine_id_filter.split(",") id_list = teamService.get_user_permissions( authService.get_userid_by_auth_token())[ "machine_id_list"] # TOOL SET IDS machines = list(machineDB.GetMachines({"_id": {"$in": id_list},\ "host": {"$regex": str(host_filter), "$options": "i"}},skip,limit)) total_machines = list(machineDB.GetMachines({"_id": {"$in": id_list}})) user_id = authService.get_userid_by_auth_token() keys_to_keep = [ "username", "machine_name", "host", "status", "_id", "machine_type", "flexible_attributes" ] final_list_of_machines = [] for index, machine in enumerate(machines): #FILTER BY TAGS if (HelperServices.filter_handler( machine, tags_filter, tagDB.get_tag_names_from_given_ids_list(machine.get("tag", [])), "tag")): continue if machine_type_filter and machineTypeDb.get_machine_type_by_id( machine.get("machine_type")).get( "type") not in machine_type_filter: continue if machine_name_filter: if len([ f for f in machine_name_filter if re.compile(f.lower(), re.IGNORECASE).match( machine.get("machine_name").lower()) ]) == 0: continue if machine_id_filter: if len( [f for f in machine_id_filter if f in str(machine.get("_id"))]) == 0: continue machines[index] = machineDB.decrypt(machine) # DECRYPT PASSWORDS for key in machines[index].keys(): if key not in keys_to_keep: machine.pop(key) fav_machine = machineFavDb.get_user_favorite_machine_by_machine_id_and_user_id( str(machines[index].get("_id")), user_id) if machines[index].get("machine_type"): machine_type = machineTypeDb.get_machine_type_by_id( machines[index]["machine_type"]) if machines[index]: machines[index]["machine_type"] = machine_type["type"] final_list_of_machines.append(machine) return jsonify( json.loads( dumps({ "result": "success", "data": { "data": final_list_of_machines, "page": page, "total": len(total_machines), "page_total": len(final_list_of_machines) } }))), 200
def getAllDeploymentUnits(): id_list = teamService.get_user_permissions( authService.get_userid_by_auth_token())[ "parent_entity_id_list"] # TOOL SET IDS # total_count=len(id_list) status_filter = request.args.get('status', None) tags_filter = [] duSet_filter = [] duName_filter = [] approval_status_filter = [] deployment_unit_type_filter = [] total_count_of_du_in_page = 0 limit = int(request.args.get('perpage', "30")) page = int(request.args.get('page', "0")) skip = page * limit if request.args.get('tags', None): tags_filter = request.args.get('tags').split(",") if request.args.get('duset', None): duSet_filter = request.args.get('duset', None).split(",") if not status_filter: status_filter = ['1'] elif not status_filter or "any" in status_filter: status_filter = None else: status_filter = status_filter.split(",") if request.args.get('type', None): deployment_unit_type_filter = request.args.get('type', None) if not deployment_unit_type_filter or "any" in deployment_unit_type_filter: deployment_unit_type_filter = None else: deployment_unit_type_filter = deployment_unit_type_filter.split(",") if request.args.get('approval_status', None): approval_status_filter = request.args.get('approval_status', None).split(",") if request.args.get('duname', None): duName_filter = request.args.get('duname', None) if duName_filter: deploymentUnits = deploymentUnitDB.GetAllDeploymentUnits( status_filter, deployment_unit_type_filter, False, { "$and": [{ "_id": { "$in": id_list } }, { "name": re.compile(duName_filter, re.IGNORECASE) }] }, 0, 0, True) else: deploymentUnits = deploymentUnitDB.GetAllDeploymentUnits( status_filter, deployment_unit_type_filter, False, {"_id": { "$in": id_list }}, skip, limit, True) total_count_of_du_in_db = len( list( deploymentUnitDB.GetAllDeploymentUnits(status_filter, None, False, {"_id": { "$in": id_list }}))) ###########GROUP by DeploymentUnitType############################# duJsonObj = {} du_list = [] for du in deploymentUnits: #FILTER BY TAGS if (HelperServices.filter_handler(du, tags_filter, du.get("tag", []), "tag")): continue #Filter by state approval status if approval_status_filter: approval_sts_of_states = [] for state in stateDB.get_state_by_parent_entity_id( str(du["_id"]), True): if state.get("approval_status"): approval_sts_of_states.append(state.get("approval_status")) if(HelperServices.filter_handler({"approval_status":True},\ approval_status_filter,approval_sts_of_states,"approval_status")): continue if duSet_filter: included_in_du_set_names = [] for duSetdata in deploymentUnitSetDB.GetDeploymentUnitSetByCondition( "du_set.du_id", du["_id"]): if duSetdata.get("_id") or duSetdata("name") is not None: included_in_du_set_names.append(str(duSetdata.get("name"))) if "any" not in duSet_filter: if duSet_filter and len(duSet_filter) > 0 and len( list( set(duSet_filter) & set(included_in_du_set_names))) < 1: continue # Latest BUILD NUMBER and BUILD TYPE latest_build_details = buildDB.get_last_active_build(str(du["_id"])) if latest_build_details: du["build_number"] = latest_build_details.get("build_number") du["build_id"] = str(latest_build_details.get("_id")) # ADD GROUPS HERE if du.get("type") in duJsonObj.keys(): duJsonObj[du.get("type")].append(du) else: duJsonObj[du.get("type")] = [] duJsonObj[du.get("type")].append(du) total_count_of_du_in_page += 1 for keytype in duJsonObj.keys(): dutype = {} dutype["type"] = keytype dutype["data"] = duJsonObj.get(keytype) du_list.append(dutype) return jsonify(json.loads(dumps({"result": "success", "data":\ {"data": du_list, "page": page, "total": total_count_of_du_in_db, "page_total": total_count_of_du_in_page}}))), 200