summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlaili <lai.li@zte.com.cn>2018-09-11 13:42:31 +0800
committerlaili <lai.li@zte.com.cn>2018-09-11 13:42:31 +0800
commit43323b9afbff2e8a5892b0837a3cfa4ce16e2c85 (patch)
treea8b614450204f317c51a28f7ce1861f67f93e863
parent040b4afd4e863f466b2e9a57006e7d14345ebc21 (diff)
Notification endpoint stuffs.
- Add vnf identifier creation/deletion notification handler. Change-Id: I53f18483b55d2ce681a17ef49d478c3421392a0f Issue-ID: VFC-1095 Signed-off-by: laili <lai.li@zte.com.cn>
-rw-r--r--lcm/ns_vnfs/biz/handle_notification.py (renamed from lcm/ns_vnfs/biz/handle_vnflcmooc_notification.py)50
-rw-r--r--lcm/ns_vnfs/serializers/grant_vnf_serializer.py35
-rw-r--r--lcm/ns_vnfs/tests/vnf_tests.py (renamed from lcm/ns_vnfs/tests/grant_vnf_test.py)2
-rw-r--r--lcm/ns_vnfs/urls.py2
-rw-r--r--lcm/ns_vnfs/views/vnf_views.py (renamed from lcm/ns_vnfs/views/grant_vnf_views.py)33
5 files changed, 94 insertions, 28 deletions
diff --git a/lcm/ns_vnfs/biz/handle_vnflcmooc_notification.py b/lcm/ns_vnfs/biz/handle_notification.py
index e8a36fb4..5ba685bc 100644
--- a/lcm/ns_vnfs/biz/handle_vnflcmooc_notification.py
+++ b/lcm/ns_vnfs/biz/handle_notification.py
@@ -36,9 +36,9 @@ logger = logging.getLogger(__name__)
class HandleVnfLcmOocNotification(object):
def __init__(self, vnfmid, vnfInstanceId, data):
logger.debug("[Notify LCM] vnfmid=%s, vnfInstanceId=%s, data=%s" % (vnfmid, vnfInstanceId, data))
- self.vnf_instid = ''
self.vnfmid = vnfmid
self.m_vnfInstanceId = vnfInstanceId
+ self.vnf_instid = self.get_vnfinstid(self.m_vnfInstanceId, self.vnfmid)
self.operation = ignore_case_get(data, 'operation')
self.affectedVnfcs = ignore_case_get(data, 'affectedVnfcs')
self.affectedVls = ignore_case_get(data, 'affectedVls')
@@ -47,7 +47,6 @@ class HandleVnfLcmOocNotification(object):
def do_biz(self):
try:
- self.vnf_instid = self.get_vnfinstid(self.m_vnfInstanceId, self.vnfmid)
self.update_Vnfc()
self.update_Vl()
self.update_Cp()
@@ -181,7 +180,7 @@ class HandleVnfLcmOocNotification(object):
logger.error('affectedVl struct error: resourceType not euqal network')
raise NSLCMException("affectedVl struct error: resourceType not euqal network")
- ownerId = self.get_vnfinstid(self.m_vnfInstanceId, self.vnfmid)
+ ownerId = self.vnf_instid
if changeType in ['ADDED', 'MODIFIED']:
self.create_network_and_subnet_in_aai(vlInstanceId, ownerId)
@@ -304,3 +303,48 @@ class HandleVnfLcmOocNotification(object):
logger.debug("Fail to delete vserver from aai, detail message: %s" % e.message)
except:
logger.error(traceback.format_exc())
+
+
+class HandleVnfIdentifierCreationNotification(object):
+ def __init__(self, vnfmId, vnfInstanceId, data):
+ logger.debug("[Notify VNF Identifier Creation] vnfmId=%s, vnfInstanceId=%s, data=%s" % (vnfmId, vnfInstanceId, data))
+ self.vnfm_id = vnfmId
+ self.m_vnf_instance_id = vnfInstanceId
+ self.time_stamp = ignore_case_get(data, 'timeStamp')
+ # TODO: self.subscription_id = ignore_case_get(data, 'subscriptionId')
+ # TODO: self._links = ignore_case_get(data, '_links')
+
+ def do_biz(self):
+ try:
+ NfInstModel(
+ nfinstid=str(uuid.uuid4()),
+ mnfinstid=self.m_vnf_instance_id,
+ vnfm_inst_id=self.vnfm_id,
+ create_time=self.time_stamp
+ ).save()
+ logger.debug("Notify VNF identifier creation end.")
+ except Exception:
+ logger.error(traceback.format_exc())
+ self.exception('unexpected exception')
+
+
+class HandleVnfIdentifierDeletionNotification(object):
+ def __init__(self, vnfmId, vnfInstanceId, data):
+ logger.debug("[Notify VNF Identifier Deletion] vnfmId=%s, vnfInstanceId=%s, data=%s" % (vnfmId, vnfInstanceId, data))
+ self.vnfm_id = vnfmId
+ self.m_vnf_instance_id = vnfInstanceId
+ self.vnf_instance_id = self.get_vnfinstid(self.m_vnfInstanceId, self.vnfmid)
+ self.time_stamp = ignore_case_get(data, 'timeStamp')
+ # TODO: self.subscription_id = ignore_case_get(data, 'subscriptionId')
+ # TODO: self._links = ignore_case_get(data, '_links')
+
+ def do_biz(self):
+ try:
+ nf_insts = NfInstModel.objects.filter(
+ mnfinstid=self.m_vnf_instance_id, vnfm_inst_id=self.vnfm_id)
+ if nf_insts.exists():
+ nf_insts.delete()
+ logger.debug("Notify VNF identifier deletion end.")
+ except Exception:
+ logger.error(traceback.format_exc())
+ self.exception('unexpected exception')
diff --git a/lcm/ns_vnfs/serializers/grant_vnf_serializer.py b/lcm/ns_vnfs/serializers/grant_vnf_serializer.py
index f140e666..2325c83b 100644
--- a/lcm/ns_vnfs/serializers/grant_vnf_serializer.py
+++ b/lcm/ns_vnfs/serializers/grant_vnf_serializer.py
@@ -932,8 +932,13 @@ class VnfLcmOperationOccurrenceNotificationSerializer(serializers.Serializer):
help_text="Identifier of this notification.",
required=True
)
- notificationType = serializers.CharField(
+ notificationType = serializers.ChoiceField(
help_text="Discriminator for the different notification types.",
+ choices=[
+ 'VnfLcmOperationOccurrenceNotification',
+ 'VnfIdentifierCreationNotification',
+ 'VnfIdentifierDeletionNotification'
+ ],
required=True
)
subscriptionId = serializers.CharField(
@@ -1017,12 +1022,14 @@ class VnfIdentifierCreationNotificationSerializer(serializers.Serializer):
allow_null=False,
allow_blank=False
)
- notificationType = serializers.CharField(
- help_text="Discriminator for the different notification types. \
- Shall be set to VnfIdentifierCreationNotification for this notification type.",
- required=True,
- allow_null=False,
- allow_blank=False
+ notificationType = serializers.ChoiceField(
+ help_text="Discriminator for the different notification types.",
+ choices=[
+ 'VnfLcmOperationOccurrenceNotification',
+ 'VnfIdentifierCreationNotification',
+ 'VnfIdentifierDeletionNotification'
+ ],
+ required=True
)
subscriptionId = serializers.CharField(
help_text="Identifier of the subscription that this notification relates to.",
@@ -1058,12 +1065,14 @@ class VnfIdentifierDeletionNotificationSerializer(serializers.Serializer):
allow_null=False,
allow_blank=False
)
- notificationType = serializers.CharField(
- help_text="Discriminator for the different notification types. \
- Shall be set to VnfIdentifierDeletionNotification for this notification type.",
- required=True,
- allow_null=False,
- allow_blank=False
+ notificationType = serializers.ChoiceField(
+ help_text="Discriminator for the different notification types.",
+ choices=[
+ 'VnfLcmOperationOccurrenceNotification',
+ 'VnfIdentifierCreationNotification',
+ 'VnfIdentifierDeletionNotification'
+ ],
+ required=True
)
subscriptionId = serializers.CharField(
help_text="Identifier of the subscription that this notification relates to.",
diff --git a/lcm/ns_vnfs/tests/grant_vnf_test.py b/lcm/ns_vnfs/tests/vnf_tests.py
index ce655de9..3b3bddcd 100644
--- a/lcm/ns_vnfs/tests/grant_vnf_test.py
+++ b/lcm/ns_vnfs/tests/vnf_tests.py
@@ -281,7 +281,7 @@ class VnfGrantViewTest(unittest.TestCase):
def test_notify_vnf_normal(self):
data = {
"id": "string",
- "notificationType": "string",
+ "notificationType": "VnfLcmOperationOccurrenceNotification",
"subscriptionId": "string",
"timeStamp": "string",
"notificationStatus": "START",
diff --git a/lcm/ns_vnfs/urls.py b/lcm/ns_vnfs/urls.py
index f3f2e3e5..ce972efa 100644
--- a/lcm/ns_vnfs/urls.py
+++ b/lcm/ns_vnfs/urls.py
@@ -17,7 +17,7 @@ from rest_framework.urlpatterns import format_suffix_patterns
from lcm.ns_vnfs.views.views import LcmNotify, NfScaleView, NfVerifyView
from lcm.ns_vnfs.views.views import NfView, NfDetailView, NfGrant, NfPlacement, NfTerminate
from lcm.ns_vnfs.views.views import NfVnfmInfoView, NfVimInfoView
-from lcm.ns_vnfs.views.grant_vnf_views import VnfGrantView, VnfNotifyView
+from lcm.ns_vnfs.views.vnf_views import VnfGrantView, VnfNotifyView
urlpatterns = [
url(r'^api/nslcm/v1/ns/vnfs$', NfView.as_view()),
diff --git a/lcm/ns_vnfs/views/grant_vnf_views.py b/lcm/ns_vnfs/views/vnf_views.py
index aa4fd32e..a672ed5f 100644
--- a/lcm/ns_vnfs/views/grant_vnf_views.py
+++ b/lcm/ns_vnfs/views/vnf_views.py
@@ -20,10 +20,10 @@ from rest_framework.response import Response
from rest_framework.views import APIView
from lcm.ns_vnfs.biz.grant_vnf import GrantVnf
-from lcm.ns_vnfs.biz.handle_vnflcmooc_notification import HandleVnfLcmOocNotification
+from lcm.ns_vnfs.biz.handle_notification import HandleVnfLcmOocNotification, HandleVnfIdentifierCreationNotification, HandleVnfIdentifierDeletionNotification
from lcm.ns_vnfs.serializers.grant_vnf_serializer import GrantRequestSerializer
from lcm.ns_vnfs.serializers.grant_vnf_serializer import GrantSerializer
-from lcm.ns_vnfs.serializers.grant_vnf_serializer import VnfLcmOperationOccurrenceNotificationSerializer
+from lcm.ns_vnfs.serializers.grant_vnf_serializer import VnfLcmOperationOccurrenceNotificationSerializer, VnfIdentifierCreationNotificationSerializer, VnfIdentifierDeletionNotificationSerializer
logger = logging.getLogger(__name__)
@@ -41,9 +41,9 @@ class VnfGrantView(APIView):
def post(self, request):
logger.debug("VnfGrantView Post: %s" % request.data)
try:
- req_serializer = GrantRequestSerializer(data=request.data)
- if not req_serializer.is_valid():
- raise Exception(req_serializer.errors)
+ grant_request = GrantRequestSerializer(data=request.data)
+ if not grant_request.is_valid():
+ raise Exception(grant_request.errors)
grant_resp = GrantVnf(request.data).exec_grant()
@@ -71,12 +71,25 @@ class VnfNotifyView(APIView):
def post(self, request, vnfmId, vnfInstanceId):
logger.debug("VnfNotifyView post: %s" % request.data)
logger.debug("vnfmId: %s vnfInstanceId: %s", vnfmId, vnfInstanceId)
+ notification_type = request.data['notificationType']
try:
- vnfLcmOocNotificationSerializer = VnfLcmOperationOccurrenceNotificationSerializer(data=request.data)
- if not vnfLcmOocNotificationSerializer.is_valid():
- raise Exception(vnfLcmOocNotificationSerializer.errors)
-
- HandleVnfLcmOocNotification(vnfmId, vnfInstanceId, vnfLcmOocNotificationSerializer.data).do_biz()
+ if notification_type == 'VnfLcmOperationOccurrenceNotification':
+ notification = VnfLcmOperationOccurrenceNotificationSerializer(data=request.data)
+ if not notification.is_valid():
+ raise Exception(notification.errors)
+ HandleVnfLcmOocNotification(vnfmId, vnfInstanceId, notification.data).do_biz()
+ elif notification_type == 'VnfIdentifierCreationNotification':
+ notification = VnfIdentifierCreationNotificationSerializer(data=request.data)
+ if not notification.is_valid():
+ raise Exception(notification.errors)
+ HandleVnfIdentifierCreationNotification(vnfmId, vnfInstanceId, notification.data).do_biz()
+ elif notification_type == 'VnfIdentifierDeletionNotification':
+ notification = VnfIdentifierDeletionNotificationSerializer(data=request.data)
+ if not notification.is_valid():
+ raise Exception(notification.errors)
+ HandleVnfIdentifierDeletionNotification(vnfmId, vnfInstanceId, notification.data).do_biz()
+ else:
+ raise Exception('Unexpected noitifcation type value.')
return Response(data={}, status=status.HTTP_204_NO_CONTENT)
except Exception as e:
logger.error(traceback.format_exc())