Commit d091507d by Bodor Máté

Fix flake8 errors

parent a017ac6d
Pipeline #788 failed with stages
in 2 minutes 0 seconds
......@@ -69,7 +69,6 @@ class Image(models.Model):
return inst
@classmethod
def create_from_instance(cls, user, instance, description):
interface = OSVirtualMachineManager(settings.CONNECTION)
......@@ -88,7 +87,8 @@ class Image(models.Model):
@classmethod
def create_from_user(cls, description, file_format, image_file, name, user):
interface = OpenstackImageManager(settings.CONNECTION)
remote_image = interface.upload_file(name=name, path=image_file.temporary_file_path(), format=file_format)
remote_image = interface.upload_file(name=name, path=image_file.temporary_file_path(),
format=file_format)
new_image = cls.create(
name=name,
remote_id=remote_image.id,
......
# from django.shortcuts import render
from rest_framework.viewsets import ModelViewSet
from rest_framework.response import Response
from django.http import HttpResponse
from image.models import Image
from image.serializers import ImageSerializer
class ImageViewSet(ModelViewSet):
serializer_class=ImageSerializer
queryset=Image.objects.all()
serializer_class = ImageSerializer
queryset = Image.objects.all()
# def list(self, request):
# return HttpResponse("list")
......@@ -17,7 +16,7 @@ class ImageViewSet(ModelViewSet):
serializer = ImageSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
data = serializer.validated_data
new_image =Image.create_from_user(
new_image = Image.create_from_user(
description=data['description'],
file_format=data['file_format'],
image_file=data['image_file'],
......
......@@ -9,6 +9,7 @@ from interface_openstack.implementation.vm.instance import (
)
from instance.models import Instance, Flavor, Lease
from instance.serializers import InstanceSerializer, FlavorSerializer
from template.models import ImageTemplate
class InstanceList(APIView):
......
......@@ -29,4 +29,3 @@ urlpatterns = [
re_path(r"^auth/", include("djoser.urls.authtoken")),
path(r"swagger", schema_view),
]
\ No newline at end of file
......@@ -7,7 +7,6 @@ from image.models import Image
from instance.models import Lease
from instance.models import Flavor
from interface_openstack.implementation.storage.openstack_snapshot_manager import SnapshotManager
from interface_openstack.implementation.vm.instance import OSVirtualMachineManager
class BaseTemplate(models.Model):
......@@ -77,7 +76,6 @@ class ImageTemplate(BaseTemplate):
('U', 'User create the template from image'),
('I', 'Template created from instance'),
('P', '"Pure" template'),
)
image = models.ForeignKey(
......@@ -90,13 +88,12 @@ class ImageTemplate(BaseTemplate):
@classmethod
def create(cls, name, description, image, lease, flavor, created_by, type='U'):
inst = cls(name=name, description=description, image=image, lease=lease, flavor=flavor, created_by=created_by, type=type)
inst = cls(name=name, description=description, image=image, lease=lease,
flavor=flavor, created_by=created_by, type=type)
inst.full_clean()
inst.save()
return inst
@classmethod
def create_from_instance(cls, name, description, instance, user):
image = Image.create_from_instance(user, instance, description)
......@@ -104,7 +101,7 @@ class ImageTemplate(BaseTemplate):
name=name,
description=description,
created_by=user,
image = image,
image=image,
lease=instance.lease,
flavor=instance.flavor,
type="I"
......
......@@ -9,8 +9,8 @@ from template.models import ImageTemplate
class ImageTemplateViewSet(ModelViewSet):
serializer_class=ImageTemplateModelSerializer
queryset=ImageTemplate.objects.all()
serializer_class = ImageTemplateModelSerializer
queryset = ImageTemplate.objects.all()
def create(self, request):
serializer = ImageTemplateModelSerializer(data=request.data)
......@@ -20,7 +20,7 @@ class ImageTemplateViewSet(ModelViewSet):
name=data["name"],
description=data["description"],
created_by=request.user,
image = data["image"],
image=data["image"],
lease=data["lease"],
flavor=data["flavor"],
type="U"
......@@ -32,12 +32,12 @@ class ImageTemplateViewSet(ModelViewSet):
# only the name, description, lease, flavor can be updated
allowed_keys = ["name", "description", "lease", "flavor"]
#delete not allowed key
# delete not allowed key
for key in request.data.keys():
if key not in allowed_keys:
request.data.pop(key, None)
return super(QuestionViewSet, self).update(request, partial=True)
return super(ImageTemplateViewSet, self).update(request, partial=True)
@action(detail=True, methods=["post"])
def template(self, request, pk):
......@@ -45,6 +45,7 @@ class ImageTemplateViewSet(ModelViewSet):
serializer = InstanceFromTemplateSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
data = serializer.validated_data
new_template = ImageTemplate.create_from_instance(data["name"], data["description"], instance, request.user)
new_template = ImageTemplate.create_from_instance(data["name"], data["description"],
instance, request.user)
serializer = ImageTemplateModelSerializer(instance=new_template)
return Response(serializer.data)
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