时间:2020-02-20来源:系统城作者:电脑系统城
from flask import Flask
from flask import request, Response
app = Flask(__name__)
import os
def getApolloconf(k):
import requests
env = os.environ.get("RUNTIME_ENV") or "dev"
getApolloconfig = requests.get(
'http://configserver-{env}.chj.cloud/configs/op-bmc-api/default/application'.format(env=env))
data = getApolloconfig.json()["configurations"]
return data.get(k)
#######获取配置插入数据库#########
def mysqlConfig(sql):
import pymysql
import json
USERNAME = getApolloconf("USERNAME")
PASSWORD = getApolloconf("PASSWORD")
HOST = getApolloconf("HOST")
DATABASE = getApolloconf("NGINXDATABASE")
dbconfig = pymysql.connect(HOST, USERNAME, PASSWORD, DATABASE)
try:
cursor = dbconfig.cursor()
try:
cursor.execute(sql)
results = cursor.fetchall()
reultData=[]
columnList=["run_type","upstreamname","front_listen","domain_name","backend_ip"]
for row in results:
reultData.append(dict(zip(columnList, list(row))))
str1=(json.dumps(reultData, ensure_ascii=False))
return str1
except Exception as e:
pass
except Exception as err:
print(err)
def nginxtbale():
try:
sql = "select run_type,upstreamname,front_listen,domain_name,backend_ip from nginxManager_dj_nginx_conf order by create_time"
return mysqlConfig(sql)
except Exception as e:
# 如果发生错误则回滚
print(e)
@app.route('/')
def index():
import json
return Response(json.dumps(nginxtbale()), mimetype='application/json')
if __name__ == '__main__':
app.run(
host="192.168.1.1",
port=8008,
debug=True
)
完成接口执行效果如下:
2023-10-30
windows上的mysql服务突然消失提示10061 Unkonwn error问题及解决方案2023-10-30
MySQL非常重要的日志bin log详解2023-10-30
详解MySQL事务日志redo log一、单表查询 1、排序 2、聚合函数 3、分组 4、limit 二、SQL约束 1、主键约束 2、非空约束 3、唯一约束 4、外键约束 5、默认值 三、多表查询 1、内连接 1)隐式内连接: 2)显式内连接: 2、外连接 1)左外连接 2)右外连接 四...
2023-10-30
Mysql删除表重复数据 表里存在唯一主键 没有主键时删除重复数据 Mysql删除表中重复数据并保留一条 准备一张表 用的是mysql8 大家自行更改 创建表并添加四条相同的数据...
2023-10-30