1 # Copyright 2017 ZTE Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 from rest_framework import status
18 from rest_framework.decorators import api_view
19 from rest_framework.response import Response
21 from res.pub.utils.values import ignore_case_get
22 from res.pub.utils.syscomm import fun_name
23 from res.pub.database.models import NfInstModel
25 logger = logging.getLogger(__name__)
28 @api_view(http_method_names=['GET'])
29 def get_vnf(request, *args, **kwargs):
30 vnf_inst_id = ignore_case_get(kwargs, "vnfInstanceId")
31 logger.debug("[%s]vnf_inst_id=%s", fun_name(), vnf_inst_id)
33 vnf_inst = NfInstModel.objects.filter(nfinstid=vnf_inst_id)
35 return Response(data={'error': 'Vnf(%s) does not exist' % vnf_inst_id},
36 status=status.HTTP_404_NOT_FOUND)
37 # TODO: fill resp_data
38 resp_data = {"vnfInstanceId": vnf_inst_id}
39 return Response(data=resp_data, status=status.HTTP_200_OK)
41 logger.error(traceback.format_exc())
42 return Response(data={'error': 'Failed to get Vnf(%s)' % vnf_inst_id},
43 status=status.HTTP_500_INTERNAL_SERVER_ERROR)