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): ...@@ -264,6 +264,15 @@ class Instance(BaseMachineDescriptor):
self.password = self.generate_password() self.password = self.generate_password()
self.save() 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): def change_name(self, new_name):
self.name = new_name self.name = new_name
self.save() self.save()
......
...@@ -168,15 +168,13 @@ class InstanceViewSet(AuthorizationMixin, ViewSet): ...@@ -168,15 +168,13 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
@action(detail=True, methods=["POST"]) @action(detail=True, methods=["POST"])
def resize(self, request, pk): def resize(self, request, pk):
pass instance = self.get_object(pk)
# TODO: resize not implemented in model if "flavor" in request.data:
# instance = self.get_object(pk) flavor = Flavor.objects.get(pk=request.data["flavor"])
# if "flavor" in request.data: instance.resize(flavor)
# flavor = Flavor.objects.get(pk=request.data["flavor"]) return Response(status=status.HTTP_200_OK)
# instance.resize(flavor) else:
# return Response(status=status.HTTP_200_OK) return Response(data="No new flavor provided", status=status.HTTP_400_BAD_REQUEST)
# else:
# return Response(data="No new flavor provided", status=status.HTTP_400_BAD_REQUEST)
@action(detail=True, methods=["POST"]) @action(detail=True, methods=["POST"])
def attach_disk(self, request, pk): 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