增加手动升级的日志记录功能

main
RogerWork 8 months ago
parent 737c50127d
commit 3050ddf632
  1. 32
      update/migrations/0026_updatelog.py
  2. 2
      update/utils/get_version.py
  3. 28
      update/views.py

@ -0,0 +1,32 @@
# Generated by Django 4.2.7 on 2024-03-18 02:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('update', '0025_alter_updatealter_alter'),
]
operations = [
migrations.CreateModel(
name='UpdateLog',
fields=[
('update_time', models.DateTimeField(auto_now=True, help_text='最后更新时间', verbose_name='最后更新时间')),
('id', models.AutoField(primary_key=True, serialize=False)),
('ip', models.CharField(help_text='ip地址', max_length=20, verbose_name='ip地址')),
('type', models.CharField(help_text='触发类型', max_length=20, verbose_name='触发类型')),
('origin_ver', models.CharField(help_text='升级前版本', max_length=200, verbose_name='升级前版本')),
('target_ver', models.CharField(help_text='升级后版本', max_length=200, verbose_name='升级后版本')),
('time', models.DateTimeField(help_text='操作时间', verbose_name='操作时间')),
('result', models.CharField(help_text='升级结果', max_length=20, verbose_name='升级结果')),
('result_detail', models.TextField(help_text='升级结果详情', verbose_name='升级结果详情')),
],
options={
'verbose_name': '升级日志',
'verbose_name_plural': '升级日志',
'db_table': 'update_log',
},
),
]

@ -81,7 +81,7 @@ class GetVersion(object):
def get_cinema_ver_by_ip(ip):
sql_str = "SELECT cv.server_version FROM cinema_version cv ON 1=1;"
sql_str = "SELECT cv.server_version FROM cinema_version cv WHERE 1=1;"
db_config = {
'host': ip,
'user': Cinema.objects.get(ip=ip).db_user,

@ -1,3 +1,4 @@
import datetime
import json
import copy
@ -22,6 +23,7 @@ from update.utils.git_util import GitUtil, GitDbUtil
from update.utils.cmd_extcute import UpdateCommandUtil, UpdateConfigUtil
from update.utils.db_compare import DbCompare
from update.utils.client_util import ClientUtil
from django.utils import timezone
# from consumers import UpdateConsumer
@ -108,6 +110,7 @@ def update_cine(request):
# 获取当前版本
org_ver = get_cinema_ver_by_ip(ip=cinema_ip)
update_time = timezone.now()
# 处理命令格式
cmd_dict = {}
@ -180,6 +183,9 @@ def update_cine(request):
update_status['git']['msg'] = str(e)
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60)
# redis_conn.delete(redis_key)
UpdateLog.objects.create(ip=cinema_ip, type='toolbox', origin_ver=org_ver, target_ver=short_release,
time=update_time, result=update_status['result'],
result_detail=json.dumps(update_status))
return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)})
# 执行setup
@ -203,6 +209,9 @@ def update_cine(request):
update_status['setup']['msg'] = str(e)
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60)
# redis_conn.delete(redis_key)
UpdateLog.objects.create(ip=cinema_ip, type='toolbox', origin_ver=org_ver, target_ver=short_release,
time=update_time, result=update_status['result'],
result_detail=json.dumps(update_status))
return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)})
# 数据库对比
@ -224,6 +233,9 @@ def update_cine(request):
update_status['sql']['msg'] = str(e)
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60)
# redis_conn.delete(redis_key)
UpdateLog.objects.create(ip=cinema_ip, type='toolbox', origin_ver=org_ver, target_ver=short_release,
time=update_time, result=update_status['result'],
result_detail=json.dumps(update_status))
return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)})
# 修改设置
@ -244,6 +256,9 @@ def update_cine(request):
update_status['config']['msg'] = str(e)
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60)
# redis_conn.delete(redis_key)
UpdateLog.objects.create(ip=cinema_ip, type='toolbox', origin_ver=org_ver, target_ver=short_release,
time=update_time, result=update_status['result'],
result_detail=json.dumps(update_status))
return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)})
# 执行teardown
@ -267,6 +282,9 @@ def update_cine(request):
update_status['teardown']['msg'] = str(e)
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60)
# redis_conn.delete(redis_key)
UpdateLog.objects.create(ip=cinema_ip, type='toolbox', origin_ver=org_ver, target_ver=short_release,
time=update_time, result=update_status['result'],
result_detail=json.dumps(update_status))
return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)})
# 修改设置
@ -287,6 +305,9 @@ def update_cine(request):
update_status['config']['msg'] = config_before_output + '<br/>' + str(e)
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60)
# redis_conn.delete(redis_key)
UpdateLog.objects.create(ip=cinema_ip, type='toolbox', origin_ver=org_ver, target_ver=short_release,
time=update_time, result=update_status['result'],
result_detail=json.dumps(update_status))
return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)})
# 传输客户端
@ -309,6 +330,9 @@ def update_cine(request):
update_status['client']['msg'] = str(e)
redis_conn.set(redis_key, json.dumps(update_status), 5 * 60)
# redis_conn.delete(redis_key)
UpdateLog.objects.create(ip=cinema_ip, type='toolbox', origin_ver=org_ver, target_ver=short_release,
time=update_time, result=update_status['result'],
result_detail=json.dumps(update_status))
return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)})
update_status['result'] = 'success'
@ -316,6 +340,10 @@ def update_cine(request):
print('update_status', update_status)
print('redis_get', redis_conn.get(redis_key))
print('update_time', update_time)
UpdateLog.objects.create(ip=cinema_ip, type='toolbox', origin_ver=org_ver, target_ver=short_release[:11],
time=update_time, result=update_status['result'], result_detail=json.dumps(update_status))
return JsonResponse({'result': 'success', 'ip': cinema_ip, 'msg': ''})

Loading…
Cancel
Save