Commit 5232a74f authored by 金凯强's avatar 金凯强 🎨

车间为空报错

nginx配置修改接口
parent 20d69347
Pipeline #22266 failed with stage
in 11 seconds
......@@ -215,7 +215,7 @@ values
id = json_data.get('id')
project_no = json_data.get('project_no')
work_shop_no = json_data.get('work_shop_no', '')
work_shop_no = json_data.get('work_shop_no', '').strip()
db_ip = json_data.get('db_ip')
db_port = json_data.get('db_port')
db_user = json_data.get('db_user')
......@@ -223,7 +223,7 @@ values
mes_db_name = json_data.get('mes_db_name')
if project_no is None or db_ip is None or db_port is None or \
db_user is None or db_password is None or mes_db_name is None or work_shop_no is None:
db_user is None or db_password is None or mes_db_name is None or not work_shop_no:
raise HSException('以上参数全部必填')
project_no = project_no.strip()
......
......@@ -33,6 +33,17 @@ class InfoAPI(ApiController):
args = request.args
return InfoService().get_upgrade_log(args)
@api('nginx_conf')
def post_nginx(self):
'''
同步nginx配置文件
:return:
'''
json_data = request.get_json()
nginx_conf = json_data.get('data')
file_name = json_data.get('file_name')
return InfoService().sync_nginx(file_name, nginx_conf)
@api('upgrade_log_dtl/<int:log_id>')
def get_upgrade_log_dtl(self, log_id):
'''
......
......@@ -13,7 +13,7 @@ import docker
from app.conncetion.conncetion_service import ConnectionService
from app.utils.db_tools import db_driver
from static_file import builds_dir, back_up_dir
from static_file import builds_dir, back_up_dir, base_dir
# docker_client = docker.APIClient(base_url='tcp://localhost:2375')
docker_client = docker.APIClient(base_url='unix:///var/run/docker.sock')
......@@ -221,10 +221,32 @@ where A.log_id={log_id}'''
since_time = None
tail = '200'
logs = docker_client.logs('test', tail=tail, since=since_time) # todo 测试用的,以后改为install_api
logs = docker_client.logs('test', tail=tail, since=since_time) # todo 测试用的,以后改为install_api
if isinstance(logs, bytes):
logs = logs.decode()
# 去除所有含有debug信息的日志
filtered_logs = re.sub('(\[20.*-.*DEBUG.*\\n)', '', logs)
return filtered_logs
def sync_nginx(self, file_name, nginx_conf):
'''
同步nginx的配置文件
:param nginx_conf:
:return:
'''
if not nginx_conf:
return
base_folder_path = os.path.join(base_dir, 'conf')
if not os.path.exists(base_folder_path):
os.mkdir(os.path.join(base_dir, 'conf'))
folder_path = os.path.join(base_folder_path, 'nginx')
if not os.path.exists(folder_path):
os.mkdir(folder_path)
file_path = os.path.join(folder_path, file_name)
with open(file_path, 'w', encoding='utf-8') as f:
f.write(nginx_conf)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment