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 there are multiple disks, we have a list of dictionaries in the database.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not 'DISK' in self.data['TEMPLATE']['DISK']:
|
disks = []
|
||||||
return []
|
|
||||||
elif type(self.data['TEMPLATE']['DISK']) is dict:
|
if 'DISK' in self.data['TEMPLATE']:
|
||||||
return [ self.data['TEMPLATE']['DISK'] ]
|
|
||||||
|
if type(self.data['TEMPLATE']['DISK']) is dict:
|
||||||
|
disks = [ self.data['TEMPLATE']['DISK'] ]
|
||||||
else:
|
else:
|
||||||
return self.data['TEMPLATE']['DISK']
|
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:
|
class Meta:
|
||||||
model = VM
|
model = VM
|
||||||
fields = ['vmid', 'owner', 'data']
|
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 .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()
|
queryset = VM.objects.all()
|
||||||
serializer_class = VMSerializer
|
serializer_class = VMSerializer
|
||||||
|
permission_classes = [permissions.IsAuthenticated]
|
||||||
|
|
||||||
|
|
||||||
class VMDetail(generics.RetrieveAPIView):
|
class VMViewSet(viewsets.ModelViewSet):
|
||||||
lookup_field = 'vmid'
|
|
||||||
queryset = VM.objects.all()
|
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 = routers.DefaultRouter()
|
||||||
router.register(r'users', views.UserViewSet)
|
router.register(r'users', views.UserViewSet)
|
||||||
router.register(r'groups', views.GroupViewSet)
|
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.
|
# Wire up our API using automatic URL routing.
|
||||||
# Additionally, we include login URLs for the browsable API.
|
# Additionally, we include login URLs for the browsable API.
|
||||||
|
@ -31,8 +33,8 @@ urlpatterns = [
|
||||||
path('', include(router.urls)),
|
path('', include(router.urls)),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('products/', views.ProductsView.as_view(), name='products'),
|
path('products/', views.ProductsView.as_view(), name='products'),
|
||||||
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
|
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
|
||||||
path('vm/list/', oneviews.VMList.as_view(), name='vm_list'),
|
# path('vm/list/', oneviews.VMList.as_view(), name='vm_list'),
|
||||||
path('vm/detail/<int:vmid>/', oneviews.VMDetail.as_view(), name='vm_detail'),
|
# path('vm/detail/<int:vmid>/', oneviews.VMDetail.as_view(), name='vm_detail'),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue