url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/networks$', views.get_networks, name='get_networks'),
url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/subnets$', views.get_subnets, name='get_subnets'),
url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/cps$', views.get_cps, name='get_cps'),
- url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/volumes$', views.get_volumes, name='get_volumes'),
+ url(r'^api/vnfres/v1/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/volumes$', views.getVolumes.as_view(), name='get_volumes'),
url(r'^api/vnfres/v1/swagger.json$', SwaggerJsonView.as_view()),
]
import os
import traceback
+from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response
from res.pub.utils.syscomm import fun_name
from res.pub.database.models import NfInstModel, StorageInstModel, NetworkInstModel, VLInstModel, \
VNFCInstModel, VmInstModel, FlavourInstModel, SubNetworkInstModel, CPInstModel
+from res.resources.serializers import VolumeInfoSerializer, NoneSerializer
logger = logging.getLogger(__name__)
return cps_data
-@api_view(http_method_names=['GET'])
-def get_volumes(request, *args, **kwargs):
- logger.debug("Query all the volumes by vnfInstanceId[%s]", fun_name())
- try:
- vnf_inst_id = ignore_case_get(kwargs, "vnfInstanceId")
- volumes = StorageInstModel.objects.filter(instid=vnf_inst_id)
- if not volumes:
- return Response(data={'error': 'Volumes does not exist'}, status=status.HTTP_404_NOT_FOUND)
- arr = []
- for v in volumes:
- arr.append(fill_volumes_data(v))
- return Response(data={'resp_data': arr}, status=status.HTTP_200_OK)
- except Exception as e:
- logger.error(e.message)
- logger.error(traceback.format_exc())
- return Response(data={'error': 'Failed to get volumes'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+class getVolumes(APIView):
+ @swagger_auto_schema(request_body=NoneSerializer(),
+ responses={
+ status.HTTP_200_OK: VolumeInfoSerializer(),
+ status.HTTP_404_NOT_FOUND: 'Volumes does not exist',
+ status.HTTP_500_INTERNAL_SERVER_ERROR: 'internal error'})
+ def get(self, request, vnfInstanceId):
+ logger.debug("Query all the volumes by vnfInstanceId[%s]", fun_name())
+ try:
+ volumes = StorageInstModel.objects.filter(instid=vnfInstanceId)
+ if not volumes:
+ return Response(data={'error': 'Volumes does not exist'}, status=status.HTTP_404_NOT_FOUND)
+ arr = []
+ for v in volumes:
+ arr.append(fill_volumes_data(v))
+ volumeSerializer = VolumeInfoSerializer(data={'resp_data': arr})
+ isValid = volumeSerializer.is_valid()
+ if not isValid:
+ raise Exception(volumeSerializer.errors)
+
+ return Response(data=volumeSerializer.data, status=status.HTTP_200_OK)
+ except Exception as e:
+ logger.error(e.message)
+ logger.error(traceback.format_exc())
+ return Response(data={'error': 'Failed to get volumes'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
def fill_volumes_data(v):