Commit 49465117 by Chif Gergő

Logging information messages about instance methods

parent 720ab1e4
Pipeline #1073 passed with stage
in 1 minute 29 seconds
......@@ -14,7 +14,9 @@ from template.models import ImageTemplate
from template.serializers import ImageTemplateModelSerializer
from authorization.mixins import AuthorizationMixin
from guardian.shortcuts import get_perms_for_model, assign_perm
import logging
logger = logging.getLogger(__name__)
authorization = {
"list": {"filter": ["use_instance"]},
......@@ -59,6 +61,7 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
return Instance.objects.get(pk=pk)
except Instance.DoesNotExist:
logger.warn(f"Unexistent instance was requested with id: {pk}")
raise Http404
def list(self, request):
......@@ -89,10 +92,15 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
)"New virt. machine instance created by {}:"
f"ID: {}")
for perm in get_perms_for_model(Instance):
assign_perm(perm, request.user, newInstance)"All permission granted to user: {} to instance:"
return Response(InstanceSerializer(newInstance).data, status=status.HTTP_201_CREATED)
def retrieve(self, request, pk):
......@@ -113,6 +121,8 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
if "description" in
instance.change_description(["description"])"Instance (ID: {}) was updated.")
return Response(InstanceSerializer(instance).data)
def destroy(self, request, pk):
......@@ -120,6 +130,7 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
if not instance:
return Response(status=status.HTTP_204_NO_CONTENT)
instance.destroy()"Instance (ID: {}) was deleted by user: {}")
return Response(status=status.HTTP_204_NO_CONTENT)
@action(detail=True, methods=["post"])
......@@ -138,6 +149,8 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
request.user)"A new template created with id: {} from instance:"
serializer = ImageTemplateModelSerializer(instance=new_template)
return Response(
......@@ -147,6 +160,9 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
if not self.has_perms_for_object(request.user,["action"], instance):
return Response({"error": "No permission to use this action on the VM."},
if "action" in
action =["action"]"Action {action} initiatied in instance: {}")
success = instance.execute_common_action(["action"])
return Response(success)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment