增加记录版本变化的功能

main
RogerWork 8 months ago
parent 4250fc3457
commit 737c50127d
  1. 22
      update/models.py
  2. 8
      update/serializers.py
  3. 17
      update/utils/get_version.py
  4. 6
      update/views.py

@ -139,3 +139,25 @@ class UpdateAlter(BaseModels):
verbose_name = 'alter'
verbose_name_plural = 'alter'
db_table = 'update_alter'
class UpdateLog(BaseModels):
"""
记录升级日志
"""
id = models.AutoField(primary_key=True)
ip = models.CharField(verbose_name='ip地址', max_length=20, null=False, help_text='ip地址')
type = models.CharField(verbose_name='触发类型', max_length=20, null=False, help_text='触发类型')
origin_ver = models.CharField(verbose_name='升级前版本', max_length=200, null=False, help_text='升级前版本')
target_ver = models.CharField(verbose_name='升级后版本', max_length=200, null=False, help_text='升级后版本')
time = models.DateTimeField(verbose_name='操作时间', help_text='操作时间')
result = models.CharField(verbose_name='升级结果', max_length=20, null=False, help_text='升级结果')
result_detail = models.TextField(verbose_name='升级结果详情', null=False, help_text='升级结果详情')
def __str__(self):
return self.ip
class Meta:
verbose_name = '升级日志'
verbose_name_plural = '升级日志'
db_table = 'update_log'

@ -50,3 +50,11 @@ class UpdateAlterSerializer(serializers.ModelSerializer):
class Meta:
model = UpdateAlter
fields = ('id', 'ver_id', 'alter', 'update_time')
class UpdateLogSerializer(serializers.ModelSerializer):
time = serializers.DateTimeField(format='%Y-%m-%d %H:%M:%S')
class Meta:
model = UpdateLog
fields = ('id', 'ip', 'type', 'origin_ver', 'target_ver', 'time', 'result', 'result_detail')

@ -80,6 +80,23 @@ class GetVersion(object):
cinema_obj = Cinema.objects.filter(ip=ip).update(**update_data)
def get_cinema_ver_by_ip(ip):
sql_str = "SELECT cv.server_version FROM cinema_version cv ON 1=1;"
db_config = {
'host': ip,
'user': Cinema.objects.get(ip=ip).db_user,
'password': Cinema.objects.get(ip=ip).db_pwd,
'database': 'cine',
'connect_timeout': 5,
}
print(db_config)
db_conn = pymysql.Connect(**db_config)
db_cursor = db_conn.cursor(cursor=DictCursor)
db_cursor.execute(sql_str)
res = db_cursor.fetchone()
return res.get('server_version')
if __name__ == '__main__':
v = GetVersion()
v.get_all_cinema()

@ -16,7 +16,7 @@ from django.views.decorators.cache import cache_page
from django.views.decorators.csrf import csrf_exempt
from django_filters.rest_framework import DjangoFilterBackend
from django.core.cache import cache
from update.utils.get_version import GetVersion
from update.utils.get_version import GetVersion, get_cinema_ver_by_ip
from rest_framework.decorators import action
from update.utils.git_util import GitUtil, GitDbUtil
from update.utils.cmd_extcute import UpdateCommandUtil, UpdateConfigUtil
@ -105,6 +105,10 @@ def get_git_version(request):
def update_cine(request):
req = request.GET.dict()
cinema_ip = req.get('ip')
# 获取当前版本
org_ver = get_cinema_ver_by_ip(ip=cinema_ip)
# 处理命令格式
cmd_dict = {}
cmd_obj = UpdateCommand.objects.filter(is_sys=0).values('id', 'process')

Loading…
Cancel
Save