2020-02-20 15:52:50 +00:00
|
|
|
from django.shortcuts import render
|
2020-02-21 10:32:41 +00:00
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from django.contrib.auth.models import Group
|
2020-02-20 15:52:50 +00:00
|
|
|
|
2020-02-22 06:32:52 +00:00
|
|
|
from rest_framework import viewsets, permissions, generics
|
2020-02-21 09:41:22 +00:00
|
|
|
from .serializers import UserSerializer, GroupSerializer
|
2020-02-22 06:32:52 +00:00
|
|
|
from rest_framework.views import APIView
|
|
|
|
from rest_framework.response import Response
|
|
|
|
|
2020-02-20 17:58:07 +00:00
|
|
|
|
2020-02-20 18:38:43 +00:00
|
|
|
class CreditCardViewSet(viewsets.ModelViewSet):
|
|
|
|
|
|
|
|
"""
|
|
|
|
API endpoint that allows credit cards to be listed
|
|
|
|
"""
|
2020-02-21 10:32:41 +00:00
|
|
|
queryset = get_user_model().objects.all().order_by('-date_joined')
|
2020-02-20 18:38:43 +00:00
|
|
|
serializer_class = UserSerializer
|
|
|
|
|
|
|
|
permission_classes = [permissions.IsAuthenticated]
|
|
|
|
|
2020-02-20 17:58:07 +00:00
|
|
|
|
|
|
|
class UserViewSet(viewsets.ModelViewSet):
|
2020-02-20 18:38:43 +00:00
|
|
|
|
2020-02-20 17:58:07 +00:00
|
|
|
"""
|
|
|
|
API endpoint that allows users to be viewed or edited.
|
|
|
|
"""
|
2020-02-21 10:32:41 +00:00
|
|
|
queryset = get_user_model().objects.all().order_by('-date_joined')
|
2020-02-20 17:58:07 +00:00
|
|
|
serializer_class = UserSerializer
|
|
|
|
|
2020-02-20 18:38:43 +00:00
|
|
|
permission_classes = [permissions.IsAuthenticated]
|
2020-02-20 17:58:07 +00:00
|
|
|
|
|
|
|
class GroupViewSet(viewsets.ModelViewSet):
|
|
|
|
"""
|
|
|
|
API endpoint that allows groups to be viewed or edited.
|
|
|
|
"""
|
|
|
|
queryset = Group.objects.all()
|
|
|
|
serializer_class = GroupSerializer
|
2020-02-20 18:38:43 +00:00
|
|
|
|
|
|
|
permission_classes = [permissions.IsAuthenticated]
|
2020-02-22 06:32:52 +00:00
|
|
|
|
|
|
|
class GroupViewSet(viewsets.ModelViewSet):
|
|
|
|
"""
|
|
|
|
API endpoint that allows groups to be viewed or edited.
|
|
|
|
"""
|
|
|
|
queryset = Group.objects.all()
|
|
|
|
serializer_class = GroupSerializer
|
|
|
|
|
|
|
|
permission_classes = [permissions.IsAuthenticated]
|
|
|
|
|
|
|
|
|
|
|
|
# POST /vm/snapshot/ vmuuid=... => create snapshot, returns snapshot uuid
|
|
|
|
# GET /vm/snapshot => list
|
|
|
|
# DEL /vm/snapshot/<uuid:uuid> => delete
|
|
|
|
# create-list -> get, post => ListCreateAPIView
|
|
|
|
# del on other!
|
|
|
|
class VMSnapshotView(generics.ListCreateAPIView):
|
|
|
|
#lookup_field = 'uuid'
|
|
|
|
permission_classes = [permissions.IsAuthenticated]
|
|
|
|
|
|
|
|
import inspect
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
|
|
|
|
# Next: create /order/<productname> urls
|
|
|
|
# Next: strip off "Product" at the end
|
|
|
|
class ProductsView(APIView):
|
|
|
|
def get(self, request, format=None):
|
|
|
|
clsmembers = inspect.getmembers(sys.modules['uncloud_api.models'], inspect.isclass)
|
|
|
|
products = []
|
|
|
|
for name, c in clsmembers:
|
|
|
|
# Include everything that ends in Product, but not Product itself
|
|
|
|
m = re.match(r'(?P<pname>.+)Product$', name)
|
|
|
|
if m:
|
|
|
|
products.append({
|
|
|
|
'name': m.group('pname'),
|
|
|
|
'description': c.description,
|
|
|
|
'recurring_period': c.recurring_period,
|
|
|
|
'pricing_model': c.pricing_model()
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return Response(products)
|