summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lcm/ns/vnfs/notify_lcm.py87
1 files changed, 87 insertions, 0 deletions
diff --git a/lcm/ns/vnfs/notify_lcm.py b/lcm/ns/vnfs/notify_lcm.py
index 3c23a4ee..b51b490f 100644
--- a/lcm/ns/vnfs/notify_lcm.py
+++ b/lcm/ns/vnfs/notify_lcm.py
@@ -18,8 +18,10 @@ import traceback
from rest_framework import status
from rest_framework.response import Response
from lcm.ns.vnfs.const import INST_TYPE
+from lcm.pub.config.config import REPORT_TO_AAI
from lcm.pub.exceptions import NSLCMException
from lcm.pub.database.models import VNFCInstModel, VLInstModel, NfInstModel, PortInstModel, CPInstModel, VmInstModel
+from lcm.pub.msapi.aai import create_network_aai, query_network_aai, delete_network_aai
from lcm.pub.utils.values import ignore_case_get
@@ -48,6 +50,8 @@ class NotifyLcm(object):
self.update_Vl()
self.update_Cp()
self.update_Storage()
+ if REPORT_TO_AAI:
+ self.update_network_in_aai()
logger.debug("notify lcm end")
except NSLCMException as e:
self.exception(e.message)
@@ -161,3 +165,86 @@ class NotifyLcm(object):
def update_vnf_by_vnfdmodule(self):
NfInstModel.objects.filter(nfinstid=self.vnf_instid).update(vnfd_model=self.vnfdmodule)
+
+ def update_network_in_aai(self):
+ logger.debug("update_network_in_aai::begin to report network to aai.")
+ try:
+ for vl in self.affectedVl:
+ vlInstanceId = ignore_case_get(vl, 'vlInstanceId')
+ # vldid = ignore_case_get(vl, 'vldid')
+ changeType = ignore_case_get(vl, 'changeType')
+ networkResource = ignore_case_get(vl, 'networkResource')
+ resourceType = ignore_case_get(networkResource, 'resourceType')
+ # resourceId = ignore_case_get(networkResource, 'resourceId')
+
+ if resourceType != 'network':
+ logger.error('affectedVl struct error: resourceType not euqal network')
+ raise NSLCMException("affectedVl struct error: resourceType not euqal network")
+
+ # ownerId = self.vnf_instid
+ ownerId = self.get_vnfinstid(self.vnf_instid, self.vnfmid)
+
+ if changeType in ['added', 'modified']:
+ self.create_network_and_subnet_in_aai(vlInstanceId, ownerId)
+ elif changeType == 'removed':
+ self.delete_network_and_subnet_in_aai(vlInstanceId)
+ else:
+ logger.error('affectedVl struct error: changeType not in {added,removed,modified}')
+ except NSLCMException as e:
+ logger.debug("Fail to create internal network to aai, detail message: %s" % e.message)
+ except:
+ logger.error(traceback.format_exc())
+
+ def create_network_and_subnet_in_aai(self, vlInstanceId, ownerId):
+ logger.debug("CreateVls::create_network_in_aai::report network[%s] to aai." % vlInstanceId)
+ try:
+ data = {
+ "network-id": vlInstanceId,
+ "network-name": vlInstanceId,
+ "is-bound-to-vpn": False,
+ "is-provider-network": True,
+ "is-shared-network": True,
+ "is-external-network": True,
+ "relationship-list": {
+ "relationship": [
+ {
+ "related-to": "generic-vnf",
+ "relationship-data": [
+ {
+ "relationship-key": "generic-vnf.vnf-id",
+ "relationship-value": ownerId
+ }
+ ]
+ }
+ ]
+ }
+ }
+ resp_data, resp_status = create_network_aai(vlInstanceId, data)
+ if resp_data:
+ logger.debug("Fail to create network[%s] to aai: [%s].", vlInstanceId, resp_status)
+ else:
+ logger.debug("Success to create network[%s] to aai: [%s].", vlInstanceId, resp_status)
+ except NSLCMException as e:
+ logger.debug("Fail to create network[%s] to aai, detail message: %s" % (vlInstanceId, e.message))
+ except:
+ logger.error(traceback.format_exc())
+
+ def delete_network_and_subnet_in_aai(self, vlInstanceId):
+ logger.debug("DeleteVls::delete_network_in_aai::delete network[%s] in aai." % vlInstanceId)
+ try:
+ # query network in aai, get resource_version
+ customer_info = query_network_aai(vlInstanceId)
+ resource_version = customer_info["resource-version"]
+
+ # delete network from aai
+ resp_data, resp_status = delete_network_aai(vlInstanceId, resource_version)
+ if resp_data:
+ logger.debug("Fail to delete network[%s] from aai, resp_status: [%s]."
+ % (vlInstanceId, resp_status))
+ else:
+ logger.debug("Success to delete network[%s] from aai, resp_status: [%s]."
+ % (vlInstanceId, resp_status))
+ except NSLCMException as e:
+ logger.debug("Fail to delete network[%s] to aai, detail message: %s" % (vlInstanceId, e.message))
+ except:
+ logger.error(traceback.format_exc())