diff options
-rw-r--r-- | lcm/v2/views.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lcm/v2/views.py b/lcm/v2/views.py index 4b0a9499..19f6740a 100644 --- a/lcm/v2/views.py +++ b/lcm/v2/views.py @@ -12,15 +12,35 @@ # See the License for the specific language governing permissions and # limitations under the License. import logging +import traceback from rest_framework.response import Response from rest_framework.views import APIView from rest_framework import status +from drf_yasg.utils import swagger_auto_schema + +from lcm.v2.serializers import GrantRequestSerializer +from lcm.v2.serializers import GrantSerializer logger = logging.getLogger(__name__) class VnfGrantView(APIView): + @swagger_auto_schema( + request_body=GrantRequestSerializer(), + responses={ + status.HTTP_201_CREATED: GrantSerializer(), + status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error" + } + ) def post(self, request): logger.debug("VnfGrantView Post: %s" % request.data) + try: + req_serializer = GrantRequestSerializer(data=request.data) + if not req_serializer.is_valid(): + raise Exception(req_serializer.errors) + except Exception as e: + logger.error(traceback.format_exc()) + logger.error("Exception in VnfGrant: %s", e.message) + return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) return Response(data={}, status=status.HTTP_201_CREATED) |