2020-05-27 12:24:06 +00:00
|
|
|
import json
|
|
|
|
|
|
|
|
from django.conf import settings
|
2017-12-11 14:07:01 +00:00
|
|
|
from django.http import HttpResponse, HttpResponseRedirect
|
2020-05-27 12:24:06 +00:00
|
|
|
from django.shortcuts import render
|
2020-01-24 07:09:46 +00:00
|
|
|
from django.urls import reverse
|
2020-05-27 12:24:06 +00:00
|
|
|
|
|
|
|
from admin.decorators import superuser_only
|
2017-12-11 14:07:01 +00:00
|
|
|
from instances.models import Instance
|
2015-03-03 09:34:09 +00:00
|
|
|
from logs.models import Logs
|
|
|
|
|
|
|
|
|
2015-05-18 19:00:30 +00:00
|
|
|
def addlogmsg(user, instance, message):
|
2015-03-18 13:48:29 +00:00
|
|
|
"""
|
2019-09-10 06:48:31 +00:00
|
|
|
:param user:
|
|
|
|
:param instance:
|
|
|
|
:param message:
|
2015-03-18 13:48:29 +00:00
|
|
|
:return:
|
|
|
|
"""
|
2015-05-18 19:00:30 +00:00
|
|
|
add_log_msg = Logs(user=user, instance=instance, message=message)
|
2015-03-18 13:48:29 +00:00
|
|
|
add_log_msg.save()
|
|
|
|
|
|
|
|
|
2020-05-27 12:24:06 +00:00
|
|
|
@superuser_only
|
2017-12-11 14:07:01 +00:00
|
|
|
def vm_logs(request, vname):
|
|
|
|
"""
|
|
|
|
:param request:
|
2019-09-10 06:48:31 +00:00
|
|
|
:param vname:
|
2017-12-11 14:07:01 +00:00
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
|
|
|
|
vm = Instance.objects.get(name=vname)
|
|
|
|
logs_ = Logs.objects.filter(instance=vm.name, date__gte=vm.created).order_by('-date')
|
|
|
|
logs = []
|
|
|
|
for l in logs_:
|
2019-09-10 06:48:31 +00:00
|
|
|
log = dict()
|
2017-12-11 14:07:01 +00:00
|
|
|
log['user'] = l.user
|
|
|
|
log['instance'] = l.instance
|
|
|
|
log['message'] = l.message
|
|
|
|
log['date'] = l.date.strftime('%x %X')
|
|
|
|
logs.append(log)
|
2020-05-27 12:24:06 +00:00
|
|
|
|
2017-12-11 14:07:01 +00:00
|
|
|
return HttpResponse(json.dumps(logs))
|