Commit f34faabf by Chif Gergő

Call remote resize in model

parent 720ab1e4
Pipeline #1070 passed with stage
in 1 minute 32 seconds
......@@ -264,6 +264,15 @@ class Instance(BaseMachineDescriptor):
self.password = self.generate_password()
self.save()
def resize(self, flavor):
try:
interface.resize_vm(self.remote_id, flavor)
self.flavor = flavor
self.save()
except Exception as e:
if e.OpenStackError:
logger.error("Can not resize the instance in remote cloud")
def change_name(self, new_name):
self.name = new_name
self.save()
......
......@@ -168,15 +168,13 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
@action(detail=True, methods=["POST"])
def resize(self, request, pk):
pass
# TODO: resize not implemented in model
# instance = self.get_object(pk)
# if "flavor" in request.data:
# flavor = Flavor.objects.get(pk=request.data["flavor"])
# instance.resize(flavor)
# return Response(status=status.HTTP_200_OK)
# else:
# return Response(data="No new flavor provided", status=status.HTTP_400_BAD_REQUEST)
instance = self.get_object(pk)
if "flavor" in request.data:
flavor = Flavor.objects.get(pk=request.data["flavor"])
instance.resize(flavor)
return Response(status=status.HTTP_200_OK)
else:
return Response(data="No new flavor provided", status=status.HTTP_400_BAD_REQUEST)
@action(detail=True, methods=["POST"])
def attach_disk(self, request, pk):
......
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