|
|
@ -1,4 +1,5 @@ |
|
|
|
import json |
|
|
|
import json |
|
|
|
|
|
|
|
import copy |
|
|
|
|
|
|
|
|
|
|
|
from django.http import JsonResponse |
|
|
|
from django.http import JsonResponse |
|
|
|
from django.db.models import Q |
|
|
|
from django.db.models import Q |
|
|
@ -21,6 +22,7 @@ from update.utils.git_util import GitUtil, GitDbUtil |
|
|
|
from update.utils.cmd_extcute import UpdateCommandUtil, UpdateConfigUtil |
|
|
|
from update.utils.cmd_extcute import UpdateCommandUtil, UpdateConfigUtil |
|
|
|
from update.utils.db_compare import DbCompare |
|
|
|
from update.utils.db_compare import DbCompare |
|
|
|
from update.utils.client_util import ClientUtil |
|
|
|
from update.utils.client_util import ClientUtil |
|
|
|
|
|
|
|
# from consumers import UpdateConsumer |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# CacheResponseMixin 一定要放第一位 |
|
|
|
# CacheResponseMixin 一定要放第一位 |
|
|
@ -90,6 +92,9 @@ def get_git_version(request): |
|
|
|
return JsonResponse(serializer.data, safe=False) |
|
|
|
return JsonResponse(serializer.data, safe=False) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cinema_update_status = dict() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_cine(request): |
|
|
|
def update_cine(request): |
|
|
|
req = request.GET.dict() |
|
|
|
req = request.GET.dict() |
|
|
|
cinema_ip = req.get('ip') |
|
|
|
cinema_ip = req.get('ip') |
|
|
@ -113,6 +118,8 @@ def update_cine(request): |
|
|
|
'client': {'result': '', 'msg': ''}, |
|
|
|
'client': {'result': '', 'msg': ''}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cinema_update_status[cinema_ip] = copy.deepcopy(update_status) |
|
|
|
|
|
|
|
|
|
|
|
short_release = req.get('version') |
|
|
|
short_release = req.get('version') |
|
|
|
cmd_list = json.loads(req.get('cmd')) |
|
|
|
cmd_list = json.loads(req.get('cmd')) |
|
|
|
print(cinema_ip, short_release, cmd_list) |
|
|
|
print(cinema_ip, short_release, cmd_list) |
|
|
@ -124,81 +131,87 @@ def update_cine(request): |
|
|
|
# 获取并写入cine.sql |
|
|
|
# 获取并写入cine.sql |
|
|
|
print('获取并写入cine.sql') |
|
|
|
print('获取并写入cine.sql') |
|
|
|
try: |
|
|
|
try: |
|
|
|
|
|
|
|
cinema_update_status[cinema_ip]['git']['result'] = 'running' |
|
|
|
git_util = GitUtil(short_release) |
|
|
|
git_util = GitUtil(short_release) |
|
|
|
git_output = git_util.handle_create_cine() |
|
|
|
git_output = git_util.handle_create_cine() |
|
|
|
update_status['git']['result'] = 'success' |
|
|
|
cinema_update_status[cinema_ip]['git']['result'] = 'success' |
|
|
|
update_status['git']['msg'] = git_output |
|
|
|
cinema_update_status[cinema_ip]['git']['msg'] = git_output |
|
|
|
except Exception as e: |
|
|
|
except Exception as e: |
|
|
|
print('git', e) |
|
|
|
print('git', e) |
|
|
|
update_status['git']['result'] = 'fail' |
|
|
|
cinema_update_status[cinema_ip]['git']['result'] = 'fail' |
|
|
|
update_status['git']['msg'] = str(e) |
|
|
|
cinema_update_status[cinema_ip]['git']['msg'] = str(e) |
|
|
|
|
|
|
|
|
|
|
|
# 执行setup |
|
|
|
# 执行setup |
|
|
|
print('执行setup') |
|
|
|
print('执行setup') |
|
|
|
try: |
|
|
|
try: |
|
|
|
|
|
|
|
cinema_update_status[cinema_ip]['setup']['result'] = 'running' |
|
|
|
setup_list = list(set(cmd_list) & set(cmd_dict['setup'])) |
|
|
|
setup_list = list(set(cmd_list) & set(cmd_dict['setup'])) |
|
|
|
update_cmd = UpdateCommandUtil() |
|
|
|
update_cmd = UpdateCommandUtil() |
|
|
|
setup_output = update_cmd.exec_cmd_by_type(cinema_ip, 'setup', setup_list, short_release) |
|
|
|
setup_output = update_cmd.exec_cmd_by_type(cinema_ip, 'setup', setup_list, short_release) |
|
|
|
update_status['setup']['result'] = 'success' |
|
|
|
cinema_update_status[cinema_ip]['setup']['result'] = 'success' |
|
|
|
update_status['setup']['msg'] = setup_output |
|
|
|
cinema_update_status[cinema_ip]['setup']['msg'] = setup_output |
|
|
|
except Exception as e: |
|
|
|
except Exception as e: |
|
|
|
print('setup', e) |
|
|
|
print('setup', e) |
|
|
|
update_status['setup']['result'] = 'fail' |
|
|
|
cinema_update_status[cinema_ip]['setup']['result'] = 'fail' |
|
|
|
update_status['setup']['msg'] = str(e) |
|
|
|
cinema_update_status[cinema_ip]['setup']['msg'] = str(e) |
|
|
|
|
|
|
|
|
|
|
|
# 数据库对比 |
|
|
|
# 数据库对比 |
|
|
|
sql_list = list(set(cmd_list) & set(cmd_dict['sql'])) |
|
|
|
sql_list = list(set(cmd_list) & set(cmd_dict['sql'])) |
|
|
|
if len(sql_list) > 0: |
|
|
|
if len(sql_list) > 0: |
|
|
|
print('数据库对比') |
|
|
|
print('数据库对比') |
|
|
|
try: |
|
|
|
try: |
|
|
|
|
|
|
|
cinema_update_status[cinema_ip]['sql']['result'] = 'running' |
|
|
|
db_compare = DbCompare(cinema_ip, short_release) |
|
|
|
db_compare = DbCompare(cinema_ip, short_release) |
|
|
|
sql_output = db_compare.exec_diff_sql() |
|
|
|
sql_output = db_compare.exec_diff_sql() |
|
|
|
update_status['sql']['result'] = 'success' |
|
|
|
cinema_update_status[cinema_ip]['sql']['result'] = 'success' |
|
|
|
update_status['sql']['msg'] = sql_output |
|
|
|
cinema_update_status[cinema_ip]['sql']['msg'] = sql_output |
|
|
|
except Exception as e: |
|
|
|
except Exception as e: |
|
|
|
print('sql', e) |
|
|
|
print('sql', e) |
|
|
|
update_status['sql']['result'] = 'fail' |
|
|
|
cinema_update_status[cinema_ip]['sql']['result'] = 'fail' |
|
|
|
update_status['sql']['msg'] = str(e) |
|
|
|
cinema_update_status[cinema_ip]['sql']['msg'] = str(e) |
|
|
|
|
|
|
|
|
|
|
|
# 修改设置 |
|
|
|
# 修改设置 |
|
|
|
print('执行config(teardown前)') |
|
|
|
print('执行config(teardown前)') |
|
|
|
try: |
|
|
|
try: |
|
|
|
|
|
|
|
cinema_update_status[cinema_ip]['config']['result'] = 'running' |
|
|
|
config_list = list(set(cmd_list) & set(cmd_dict['config'])) |
|
|
|
config_list = list(set(cmd_list) & set(cmd_dict['config'])) |
|
|
|
update_config = UpdateConfigUtil(cinema_ip, config_list, True) |
|
|
|
update_config = UpdateConfigUtil(cinema_ip, config_list, True) |
|
|
|
config_before_output = update_config.exec_config() |
|
|
|
config_before_output = update_config.exec_config() |
|
|
|
update_status['config']['result'] = 'success' |
|
|
|
cinema_update_status[cinema_ip]['config']['result'] = 'success' |
|
|
|
update_status['config']['msg'] = config_before_output |
|
|
|
cinema_update_status[cinema_ip]['config']['msg'] = config_before_output |
|
|
|
except Exception as e: |
|
|
|
except Exception as e: |
|
|
|
print('config', e) |
|
|
|
print('config', e) |
|
|
|
update_status['config']['result'] = 'fail' |
|
|
|
cinema_update_status[cinema_ip]['config']['result'] = 'fail' |
|
|
|
update_status['config']['msg'] = str(e) |
|
|
|
cinema_update_status[cinema_ip]['config']['msg'] = str(e) |
|
|
|
|
|
|
|
|
|
|
|
# 执行teardown |
|
|
|
# 执行teardown |
|
|
|
teardown_list = list(set(cmd_list) & set(cmd_dict['teardown'])) |
|
|
|
teardown_list = list(set(cmd_list) & set(cmd_dict['teardown'])) |
|
|
|
if len(teardown_list) > 0: |
|
|
|
if len(teardown_list) > 0: |
|
|
|
print('执行teardown') |
|
|
|
print('执行teardown') |
|
|
|
try: |
|
|
|
try: |
|
|
|
|
|
|
|
cinema_update_status[cinema_ip]['teardown']['result'] = 'running' |
|
|
|
update_cmd = UpdateCommandUtil() |
|
|
|
update_cmd = UpdateCommandUtil() |
|
|
|
teardown_output = update_cmd.exec_cmd_by_type(cinema_ip, 'teardown', teardown_list, short_release) |
|
|
|
teardown_output = update_cmd.exec_cmd_by_type(cinema_ip, 'teardown', teardown_list, short_release) |
|
|
|
update_status['teardown']['result'] = 'success' |
|
|
|
cinema_update_status[cinema_ip]['teardown']['result'] = 'success' |
|
|
|
update_status['teardown']['msg'] = '执行升级脚本:执行成功' |
|
|
|
cinema_update_status[cinema_ip]['teardown']['msg'] = '执行升级脚本:执行成功' |
|
|
|
except Exception as e: |
|
|
|
except Exception as e: |
|
|
|
print('teardown', e) |
|
|
|
print('teardown', e) |
|
|
|
update_status['teardown']['result'] = 'fail' |
|
|
|
cinema_update_status[cinema_ip]['teardown']['result'] = 'fail' |
|
|
|
update_status['teardown']['msg'] = str(e) |
|
|
|
cinema_update_status[cinema_ip]['teardown']['msg'] = str(e) |
|
|
|
|
|
|
|
|
|
|
|
# 修改设置 |
|
|
|
# 修改设置 |
|
|
|
print('执行config(teardown后)') |
|
|
|
print('执行config(teardown后)') |
|
|
|
try: |
|
|
|
try: |
|
|
|
|
|
|
|
cinema_update_status[cinema_ip]['config']['result'] = 'running' |
|
|
|
config_list = list(set(cmd_list) & set(cmd_dict['config'])) |
|
|
|
config_list = list(set(cmd_list) & set(cmd_dict['config'])) |
|
|
|
update_config = UpdateConfigUtil(cinema_ip, config_list, False) |
|
|
|
update_config = UpdateConfigUtil(cinema_ip, config_list, False) |
|
|
|
config_after_output = update_config.exec_config() |
|
|
|
config_after_output = update_config.exec_config() |
|
|
|
update_status['config']['result'] = 'success' |
|
|
|
cinema_update_status[cinema_ip]['config']['result'] = 'success' |
|
|
|
update_status['config']['msg'] = update_status['config']['msg'] + '\n' + config_after_output |
|
|
|
cinema_update_status[cinema_ip]['config']['msg'] = update_status['config']['msg'] + '\n' + config_after_output |
|
|
|
except Exception as e: |
|
|
|
except Exception as e: |
|
|
|
print('config', e) |
|
|
|
print('config', e) |
|
|
|
update_status['config']['result'] = 'fail' |
|
|
|
cinema_update_status[cinema_ip]['config']['result'] = 'fail' |
|
|
|
update_status['config']['msg'] = update_status['config']['msg'] + '\n' + str(e) |
|
|
|
cinema_update_status[cinema_ip]['config']['msg'] = update_status['config']['msg'] + '\n' + str(e) |
|
|
|
|
|
|
|
|
|
|
|
# 传输客户端 |
|
|
|
# 传输客户端 |
|
|
|
client_list = list(set(cmd_list) & set(cmd_dict['client'])) |
|
|
|
client_list = list(set(cmd_list) & set(cmd_dict['client'])) |
|
|
@ -207,14 +220,14 @@ def update_cine(request): |
|
|
|
try: |
|
|
|
try: |
|
|
|
client_release = ClientUtil() |
|
|
|
client_release = ClientUtil() |
|
|
|
client_release.client_process(cinema_ip, short_release) |
|
|
|
client_release.client_process(cinema_ip, short_release) |
|
|
|
update_status['client']['result'] = 'success' |
|
|
|
cinema_update_status[cinema_ip]['client']['result'] = 'success' |
|
|
|
update_status['client']['msg'] = '客户端上传成功' |
|
|
|
cinema_update_status[cinema_ip]['client']['msg'] = '客户端上传成功' |
|
|
|
except Exception as e: |
|
|
|
except Exception as e: |
|
|
|
print('client', e) |
|
|
|
print('client', e) |
|
|
|
update_status['client']['result'] = 'fail' |
|
|
|
cinema_update_status[cinema_ip]['client']['result'] = 'fail' |
|
|
|
update_status['client']['msg'] = str(e) |
|
|
|
cinema_update_status[cinema_ip]['client']['msg'] = str(e) |
|
|
|
|
|
|
|
|
|
|
|
print(update_status) |
|
|
|
print(cinema_update_status[cinema_ip]) |
|
|
|
return JsonResponse({'result': 'success', 'ip': cinema_ip}) |
|
|
|
return JsonResponse({'result': 'success', 'ip': cinema_ip}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|