summaryrefslogtreecommitdiffstats
path: root/lcm/lcm/pub/msapi/gvnfmdriver.py
diff options
context:
space:
mode:
authorlaili <lai.li@zte.com.cn>2018-09-12 17:30:01 +0800
committerlaili <lai.li@zte.com.cn>2018-09-12 18:22:57 +0800
commit5729b6abb1a43319bfa419db6548ae8df6120479 (patch)
tree7fc093ebc032664b972a5ff20e7c06f1857fe5d7 /lcm/lcm/pub/msapi/gvnfmdriver.py
parent50ad0c42077b5ce1393396b2a3f376a961872124 (diff)
Notification stuffs.
- Send notification using notificationutil. Change-Id: I35fbc0b57adff499cabb4b956bbc6fb6e794ef38 Issue-ID: VFC-1095 Signed-off-by: laili <lai.li@zte.com.cn>
Diffstat (limited to 'lcm/lcm/pub/msapi/gvnfmdriver.py')
-rw-r--r--lcm/lcm/pub/msapi/gvnfmdriver.py46
1 files changed, 29 insertions, 17 deletions
diff --git a/lcm/lcm/pub/msapi/gvnfmdriver.py b/lcm/lcm/pub/msapi/gvnfmdriver.py
index 763b1974..a61227f1 100644
--- a/lcm/lcm/pub/msapi/gvnfmdriver.py
+++ b/lcm/lcm/pub/msapi/gvnfmdriver.py
@@ -1,22 +1,24 @@
# Copyright 2017 ZTE Corporation.
#
-# Licensed under the Apache License, Version 2.0 (the "License");
+# 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,
+# 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
+import uuid
from lcm.pub.exceptions import NFLCMException
from lcm.pub.utils.restcall import req_by_msb
+from lcm.pub.utils.timeutil import now_time
from lcm.pub.database.models import (
NfInstModel, VmInstModel, NetworkInstModel,
PortInstModel, StorageInstModel, VNFCInstModel
@@ -26,26 +28,26 @@ logger = logging.getLogger(__name__)
def get_packageinfo_by_vnfdid(vnfdid):
- ret = req_by_msb("api/gvnfmdriver/v1/vnfpackages", "GET")
+ ret = req_by_msb('api/gvnfmdriver/v1/vnfpackages', 'GET')
if ret[0] != 0:
- logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
- raise NFLCMException("Failed to query package_info of vnfdid(%s) from nslcm." % vnfdid)
+ logger.error('Status code is %s, detail is %s.', ret[2], ret[1])
+ raise NFLCMException('Failed to query package_info of vnfdid(%s) from nslcm.' % vnfdid)
return json.JSONDecoder().decode(ret[1])
def apply_grant_to_nfvo(data):
- ret = req_by_msb("api/gvnfmdriver/v1/resource/grant", "PUT", data)
+ ret = req_by_msb('api/gvnfmdriver/v1/resource/grant', 'PUT', data)
if ret[0] != 0:
- logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
- raise NFLCMException("Nf instancing apply grant exception")
+ logger.error('Status code is %s, detail is %s.', ret[2], ret[1])
+ raise NFLCMException('Nf instancing apply grant exception')
return json.JSONDecoder().decode(ret[1])
def notify_lcm_to_nfvo(data):
- ret = req_by_msb("api/gvnfmdriver/v1/vnfs/lifecyclechangesnotification", "POST", data)
+ ret = req_by_msb('api/gvnfmdriver/v1/vnfs/lifecyclechangesnotification', 'POST', data)
if ret[0] != 0:
- logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
- raise NFLCMException("Nf lcm notify exception")
+ logger.error('Status code is %s, detail is %s.', ret[2], ret[1])
+ raise NFLCMException('Nf lcm notify exception')
return ret[1]
@@ -113,11 +115,16 @@ def prepare_notification_data(nfinstid, jobid, changetype):
}
})
notification_content = {
- "notificationType": 'VnfLcmOperationOccurrenceNotification',
- "notificationStatus": 'RESULT',
- "vnfInstanceId": nfinstid,
- "operation": 'INSTANTIATE',
- "vnfLcmOpOccId": jobid,
+ 'id': str(uuid.uuid4()), # shall be the same if sent multiple times due to multiple subscriptions.
+ 'notificationType': 'VnfLcmOperationOccurrenceNotification',
+ # set 'subscriptionId' after filtering for subscribers
+ 'timeStamp': now_time(),
+ 'notificationStatus': 'RESULT',
+ 'operationState': 'COMPLETED',
+ 'vnfInstanceId': nfinstid,
+ 'operation': 'INSTANTIATE',
+ 'isAutomaticInvocation': False,
+ 'vnfLcmOpOccId': jobid,
'affectedVnfcs': affected_vnfcs,
'affectedVirtualLinks': affected_vls,
'affectedVirtualStorages': affected_vss,
@@ -125,7 +132,12 @@ def prepare_notification_data(nfinstid, jobid, changetype):
'id': None, # TODO
'resourceHandle': None, # TODO
'extLinkPorts': ext_link_ports
- }]
+ }],
+ '_links': {
+ 'vnfInstance': {'href': '/api/vnflcm/v1/vnf_instances/%s' % nfinstid},
+ # set 'subscription' link after filtering for subscribers
+ 'vnfLcmOpOcc': {'href': '/api/vnflcm/v1/vnf_lcm_op_occs/%s' % jobid}
+ }
}
nfInsts = NfInstModel.objects.filter(nfinstid=nfinstid)
notification_content['vnfmInstId'] = nfInsts[0].vnfminstid