def salt_module_name(): try: private_module=Module.objects.filter(private_status=False) module_list=[{"name":x.name,"describe":x.describe} for x in private_module] result=get_result(0,module_list) except Exception,e: result=get_result(1,e.message)
def handle(host,module_name,arg): try: host_contain=host+'#' host_detail=Minion.objects.filter(ip__contains=host_contain) if len(host_detail)==0: return get_result(1,'no this ip %s' %host) raise NameError host_name=host_detail[0].name try: salt_name=Module.objects.get(name=module_name).salt_name Log.objects.create(host=host, module=module_name, arg=str(arg), action='start') result=func(host_name,salt_name,arg) if result['retcode']==0: host_result=result['stdout'][host_name] result['stdout']={ host:host_result } Log.objects.create(host=host, module=module_name, arg=str(arg), action='end', result=str(result)) except Exception,e: result=get_result(1,e.message) except Exception,e: result=get_result(1,e.message)
def salt_key_delete(master_ip,host): try: minion=Minion.objects.get(name=host) minion_name=minion.name master=Master.objects.get(ip=master_ip) master_port=master.port master_token=master.token send_data={'host':minion_name} m_result=Salt_http().post(master_ip,master_port,master_token,'/key/delete',send_data) if m_result['retcode']==0: minion.master.remove(master) result=get_result(0,'all done') except Exception,e: result=get_result(1,e.message)
def get_result(): project_info = api.get_project() static_result, dynamic_result = api.get_result() return render_template('project_result.html', username=current_user.user_name, project_info=project_info, static_result=static_result, dynamic_result=dynamic_result)
def salt_key_accept(master,host): try: m_master=Master.objects.get(ip=master) master_ip=m_master.ip master_port=m_master.port master_token=m_master.token send_data={'host':host} result=Salt_http().post(master_ip,master_port,master_token,'/key/accept',send_data) if result['retcode']==0 and result['stdout']==host: kernel_data={ 'tgt':host, 'func':'grains.item', 'arg':('kernel',) } ip_data={ 'tgt':host, 'func':'network.ip_addrs', 'arg':() } kernel_result=Salt_http().post(master_ip,master_port,master_token,'/cmd',kernel_data) if kernel_result['retcode']==0: m_kernel=kernel_result['stdout'][host]['kernel'] else: m_kernel='none' ip_result=Salt_http().post(master_ip,master_port,master_token,'/cmd',ip_data) if ip_result['retcode']==0: m_ip='#'.join(ip_result['stdout'][host])+'#' else: m_ip='none' if len(Minion.objects.filter(name=host))==0: aa=Minion(ip=m_ip,kernel=m_kernel,name=host) aa.save() aa.master.add(m_master) else: aa_master=[x.ip for x in Minion.objects.get(name=host).master.all()] if master in aa_master: Minion.objects.filter(name=host).update(kernel=m_kernel,ip=m_ip) else: Minion.objects.get(name=host).master.add(m_master) result=get_result(0,'done') else: result=get_result(1,'failed') except Exception,e: result=get_result(1,e.message)
def salt_minion_init(master_ip,host): try: minion=Minion.objects.get(name=host) master=Master.objects.get(ip=master_ip) master_port=master.port master_token=master.token send_data={ 'tgt':host, 'func':'saltutil.sync_all', 'arg':() } # if minion.ip.lower()=='none': ip_data={ 'tgt':host, 'func':'network.ip_addrs', 'arg':() } ip_result=Salt_http().post(master_ip,master_port,master_token,'/cmd',ip_data) if ip_result['retcode']==0: m_ip='#'.join(ip_result['stdout'][host])+'#' else: m_ip='none' minion.ip=m_ip minion.save() if minion.kernel.lower()=='none': kernel_data={ 'tgt':host, 'func':'grains.item', 'arg':('kernel',) } kernel_result=Salt_http().post(master_ip,master_port,master_token,'/cmd',kernel_data) if kernel_result['retcode']==0: m_kernel=kernel_result['stdout'][host]['kernel'] else: m_kernel='none' minion.kernel=m_kernel minion.save() elif minion.kernel.lower()=='linux': pass elif minion.kernel.lower()=='windows': cp_data={ 'tgt':host, 'func':'cp.get_dir', 'arg':('salt://file/chardet', 'C:\\salt\\bin\\Lib',) } cp_result=Salt_http().post(master_ip,master_port,master_token,'/cmd',cp_data) else: pass m_result=Salt_http().post(master_ip,master_port,master_token,'/cmd',send_data) if m_result['retcode']==0: result=m_result else: result=m_result except Exception,e: result=get_result(1,e.message)
def model(): # Load the model payload = request.json input_features = api.preprocess_sentence(payload['conversation']) model = keras.models.load_model('model_FINAL.h5', compile = False) message ={'model name':'work', 'api ver':'1.0', 'predict result':str(api.get_result(model.predict(input_features))), } result = jsonify(message) return result
def model(): #----------------------------- TODO: reading user input json and extract sentence payload = request.json #----------------------------- #input_features = api.preprocess_sentence("다리가 진짜 아파요") input_features = api.preprocess_sentence(payload['conversation']) model = keras.models.load_model('model_FINAL.h5', compile=False) result = { 'model name': 'work', 'api ver': '1.0', 'predict result': str(api.get_result(model.predict(input_features))), } return jsonify(result)
def get_weather() -> str: while True: city_id = input('Input city id (q to quit): ') if city_id == 'q': break units = input('Input units (metric or imperial, default Kelvin): ') try: data = api.get_result(api.build_url(city_id, units)) if units == 'metric': output.get_output(data, 'C') elif units == 'imperial': output.get_output(data, 'F') else: output.get_output(data, 'K') except: print('Error')
def execution(): path_apikey = 'D:\\project_3\\project_3_mine\\apikey.txt' url_AV_api = 'https://www.alphavantage.co' symbol_stock = 'AAPL' date_start = '2020-02-15' date_end = '2020-02-19' command = 'TR <1.5 >0.5'.split() #Hello api_key = get_apikey(path_apikey) #Concatenate the variables to create a full valid url full_url = url_AV_api + '/query?function=TIME_SERIES_DAILY&symbol=' + symbol_stock + '&outputsize=full&apikey=' + api_key #Get dictionary-type object stock_dict = api.get_result(full_url) #Get all days from the start date to the end date date_range = get_date_range(date_start, date_end) #Store info of selected stock into new dictionary. selected_dict = get_dict_in_range(date_range, stock_dict) #Extract days in the dict for ease usage stock_date_list = list(selected_dict.keys()) selected_dict = analysis(command, selected_dict, stock_date_list) report(symbol_stock, selected_dict, stock_date_list)
def application(environ, start_response): print("Recieved") try: request_body_size = int(environ.get('CONTENT_LENGTH', 0)) except (ValueError): request_body_size = 0 try: request_body = environ['wsgi.input'].read(request_body_size) # print(request_body) img = base64_to_image(request_body) res = get_result(img) except Exception as e: res = "Error" print(e) traceback.print_exc() print("Result:", res) start_response('200 OK', [('Content-Type', 'application/json')]) return [json.dumps(res).encode("utf-8")]
from api import get_result import os import shutil from glob import glob from PIL import Image if __name__ == '__main__': image_files = glob('./test_images/*.*') result_dir = './test_results' if os.path.exists(result_dir): shutil.rmtree(result_dir) os.mkdir(result_dir) txt_file = os.path.join(result_dir, 'result.txt') txt_f = open(txt_file, 'w') for image_file in sorted(image_files): if ".gitkeep" in image_files: continue print("Finded file", image_file, end=" ") result = get_result(Image.open(image_file)) print(":", result) txt_f.write(image_file.split('/')[-1].split('.')[0] + ':' + result + '\n') txt_f.close()
def GetResult(self, request, context): response = operator_pb2.Resp() data = api.get_result(request.u_id) response.data = data['data'] response.code = data['code'] return response