Add code of delete vnf instance
authorying.yunlong <ying.yunlong@zte.com.cn>
Tue, 14 Feb 2017 09:17:58 +0000 (17:17 +0800)
committerying.yunlong <ying.yunlong@zte.com.cn>
Tue, 14 Feb 2017 09:17:58 +0000 (17:17 +0800)
Change-Id: Ie1efc3a53e2bb4ef05952bb77de95638ce55447c
Issue-Id: GVNFM-11
Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py [new file with mode: 0644]
lcm/lcm/nf/vnfs/views.py
lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py

diff --git a/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py b/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py
new file mode 100644 (file)
index 0000000..650d17e
--- /dev/null
@@ -0,0 +1,13 @@
+# Copyright 2017 ZTE Corporation.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
\ No newline at end of file
index f03e4bc..481f308 100644 (file)
@@ -20,6 +20,7 @@ from rest_framework import status
 from rest_framework.response import Response
 from rest_framework.views import APIView
 
+from lcm.nf.vnfs.vnf_cancel.delete_vnf_identifier import DeleteVnf
 from lcm.nf.vnfs.vnf_create.create_vnf_identifier import CreateVnf
 from lcm.nf.vnfs.vnf_create.inst_vnf import InstVnf
 from lcm.pub.exceptions import NFLCMException
@@ -54,9 +55,17 @@ class InstantiateVnf(APIView):
 
 
 class DeleteVnfIdentifier(APIView):
-    def delete(self, request):
+    def delete(self, request, instanceId):
         logger.debug("DeleteVnfIdentifier--delete::> %s" % request.data)
-        return Response(data='', status=status.HTTP_204_NO_CONTENT)
+        try:
+            DeleteVnf(request.data, instanceId).do_biz()
+        except NFLCMException as e:
+            logger.error(e.message)
+            return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+        except Exception:
+            logger.error(traceback.format_exc())
+            return Response(data={'error': 'unexpected exception'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+        return Response(data={}, status=status.HTTP_204_NO_CONTENT)
 
 
 class TerminateVnf(APIView):
index 650d17e..107d9ab 100644 (file)
 # distributed under the License is distributed on an "AS IS" BASIS,
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
-# limitations under the License.
\ No newline at end of file
+# limitations under the License.
+from lcm.pub.database.models import NfInstModel
+from lcm.pub.exceptions import NFLCMException
+
+
+class DeleteVnf:
+    def __init__(self, data, instanceId):
+        self.data = data
+        self.nf_inst_id = instanceId
+
+    def do_biz(self):
+        sel_vnfs = NfInstModel.objects.filter(pk=self.nf_inst_id)
+        if not sel_vnfs.exists():
+            raise NFLCMException('VnfInst(%s) does not exist.' % self.nf_inst_id)
+        sel_vnf = sel_vnfs[0]
+        if sel_vnf.instantiationState != 'VNF_INSTANTIATED':
+            raise NFLCMException("No instantiated vnf")
+        pass
\ No newline at end of file