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