summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfujinhua <fu.jinhua@zte.com.cn>2019-07-12 11:32:14 +0800
committerfujinhua <fu.jinhua@zte.com.cn>2019-07-12 11:32:14 +0800
commit17a30cc7369e240b50a7f60f407e97caef47439d (patch)
tree32806374a00fdb88bc6ed103aa75f946747ef9b5
parent2bd210a0ebf4c3c861365eb63b5fd558b792420a (diff)
Refactor codes for del and get ns
Change-Id: I773cd98f28a2b27f7ccebceec1a6cdd0e491bada Issue-ID: VFC-1429 Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r--lcm/ns/views/deprecated/get_del_ns_view.py40
1 files changed, 16 insertions, 24 deletions
diff --git a/lcm/ns/views/deprecated/get_del_ns_view.py b/lcm/ns/views/deprecated/get_del_ns_view.py
index 2bb34c05..db5a4466 100644
--- a/lcm/ns/views/deprecated/get_del_ns_view.py
+++ b/lcm/ns/views/deprecated/get_del_ns_view.py
@@ -12,7 +12,6 @@
# 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
@@ -23,6 +22,7 @@ from lcm.ns.biz.ns_delete import DeleteNsService
from lcm.ns.biz.ns_get import GetNSInfoService
from lcm.pub.exceptions import NSLCMException
from lcm.ns.serializers.deprecated.ns_serializers import _QueryNsRespSerializer
+from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
@@ -36,22 +36,18 @@ class NSDetailView(APIView):
status.HTTP_404_NOT_FOUND: "Ns instance does not exist"
}
)
+ @view_safe_call_with_log(logger=logger)
def get(self, request, ns_instance_id):
- try:
- logger.debug("Enter NSDetailView::get ns(%s)", ns_instance_id)
- ns_filter = {"ns_inst_id": ns_instance_id}
- ret = GetNSInfoService(ns_filter).get_ns_info()
- if not ret:
- return Response(status=status.HTTP_404_NOT_FOUND)
- logger.debug("Leave NSDetailView::get::ret=%s", ret)
- resp_serializer = _QueryNsRespSerializer(data=ret[0])
- if not resp_serializer.is_valid():
- raise NSLCMException(resp_serializer.errors)
- return Response(data=resp_serializer.data, status=status.HTTP_200_OK)
- except Exception as e:
- logger.error(traceback.format_exc())
- logger.error("Exception in GetNSDetail: %s", e.args[0])
- return Response(data={'error': e.args[0]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ logger.debug("Enter NSDetailView::get ns(%s)", ns_instance_id)
+ ns_filter = {"ns_inst_id": ns_instance_id}
+ ret = GetNSInfoService(ns_filter).get_ns_info()
+ if not ret:
+ return Response(status=status.HTTP_404_NOT_FOUND)
+ logger.debug("Leave NSDetailView::get::ret=%s", ret)
+ resp_serializer = _QueryNsRespSerializer(data=ret[0])
+ if not resp_serializer.is_valid():
+ raise NSLCMException(resp_serializer.errors)
+ return Response(data=resp_serializer.data, status=status.HTTP_200_OK)
@swagger_auto_schema(
request_body=None,
@@ -60,12 +56,8 @@ class NSDetailView(APIView):
status.HTTP_500_INTERNAL_SERVER_ERROR: "Inner error"
}
)
+ @view_safe_call_with_log(logger=logger)
def delete(self, request, ns_instance_id):
- try:
- logger.debug("Enter NSDetailView::delete ns(%s)", ns_instance_id)
- DeleteNsService(ns_instance_id).do_biz()
- return Response(data={}, status=status.HTTP_204_NO_CONTENT)
- except Exception as e:
- logger.error(traceback.format_exc())
- logger.error("Exception in delete NS: %s", e.args[0])
- return Response(data={'error': e.args[0]}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ logger.debug("Enter NSDetailView::delete ns(%s)", ns_instance_id)
+ DeleteNsService(ns_instance_id).do_biz()
+ return Response(data={}, status=status.HTTP_204_NO_CONTENT)