summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2017-02-14 17:17:58 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2017-02-14 17:17:58 +0800
commit9f34de4930b7afa5ba6c1da61a5dedc0b2fa5d92 (patch)
treed0ea91aa2ac0af43a6d3a4ce7ac016a7f8600989
parent292f01ff313671718e9135689e5517be1c397d39 (diff)
Add code of delete vnf instance
Change-Id: Ie1efc3a53e2bb4ef05952bb77de95638ce55447c Issue-Id: GVNFM-11 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
-rw-r--r--lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py13
-rw-r--r--lcm/lcm/nf/vnfs/views.py13
-rw-r--r--lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py19
3 files changed, 42 insertions, 3 deletions
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
index 00000000..650d17ec
--- /dev/null
+++ b/lcm/lcm/nf/vnfs/tests/test_vnf_cancel.py
@@ -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
diff --git a/lcm/lcm/nf/vnfs/views.py b/lcm/lcm/nf/vnfs/views.py
index f03e4bcf..481f308c 100644
--- a/lcm/lcm/nf/vnfs/views.py
+++ b/lcm/lcm/nf/vnfs/views.py
@@ -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):
diff --git a/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py b/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py
index 650d17ec..107d9ab5 100644
--- a/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py
+++ b/lcm/lcm/nf/vnfs/vnf_cancel/delete_vnf_identifier.py
@@ -10,4 +10,21 @@
# 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