summaryrefslogtreecommitdiffstats
path: root/mgr
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-01-23 16:51:37 +0800
committeryunlong ying <ying.yunlong@zte.com.cn>2018-01-23 09:11:27 +0000
commitda0e046eb6dcd214bd19a867543ecbaf0db8f076 (patch)
treed2dacddabb1ef8ece56274d5c42544265b795c26 /mgr
parent6bd6774bc2c0f365cbb3b118105dfb0875a67947 (diff)
Add vfc-vnfmgr vnfconfig auto-swagger
Change-Id: Iebf400421f81ed3cfc19fdc0dbdf37fccecba310 Issue-ID: VFC-670 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'mgr')
-rw-r--r--mgr/mgr/vnfreg/views.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/mgr/mgr/vnfreg/views.py b/mgr/mgr/vnfreg/views.py
index 86e1c7f..7524dcf 100644
--- a/mgr/mgr/vnfreg/views.py
+++ b/mgr/mgr/vnfreg/views.py
@@ -27,7 +27,8 @@ from mgr.pub.utils.values import ignore_case_get
from mgr.pub.utils.syscomm import fun_name
from mgr.pub.database.models import VnfRegModel
from mgr.pub.utils import restcall
-from mgr.vnfreg.serializers import ErrorSerializer, VnfInfoSerializer, ResponseSerializer, NoneSerializer
+from mgr.vnfreg.serializers import ErrorSerializer, VnfInfoSerializer, ResponseSerializer, NoneSerializer, \
+ VnfConfigSerializer
logger = logging.getLogger(__name__)
@@ -149,11 +150,22 @@ def access_vnf(request, *args, **kwargs):
return Response(data=ret, status=normal_status)
+@swagger_auto_schema(method='post',
+ request_body=VnfConfigSerializer(),
+ responses={
+ 202: NoneSerializer(),
+ 500: ErrorSerializer()})
@api_view(http_method_names=['POST'])
def vnf_config(request, *args, **kwargs):
logger.info("Enter %s, data is %s", fun_name(), request.data)
- vnf_inst_id = ignore_case_get(request.data, "vnfInstanceId")
+ requestSerializer = VnfConfigSerializer(data=request.data)
+ request_isValid = requestSerializer.is_valid()
try:
+ if not request_isValid:
+ raise Exception(requestSerializer.errors)
+
+ requestData = requestSerializer.data
+ vnf_inst_id = ignore_case_get(requestData, "vnfInstanceId")
vnf = VnfRegModel.objects.filter(id=vnf_inst_id)
if not vnf:
raise Exception("Vnf(%s) does not exist." % vnf_inst_id)
@@ -164,11 +176,10 @@ def vnf_config(request, *args, **kwargs):
auth_type=restcall.rest_no_auth,
resource="v1/vnfconfig",
method="POST",
- content=json.dumps(request.data))
+ content=json.dumps(requestData))
if ret[0] != 0:
raise Exception("Failed to config Vnf(%s): %s" % (vnf_inst_id, ret[1]))
except Exception as e:
- logger.error(e.message)
- logger.error(traceback.format_exc())
- return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ errorData = handler_exception(e)
+ return Response(data=errorData, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response(data={}, status=status.HTTP_202_ACCEPTED)