Commit daea0676 by Chif Gergő

Modify instance create view, add flavor list view

parent 15057b46
from rest_framework import serializers
from .models import Flavor
from .models import Instance
class InstanceSerializer(serializers.Serializer):
name = serializers.CharField()
description = serializers.CharField()
system = serializers.CharField()
lease = serializers.RelatedField(read_only=True)
flavor = serializers.RelatedField(read_only=True)
class InstanceSerializer(serializers.ModelSerializer):
class FlavorSerializer(serializers.ModelSerializer):
class Meta:
model = Instance
fields = "__all__"
model = Flavor
fields = '__all__'
......@@ -6,6 +6,7 @@ urlpatterns = [
path("instances/", views.InstanceList.as_view()),
path("instances/<int:pk>/", views.InstanceDetail.as_view()),
# path('instances/<int:pk>/action/', views.InstanceAction.as_view())
path("flavors/", views.FlavorListView.as_view()),
]
urlpatterns = format_suffix_patterns(urlpatterns)
from instance.models import Instance
from instance.serializers import InstanceSerializer
from instance.serializers import InstanceSerializer, FlavorSerializer
from django.http import Http404
from rest_framework.views import APIView
from rest_framework.response import Response
......@@ -25,12 +25,15 @@ class InstanceList(APIView):
def post(self, request, format=None):
data = request.data
template = InstanceTemplate(name="test1", description="adsasdasd",
template = InstanceTemplate(
name="test1", description="adsasdasd",
remote_ID="da51253f-867c-472d-8ce0-81e7b7126d60")
flavor = Flavor(name="asd", description="asd", remote_id="1")
flavor.save()
lease = Lease(name="test_lease", description="test",
suspend_interval_in_sec=100,
delete_interval_in_sec=100)
lease.save()
newInstance = Instance.create_instance_from_template(
params={"name": data["name"],
......@@ -85,3 +88,24 @@ class InstanceDetail(APIView):
instance = self.get_object(pk)
instance.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
class FlavorListView(APIView):
"""
Create, update or delete a flavor.
"""
def get(self, request, format=None):
flavors = Flavor.objects.all()
return Response(FlavorSerializer(flavors, many=True).data)
def post(self, request, format=None):
data = request.data
new_flavor = Flavor.create(name=data["name"],
description=data["description"],
ram=data["ram"],
vcpu=data["vcpu"],
initial_disk=data["initial_disk"],
priority=data["priority"])
return Response(new_flavor.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