summaryrefslogtreecommitdiffstats
path: root/zte
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-02-12 15:47:15 +0800
committeryunlong ying <ying.yunlong@zte.com.cn>2018-02-12 08:07:41 +0000
commit662bbb1aba0521856e2e8e824dc37284d17fc19b (patch)
tree447199aeb977860430d6683bccf2fffc4ea9a7c1 /zte
parent3a158da6e82a9e8c5fb9cd4ef1f426f6607c61f2 (diff)
Add vfc-ztevnfmdriver instantiate swagger
Change-Id: I78f4e3eb5b79bf3c8c18aff13f161a08c646e439 Issue-ID: VFC-736 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'zte')
-rw-r--r--zte/vmanager/driver/interfaces/serializers.py3
-rw-r--r--zte/vmanager/driver/interfaces/views.py44
2 files changed, 30 insertions, 17 deletions
diff --git a/zte/vmanager/driver/interfaces/serializers.py b/zte/vmanager/driver/interfaces/serializers.py
index 09dbc084..a19613ca 100644
--- a/zte/vmanager/driver/interfaces/serializers.py
+++ b/zte/vmanager/driver/interfaces/serializers.py
@@ -79,9 +79,8 @@ class InstantiateVnfRequestSerializer(serializers.Serializer):
required=True,
max_length=255,
allow_null=True)
- additionalParam = serializers.DictField(
+ additionalParam = additionalParamSerializer(
help_text="additionalParam",
- child=additionalParamSerializer(help_text='additionalParam'),
required=True,
allow_null=True)
diff --git a/zte/vmanager/driver/interfaces/views.py b/zte/vmanager/driver/interfaces/views.py
index 93089670..1a1976ed 100644
--- a/zte/vmanager/driver/interfaces/views.py
+++ b/zte/vmanager/driver/interfaces/views.py
@@ -97,27 +97,36 @@ class InstamtiateVnf(APIView):
def post(self, request, vnfmid):
try:
logger.debug("[%s] request.data=%s", fun_name(), request.data)
+ instantiateVnfRequestSerializer = InstantiateVnfRequestSerializer(data=request.data)
+ if not instantiateVnfRequestSerializer.is_valid():
+ raise Exception(instantiateVnfRequestSerializer.errors)
+
ret = get_vnfminfo_from_nslcm(vnfmid)
if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
+ raise Exception(ret[1])
+
vnfm_info = json.JSONDecoder().decode(ret[1])
logger.debug("[%s] vnfm_info=%s", fun_name(), vnfm_info)
- vnf_package_id = ignorcase_get(request.data, "vnfPackageId")
+ vnf_package_id = ignorcase_get(instantiateVnfRequestSerializer.data, "vnfPackageId")
ret = vnfd_get(vnf_package_id)
if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
+ raise Exception(ret[1])
+
vnfd_info = json.JSONDecoder().decode(ret[1])
logger.debug("[%s] vnfd_info=%s", fun_name(), vnfd_info)
csar_id = ignorcase_get(vnfd_info, "csarId")
ret = vnfpackage_get(csar_id)
if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
+ raise Exception(ret[1])
+
vnf_package_info = json.JSONDecoder().decode(ret[1])
packageInfo = ignorcase_get(vnf_package_info, "packageInfo")
logger.debug("[%s] packageInfo=%s", fun_name(), packageInfo)
- data = {}
- data["NFVOID"] = 1
- data["VNFMID"] = vnfmid
+ data = {
+ "NFVOID": 1,
+ "VNFMID": vnfmid,
+ "extension": {},
+ }
vnfdModel = json.loads(ignorcase_get(packageInfo, "vnfdModel"))
metadata = ignorcase_get(vnfdModel, "metadata")
vnfd_name = ignorcase_get(metadata, "name")
@@ -134,14 +143,13 @@ class InstamtiateVnf(APIView):
data["VNFURL"] = data["VNFD"]
- data["extension"] = {}
- for name, value in ignorcase_get(ignorcase_get(request.data, "additionalParam"), "inputs").items():
+ for name, value in ignorcase_get(ignorcase_get(instantiateVnfRequestSerializer.data, "additionalParam"), "inputs").items():
inputs.append({"name": name, "value": value})
data["extension"]["inputs"] = json.dumps(inputs)
- additionalParam = ignorcase_get(request.data, "additionalParam")
+ additionalParam = ignorcase_get(instantiateVnfRequestSerializer.data, "additionalParam")
data["extension"]["extVirtualLinks"] = ignorcase_get(additionalParam, "extVirtualLinks")
- data["extension"]["vnfinstancename"] = ignorcase_get(request.data, "vnfInstanceName")
+ data["extension"]["vnfinstancename"] = ignorcase_get(instantiateVnfRequestSerializer.data, "vnfInstanceName")
data["extension"]["vnfid"] = data["VNFD"]
data["extension"]["multivim"] = 0
logger.debug("[%s] call_req data=%s", fun_name(), data)
@@ -157,17 +165,23 @@ class InstamtiateVnf(APIView):
logger.debug("[%s] call_req ret=%s", fun_name(), ret)
if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
+ raise Exception(ret[1])
+
resp = json.JSONDecoder().decode(ret[1])
resp_data = {
"vnfInstanceId": ignorcase_get(resp, "VNFInstanceID"),
"jobId": ignorcase_get(resp, "JobId")
}
logger.debug("[%s]resp_data=%s", fun_name(), resp_data)
+ instRespSerializer = InstScaleHealRespSerializer(data=resp_data)
+ if not instRespSerializer.is_valid():
+ raise Exception(instRespSerializer.errors)
+
+ return Response(data=instRespSerializer.data, status=status.HTTP_200_OK)
except Exception as e:
- logger.error("Error occurred when instantiating VNF")
- raise e
- return Response(data=resp_data, status=ret[2])
+ logger.error("Error occurred when instantiating VNF,error:%s", e.message)
+ logger.error(traceback.format_exc())
+ return Response(data={'error': 'InstantiateVnf expection'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class TerminateVnf(APIView):