def check_ansible(): request_data = request.json if request_data.get('party_id'): # TODO consider case that there are more than one records of specified party parties = JobSaver.query_party(party_id=request_data.get('party_id')) if parties: party_info = parties[0].to_json( filters=['modules', 'version', 'role']) modules = party_info.get('f_modules', {}).get('data', []) status = {} host = None for module in modules: if module.get('name') == 'supervisor': host = module.get('ips')[0] break if host: result = distribute_status_check_task(host=host) if result and result.get('list'): for item in result.get('list'): status[item['name']] = item['status'] if status: for module in modules: module['status'] = status.get(module['name'], None) return get_json_result(retmsg='Query party info successfully', data={ 'party_id': request_data.get('party_id'), 'list': modules, 'fate_version': party_info.get('f_version'), "role": party_info.get('f_role') }) return get_json_result( retcode=0, retmsg= f"can not found info party {request_data.get('party_id')} in database." ) return get_json_result(data={'status': 'success'})
def do_status_check(party_id, module_name=None): parties = JobSaver.query_party(party_id=party_id, reverse=True) if not parties: return 100, f"can not find info of party with party id {party_id}", {} else: party_info = parties[0].to_json(filters=['modules', 'version']) modules = party_info.get('f_modules', {}).get('data', []) for module in modules: if module.get('name') == 'supervisor': host = module.get('ips')[0] break else: return 100, f"can not found module supervisor on party {party_id}", {} if module_name: result = distribute_status_check_task(host=host, module_name=module_name) else: result = distribute_status_check_task(host=host) if result and result.get('list'): for item in result.get('list'): item.update({'version': party_info['f_version']}) result['version'] = party_info['f_version'] return 0, "check module status successfully", result return 100, "check module status failed, please check logs/ansible/ansible_stat.log", {}