Commit 256a2690 by Chif Gergő

Create returns the whole object, the merging in retrieve extracted to a function

parent a824aa69
Pipeline #904 passed with stage
in 1 minute 21 seconds
......@@ -56,6 +56,18 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
except Instance.DoesNotExist:
raise Http404
def get_merged_object(self, pk):
instance = self.get_object(pk)
instanceDict = InstanceSerializer(instance).data
remoteInstance = instance.get_remote_instance()
remoteInstanceDict = {
"remote_id": remoteInstance.id,
"status": remoteInstance.status,
"disks": remoteInstance.disks,
"addresses": remoteInstance.addresses,
}
return({**instanceDict, **remoteInstanceDict})
def list(self, request):
instances = self.get_objects_with_perms(request.user, "list", Instance)
return Response(InstanceSerializer(instances, many=True).data)
......@@ -87,7 +99,8 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
owner=request.user,
disks=None
)
return Response(newInstance.pk)
return Response(InstanceSerializer(newInstance).data)
def retrieve(self, request, pk):
instance = self.get_object(pk)
......@@ -95,13 +108,9 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
return Response({"error": "No permission to access the Virtual Machine."},
status=status.HTTP_401_UNAUTHORIZED)
instanceDict = InstanceSerializer(instance).data
remoteInstance = instance.get_remote_instance()
remoteInstanceDict = remoteInstance.__dict__
merged_dict = {**instanceDict, **remoteInstanceDict}
mergedInstance = self.get_merged_object(pk)
return Response(merged_dict)
return Response(mergedInstance)
def update(self, request, pk, format=None):
if request.data["action"] in update_actions:
......
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