summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-01-31 12:51:46 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2018-01-31 12:51:46 +0800
commit8f419382660590a85744d34c1532b5db3699fff6 (patch)
treef3881c9376ccdd5db58e6bda2cbe0b3f055303f7 /lcm
parentdf303570d4fcd8016cdb787a8586bc5a28faf908 (diff)
Add vfc-vnflcm terminate auto-swagger
Change-Id: I19982bb6d215cadbcfa9ac40724504454c6489d8 Issue-ID: VFC-682 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'lcm')
-rw-r--r--lcm/lcm/nf/vnfs/serializers.py9
-rw-r--r--lcm/lcm/nf/vnfs/views.py24
2 files changed, 25 insertions, 8 deletions
diff --git a/lcm/lcm/nf/vnfs/serializers.py b/lcm/lcm/nf/vnfs/serializers.py
index 2516bc9d..66867bae 100644
--- a/lcm/lcm/nf/vnfs/serializers.py
+++ b/lcm/lcm/nf/vnfs/serializers.py
@@ -264,5 +264,12 @@ class InstantiateVnfRequestSerializer(serializers.Serializer):
help_text="additionalParams", required=False, allow_null=True)
-class InstantiateVnfResponseSerializer(serializers.Serializer):
+class InstOrTeriVnfResponseSerializer(serializers.Serializer):
jobId = serializers.CharField(help_text="jobId", required=True)
+
+
+class TerminateVnfRequestSerializer(serializers.Serializer):
+ terminationType = serializers.CharField(
+ help_text="terminationType", required=True)
+ gracefulTerminationTimeout = serializers.IntegerField(
+ help_text="gracefulTerminationTimeout", default=120, required=False)
diff --git a/lcm/lcm/nf/vnfs/views.py b/lcm/lcm/nf/vnfs/views.py
index 9f385a0f..97448812 100644
--- a/lcm/lcm/nf/vnfs/views.py
+++ b/lcm/lcm/nf/vnfs/views.py
@@ -21,7 +21,7 @@ from rest_framework.response import Response
from rest_framework.views import APIView
from lcm.nf.vnfs.serializers import CreateVnfReqSerializer, CreateVnfRespSerializer, VnfsInfoSerializer, \
- InstantiateVnfResponseSerializer, InstantiateVnfRequestSerializer, VnfInfoSerializer
+ InstOrTeriVnfResponseSerializer, InstantiateVnfRequestSerializer, VnfInfoSerializer, TerminateVnfRequestSerializer
from lcm.nf.vnfs.vnf_cancel.delete_vnf_identifier import DeleteVnf
from lcm.nf.vnfs.vnf_cancel.term_vnf import TermVnf
from lcm.nf.vnfs.vnf_create.create_vnf_identifier import CreateVnf
@@ -94,7 +94,7 @@ class InstantiateVnf(APIView):
@swagger_auto_schema(
request_body=InstantiateVnfRequestSerializer(),
responses={
- status.HTTP_202_ACCEPTED: InstantiateVnfResponseSerializer(),
+ status.HTTP_202_ACCEPTED: InstOrTeriVnfResponseSerializer(),
status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
}
)
@@ -110,7 +110,7 @@ class InstantiateVnf(APIView):
JobUtil.add_job_status(job_id, 0, "INST_VNF_READY")
InstVnf(instantiateVnfRequestSerializer.data, instanceid, job_id).start()
- instantiateVnfResponseSerializer = InstantiateVnfResponseSerializer(data={"jobId": job_id})
+ instantiateVnfResponseSerializer = InstOrTeriVnfResponseSerializer(data={"jobId": job_id})
resp_isValid = instantiateVnfResponseSerializer.is_valid()
if not resp_isValid:
raise NFLCMException(instantiateVnfResponseSerializer.errors)
@@ -174,12 +174,26 @@ class DeleteVnfAndQueryVnf(APIView):
class TerminateVnf(APIView):
+ @swagger_auto_schema(
+ request_body=TerminateVnfRequestSerializer(),
+ responses={
+ status.HTTP_202_ACCEPTED: InstOrTeriVnfResponseSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ }
+ )
def post(self, request, instanceid):
logger.debug("TerminateVnf--post::> %s" % request.data)
try:
job_id = JobUtil.create_job('NF', 'TERMINATE', instanceid)
JobUtil.add_job_status(job_id, 0, "TERM_VNF_READY")
TermVnf(request.data, instanceid, job_id).start()
+
+ terminateVnfResponseSerializer = InstOrTeriVnfResponseSerializer(data={"jobId": job_id})
+ resp_isValid = terminateVnfResponseSerializer.is_valid()
+ if not resp_isValid:
+ raise NFLCMException(terminateVnfResponseSerializer.errors)
+
+ return Response(data=terminateVnfResponseSerializer.data, status=status.HTTP_202_ACCEPTED)
except NFLCMException as e:
logger.error(e.message)
return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@@ -187,7 +201,3 @@ class TerminateVnf(APIView):
logger.error(e.message)
logger.error(traceback.format_exc())
return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
- rsp = {
- "jobId": job_id
- }
- return Response(data=rsp, status=status.HTTP_202_ACCEPTED)