Commit befe5fa1 by Belákovics Ádám

Modify update response

parent 52626ae9
Pipeline #861 passed with stage
in 1 minute 21 seconds
...@@ -16,6 +16,7 @@ authorization = { ...@@ -16,6 +16,7 @@ authorization = {
"list": {"filter": ["use_instance"]}, "list": {"filter": ["use_instance"]},
"create": {"model": ["instance.create_instance"]}, "create": {"model": ["instance.create_instance"]},
"retrieve": {"object": ["use_instance"]}, "retrieve": {"object": ["use_instance"]},
"update": {"object": ["use_instance"]},
"destroy": {"object": ["administer_instance"]}, "destroy": {"object": ["administer_instance"]},
"template": {"model": ["create_template_from_instance"], "template": {"model": ["create_template_from_instance"],
"object": ["use_instance"]}, "object": ["use_instance"]},
...@@ -105,7 +106,7 @@ class InstanceViewSet(AuthorizationMixin, ViewSet): ...@@ -105,7 +106,7 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
def update(self, request, pk, format=None): def update(self, request, pk, format=None):
if request.data["action"] in update_actions: if request.data["action"] in update_actions:
instance = self.get_object(pk) instance = self.get_object(pk)
if not self.has_perms_for_object(request.user, 'retrieve', instance): if not self.has_perms_for_object(request.user, 'update', instance):
return Response({"error": "No permission to access the Virtual Machine."}, return Response({"error": "No permission to access the Virtual Machine."},
status=status.HTTP_401_UNAUTHORIZED) status=status.HTTP_401_UNAUTHORIZED)
action = request.data["action"] action = request.data["action"]
...@@ -116,7 +117,7 @@ class InstanceViewSet(AuthorizationMixin, ViewSet): ...@@ -116,7 +117,7 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
elif action == "renew": elif action == "renew":
instance.renew() instance.renew()
elif action == "change_lease": elif action == "change_lease":
lease = Lease.objects.get(id=request.data["lease"]) lease = Lease.objects.get(pk=request.data["lease"])
instance.renew(lease) instance.renew(lease)
elif action == "change_flavor": elif action == "change_flavor":
pass pass
...@@ -142,7 +143,7 @@ class InstanceViewSet(AuthorizationMixin, ViewSet): ...@@ -142,7 +143,7 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
instanceDict = InstanceSerializer(instance).data instanceDict = InstanceSerializer(instance).data
remoteInstance = instance.get_remote_instance() remoteInstance = instance.get_remote_instance()
remoteInstanceDict = remoteInstance.__dict__ remoteInstanceDict = remoteInstance.__dict__
merged_dict = {**instanceDict, **remoteInstanceDict} merged_dict = {"db": instanceDict, "openstack": remoteInstanceDict}
return Response(merged_dict) return Response(merged_dict)
else: else:
return Response({"error": "Unknown update action."}, status=status.HTTP_400_BAD_REQUEST) return Response({"error": "Unknown update action."}, status=status.HTTP_400_BAD_REQUEST)
......
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