def stop_cluster(cl_args):
Log.info("<STR_LIT>")<EOL>roles = read_and_parse_roles(cl_args)<EOL>masters = roles[Role.MASTERS]<EOL>slaves = roles[Role.SLAVES]<EOL>dist_nodes = masters.union(slaves)<EOL>if masters:<EOL><INDENT>try:<EOL><INDENT>single_master = list(masters)[<NUM_LIT:0>]<EOL>jobs = get_jobs(cl_args, single_master)<EOL>for job in jobs:<EOL><INDENT>job_id = job["<STR_LIT>"]<EOL>Log.info("<STR_LIT>" % job_id)<EOL>delete_job(cl_args, job_id, single_master)<EOL><DEDENT><DEDENT>except:<EOL><INDENT>Log.debug("<STR_LIT>")<EOL>Log.debug(sys.exc_info()[<NUM_LIT:0>])<EOL><DEDENT><DEDENT>for node in dist_nodes:<EOL><INDENT>Log.info("<STR_LIT>" % node)<EOL>if not is_self(node):<EOL><INDENT>cmd = "<STR_LIT>""<STR_LIT>"<EOL>cmd = ssh_remote_execute(cmd, node, cl_args)<EOL><DEDENT>else:<EOL><INDENT>cmd = "<STR_LIT>""<STR_LIT>"<EOL><DEDENT>Log.debug(cmd)<EOL>pid = subprocess.Popen(cmd,<EOL>shell=True,<EOL>stdout=subprocess.PIPE,<EOL>stderr=subprocess.PIPE)<EOL>return_code = pid.wait()<EOL>output = pid.communicate()<EOL>Log.debug("<STR_LIT>" % (return_code, output))<EOL>Log.info("<STR_LIT>" % node)<EOL>cmd = "<STR_LIT>"<EOL>if not is_self(node):<EOL><INDENT>cmd = ssh_remote_execute(cmd, node, cl_args)<EOL><DEDENT>Log.debug(cmd)<EOL>pid = subprocess.Popen(cmd,<EOL>shell=True,<EOL>stdout=subprocess.PIPE,<EOL>stderr=subprocess.PIPE)<EOL>return_code = pid.wait()<EOL>output = pid.communicate()<EOL>Log.debug("<STR_LIT>" % (return_code, output))<EOL><DEDENT>
teardown the cluster