opennebula -> router
This commit is contained in:
parent
cee45b5227
commit
e2b5b5d102
4 changed files with 43 additions and 16 deletions
|
@ -29,9 +29,22 @@ class VM(models.Model):
|
|||
If there are multiple disks, we have a list of dictionaries in the database.
|
||||
"""
|
||||
|
||||
if not 'DISK' in self.data['TEMPLATE']['DISK']:
|
||||
return []
|
||||
elif type(self.data['TEMPLATE']['DISK']) is dict:
|
||||
return [ self.data['TEMPLATE']['DISK'] ]
|
||||
else:
|
||||
return self.data['TEMPLATE']['DISK']
|
||||
disks = []
|
||||
|
||||
if 'DISK' in self.data['TEMPLATE']:
|
||||
|
||||
if type(self.data['TEMPLATE']['DISK']) is dict:
|
||||
disks = [ self.data['TEMPLATE']['DISK'] ]
|
||||
else:
|
||||
disks = self.data['TEMPLATE']['DISK']
|
||||
|
||||
disks = [
|
||||
{
|
||||
'size_in_gb': int(d['SIZE'])/1024. ,
|
||||
'opennebula_source': d['SOURCE'],
|
||||
'opennebula_name': d['IMAGE'],
|
||||
}
|
||||
for d in disks
|
||||
]
|
||||
|
||||
return disks
|
||||
|
|
|
@ -6,3 +6,9 @@ class VMSerializer(serializers.HyperlinkedModelSerializer):
|
|||
class Meta:
|
||||
model = VM
|
||||
fields = ['vmid', 'owner', 'data']
|
||||
|
||||
|
||||
class OpenNebulaVMSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = VM
|
||||
fields = ['vmid', 'owner', 'cores', 'ram_in_gb', 'disks' ]
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
from rest_framework import viewsets, generics
|
||||
from rest_framework import viewsets, generics, permissions
|
||||
from .models import VM
|
||||
from .serializers import VMSerializer
|
||||
from .serializers import VMSerializer, OpenNebulaVMSerializer
|
||||
|
||||
|
||||
class VMList(generics.ListAPIView):
|
||||
#class VMList(generics.ListAPIView):
|
||||
# queryset = VM.objects.all()
|
||||
# serializer_class = VMSerializer
|
||||
|
||||
|
||||
class RawVMViewSet(viewsets.ModelViewSet):
|
||||
# lookup_field = 'vmid'
|
||||
queryset = VM.objects.all()
|
||||
serializer_class = VMSerializer
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
|
||||
class VMDetail(generics.RetrieveAPIView):
|
||||
lookup_field = 'vmid'
|
||||
class VMViewSet(viewsets.ModelViewSet):
|
||||
queryset = VM.objects.all()
|
||||
serializer_class = VMSerializer
|
||||
serializer_class = OpenNebulaVMSerializer
|
||||
|
||||
class VMViewSet(
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
|
|
@ -24,6 +24,8 @@ from opennebula import views as oneviews
|
|||
router = routers.DefaultRouter()
|
||||
router.register(r'users', views.UserViewSet)
|
||||
router.register(r'groups', views.GroupViewSet)
|
||||
router.register(r'opennebula', oneviews.VMViewSet)
|
||||
router.register(r'opennebula_raw', oneviews.RawVMViewSet)
|
||||
|
||||
# Wire up our API using automatic URL routing.
|
||||
# Additionally, we include login URLs for the browsable API.
|
||||
|
@ -31,8 +33,8 @@ urlpatterns = [
|
|||
path('', include(router.urls)),
|
||||
path('admin/', admin.site.urls),
|
||||
path('products/', views.ProductsView.as_view(), name='products'),
|
||||
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
|
||||
path('vm/list/', oneviews.VMList.as_view(), name='vm_list'),
|
||||
path('vm/detail/<int:vmid>/', oneviews.VMDetail.as_view(), name='vm_detail'),
|
||||
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
|
||||
# path('vm/list/', oneviews.VMList.as_view(), name='vm_list'),
|
||||
# path('vm/detail/<int:vmid>/', oneviews.VMDetail.as_view(), name='vm_detail'),
|
||||
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue