diff options
Diffstat (limited to 'lcm')
-rw-r--r-- | lcm/lcm/v2/urls.py | 8 | ||||
-rw-r--r-- | lcm/lcm/v2/views.py | 45 |
2 files changed, 53 insertions, 0 deletions
diff --git a/lcm/lcm/v2/urls.py b/lcm/lcm/v2/urls.py index 342c2a8c..ea23519d 100644 --- a/lcm/lcm/v2/urls.py +++ b/lcm/lcm/v2/urls.py @@ -11,3 +11,11 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +from django.conf.urls import url + +from lcm.v2.views import CreateVnfAndQueryVnfs + +urlpatterns = [ + url(r'^api/vnflcm/v2/vnf_instances$', CreateVnfAndQueryVnfs.as_view()), +] diff --git a/lcm/lcm/v2/views.py b/lcm/lcm/v2/views.py index 342c2a8c..1c66c1c0 100644 --- a/lcm/lcm/v2/views.py +++ b/lcm/lcm/v2/views.py @@ -11,3 +11,48 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + +import logging +import traceback + +from drf_yasg.utils import swagger_auto_schema +from rest_framework import status +from rest_framework.response import Response +from rest_framework.views import APIView + +from lcm.nf.serializers import CreateVnfReqSerializer, CreateVnfRespSerializer +from lcm.nf.vnf_create.create_vnf_identifier import CreateVnf +from lcm.pub.exceptions import NFLCMException +from lcm.v2.serializers import VnfInstanceSerializer + +logger = logging.getLogger(__name__) + + +class CreateVnfAndQueryVnfs(APIView): + @swagger_auto_schema( + request_body=CreateVnfReqSerializer(), + responses={ + status.HTTP_201_CREATED: VnfInstanceSerializer(), + status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error" + } + ) + def post(self, request): + logger.debug("CreateVnfIdentifier--post::> %s" % request.data) + try: + req_serializer = CreateVnfReqSerializer(data=request.data) + if not req_serializer.is_valid(): + raise NFLCMException(req_serializer.errors) + + nf_inst_id = CreateVnf(req_serializer.data).do_biz() + + create_vnf_resp_serializer = CreateVnfRespSerializer(data={"vnfInstanceId": nf_inst_id}) + if not create_vnf_resp_serializer.is_valid(): + raise NFLCMException(create_vnf_resp_serializer.errors) + return Response(data=create_vnf_resp_serializer.data, status=status.HTTP_201_CREATED) + except NFLCMException as e: + logger.error(e.message) + return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + except Exception as e: + logger.error(e.message) + logger.error(traceback.format_exc()) + return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) |