def request_profiles(): """ Create a profile for the workload as it is run over each of the specified instance types. """ config_file = "profiler.ini" if request.method == "POST": description = request.form["description"] workload = request.form["workload"] working_dir = request.form["working_dir"] job_desc = json.loads(description) # Create an entry in the db for each job db_jobs = {} inst_params = {} db_manager = DBManager() db_manager.update_workload_dir(workload, working_dir, None) try: for inst in job_desc["instance_types"]: instance_type = inst["type"] job_id = db_manager.insert_job(workload) db_jobs.update({instance_type: job_id}) inst_params.update({instance_type: inst["override"]}) except Exception, e: print "Error with job creation %s" % e # While we are at it, set the executable to execuable submit_line = "chmod 777 %s%s" % (working_dir, job_desc["executable"].split("/")[-1]) submit = subprocess.Popen( (["sudo", "su", "root", "-c", submit_line]), stdout=subprocess.PIPE, stderr=subprocess.STDOUT ) s_out, s_err = submit.communicate() # Now start a thread for each of these jobs try: for inst, job_id in db_jobs.iteritems(): instance_type = inst params = inst_params[instance_type] profiler_thread = ProfilerJobThread(config_file, job_id, inst, params, job_desc) profiler_thread.start() except Exception, e: print "Error with a thread %s" % e