1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-25 15:45:23 +00:00
webvirtcloud/logs/views.py

43 lines
965 B
Python
Raw Normal View History

import json
from django.http import HttpResponse
from admin.decorators import superuser_only
from instances.models import Instance
2015-03-03 09:34:09 +00:00
from logs.models import Logs
2021-05-31 08:39:09 +00:00
def addlogmsg(user, host, instance, message):
"""
2019-09-10 06:48:31 +00:00
:param user:
2021-05-31 08:39:09 +00:00
:param host:
2019-09-10 06:48:31 +00:00
:param instance:
:param message:
:return:
"""
2021-05-31 08:39:09 +00:00
add_log_msg = Logs(user=user, host=host, instance=instance, message=message)
add_log_msg.save()
@superuser_only
def vm_logs(request, vname):
"""
:param request:
2019-09-10 06:48:31 +00:00
:param vname:
: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()
log["user"] = l.user
2021-05-31 08:39:09 +00:00
log["host"] = l.host
log["instance"] = l.instance
log["message"] = l.message
log["date"] = l.date.strftime("%x %X")
logs.append(log)
return HttpResponse(json.dumps(logs))