def login(): username = request.form.get('username') password = request.form.get('password') password = tool_pass.md5encrypt(password) sql = "select * from user where username = %s and password = %s" result = tool_db.selectByParameters(sql, (username, password)) if result: session['username'] = username return redirect('/views/servers') else: return redirect("/static/login.html")
def get_by_page(): info = request.get_data() info = json.loads(info) pagenow = info['pagenow'] pagesize = info['pagesize'] search = info['search'] search = "%{0}%".format(search) sql = 'select * from deploy where name like %s limit %s,%s' params = (search, (pagenow - 1) * pagesize, pagesize) result = tool_db.selectByParameters(sql, params=params) return json.dumps(result)
def deploy_by_id(): id = int(request.args.get('id')) sql = "select * from deploy where id = %s" result = tool_db.selectByParameters(sql, params=(id, ))[0] tmpnumber = int(time.time() * 1000) # name, hosts_path, hosts_pattern, module, args, forks runcommand = """ /usr/local/python/bin/ansible -i {0} {1} -m {2} -a '{3}' -f {4} """.format( result['hosts_path'], result['hosts_pattern'], result['module'], result['args'], result['forks']) command = """ /usr/local/python/bin/ansible -i {0} {1} -m {2} -a '{3}' -f {4} >static/logs/{5} 2>&1; printf '\n\t\t\t' >>static/logs/{6} """.format( result['hosts_path'], result['hosts_pattern'], result['module'], result['args'], result['forks'], tmpnumber, tmpnumber) t1 = threading.Thread(target=shellRun, args=(command, )) t1.start() return json.dumps({"command": runcommand, "logpath": tmpnumber})
def deploy_by_id(): id = int(request.args.get('id')) sql = "select * from playbook where id = %s" result = tool_db.selectByParameters(sql, params=(id,))[0] tmpnumber = int(time.time() * 1000) # name, hosts_path, playbook_path, forks displaycommand = """ /usr/local/python/bin/ansible-playbook -i {0} {1} -f {2} """.format( result['hosts_path'], result['playbook_path'], result['forks'] ) command = """ /usr/local/python/bin/ansible-playbook -i {0} {1} -f {2} >static/logs/{3} 2>&1; printf '\n\t\t\t' >>static/logs/{4} """.format( result['hosts_path'], result['playbook_path'], result['forks'], tmpnumber, tmpnumber ) t1 = threading.Thread(target=shellRun, args=(command,)) t1.start() return json.dumps({"command": displaycommand, "logpath": tmpnumber})
def get_by_id(): id = int(request.args.get('id')) sql = "select * from deploy where id = %s" result = tool_db.selectByParameters(sql, params=(id, )) return json.dumps(result)