from lcm.ns_vnfs.const import VNF_STATUS, NFVO_VNF_INST_TIMEOUT_SECOND, INST_TYPE, INST_TYPE_NAME
from lcm.ns_vnfs.biz.wait_job import wait_job_finish
from lcm.pub.config.config import REG_TO_MSB_REG_PARAM, OOF_BASE_URL, OOF_PASSWD, OOF_USER
+from lcm.ns_vnfs.biz.subscribe import Subscription
logger = logging.getLogger(__name__)
self.send_get_vnfm_request_to_extsys()
self.send_create_vnf_request_to_resmgr()
self.wait_vnfm_job_finish()
+ self.subscribe()
self.write_vnf_creation_info()
self.save_info_to_db()
JobUtil.add_job_status(self.job_id, 100, 'vnf instantiation success', 0)
logger.error('VNF instantiation failed on VNFM side. ret=[%s]', ret)
raise NSLCMException('VNF instantiation failed on VNFM side.')
+ def subscribe(self):
+ data = {
+ 'vnfInstanceId': self.vnfm_nf_inst_id,
+ 'vnfmId': self.vnfm_inst_id
+ }
+ Subscription(data).do_biz()
+
def write_vnf_creation_info(self):
logger.debug("write_vnf_creation_info start")
vm_inst_infos = VmInstModel.objects.filter(insttype=INST_TYPE.VNF, instid=self.nf_inst_id)
--- /dev/null
+# Copyright 2018 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.
+
+import json
+import logging
+
+from lcm.pub.exceptions import NSLCMException
+from lcm.pub.msapi.extsys import get_vnfm_by_id
+from lcm.pub.utils.restcall import req_by_msb
+
+logger = logging.getLogger(__name__)
+
+
+class Subscription(object):
+ def __init__(self, data):
+ self.data = data
+ self.vnf_instance_id = self.data['vnfInstanceId']
+ self.vnfm_id = self.data['vnfmId']
+ self.subscription_request_data = {}
+ self.subscription_response_data = {}
+ pass
+
+ def do_biz(self):
+ logger.debug('Start subscribing...')
+ self.prepare_subscription_request_data()
+ self.subscribe_lccn_notification()
+ self.save_subscription_response_data()
+ logger.debug('Subscribing has completed.')
+
+ def prepare_lccn_subscription_request_data(self):
+ vnfm_info = get_vnfm_by_id(self.vnfm_id)
+ self.subscription_request_data = {
+ "filter": {
+ "notificationTypes": ["VnfLcmOperationOccurrenceNotification"],
+ "operationTypes": [
+ "INSTANTIATE",
+ "SCALE",
+ "SCALE_TO_LEVEL",
+ "CHANGE_FLAVOUR",
+ "TERMINATE",
+ "HEAL",
+ "OPERATE",
+ "CHANGE_EXT_CONN",
+ "MODIFY_INFO"
+ ],
+ "operationStates": [
+ "STARTING",
+ "PROCESSING",
+ "COMPLETED",
+ "FAILED_TEMP",
+ "FAILED",
+ "ROLLING_BACK",
+ "ROLLED_BACK"
+ ],
+ "vnfInstanceSubscriptionFilter": {
+ "vnfdIds": [],
+ "vnfInstanceIds": [self.vnf_instance_id],
+ "vnfInstanceNames": [],
+ "vnfProductsFromProviders": {}
+ }
+ },
+ "callbackUri": "api/gvnfmdriver/v1/vnfs/lifecyclechangesnotification", # TODO: need reconfirming
+ "authentication": {
+ "authType": ["BASIC"],
+ "paramsBasic": {
+ "userName": vnfm_info['userName'],
+ "password": vnfm_info['password']
+ }
+ }
+ }
+
+ def subscribe_lccn_notification(self):
+ ret = req_by_msb('api/gvnfmdrvier/v1/%s/subscriptions' % self.vnfm_id, self.subscription_request_data)
+ if ret[0] != 0:
+ logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
+ raise NSLCMException("Failed to subscribe from vnfm(%s)." % self.vnfm_id)
+ self.subscription_response_data = json.JSONDecoder().decode(ret[1])
+
+ def save_subscription_response_data(self):
+ pass
allow_null=True,
allow_blank=True
)
- timeStamp = serializers.DateField(
+ timeStamp = serializers.DateTimeField(
help_text="Date-time of the generation of the notification.",
required=True,
allow_null=False,
allow_null=True,
allow_blank=True
)
- timeStamp = serializers.DateField(
+ timeStamp = serializers.DateTimeField(
help_text="Date-time of the generation of the notification.",
required=True,
allow_null=False,
'id': 'Identifier of this notification',
'notificationType': 'VnfIdentifierCreationNotification',
'subscriptionId': 'Identifier of the subscription',
- 'timeStamp': '2018-9-11',
+ 'timeStamp': '2018-9-12T00:00:00',
'vnfInstanceId': '2',
'_links': {
'vnfInstance': {'href': 'URI of the referenced resource'},
'id': 'Identifier of this notification',
'notificationType': 'VnfIdentifierDeletionNotification',
'subscriptionId': 'Identifier of the subscription',
- 'timeStamp': '2018-9-11',
+ 'timeStamp': '2018-9-12T00:00:00',
'vnfInstanceId': '2',
'_links': {
'vnfInstance': {'href': 'URI of the referenced resource'},
# 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.
+
import logging
import traceback
from rest_framework.views import APIView
from lcm.ns_vnfs.biz.grant_vnf import GrantVnf
-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.biz.handle_notification import HandleVnfLcmOocNotification, HandleVnfIdentifierCreationNotification, HandleVnfIdentifierDeletionNotification
from lcm.ns_vnfs.serializers.grant_vnf_serializer import VnfLcmOperationOccurrenceNotificationSerializer, VnfIdentifierCreationNotificationSerializer, VnfIdentifierDeletionNotificationSerializer
logger = logging.getLogger(__name__)