change the ETSI package directory name from the “ONBOARDED_PACKAGE” to “ETSI_PACKAGE"
[modeling/etsicatalog.git] / catalog / packages / biz / sdc_vnf_package.py
index 5f62d7e..7c9d547 100644 (file)
@@ -21,7 +21,7 @@ import traceback
 import zipfile
 
 from catalog.packages.biz.vnf_package import VnfPackage
-from catalog.packages.const import PKG_STATUS
+from catalog.packages import const
 from catalog.pub.config.config import CATALOG_ROOT_PATH, CATALOG_URL_PATH
 from catalog.pub.config.config import REG_TO_MSB_REG_PARAM
 from catalog.pub.database.models import VnfPackageModel
@@ -30,6 +30,7 @@ from catalog.pub.msapi import sdc
 from catalog.pub.utils import fileutil
 from catalog.pub.utils import toscaparser
 from catalog.pub.utils.jobutil import JobUtil, JOB_ERROR_CODE
+from catalog.packages.biz.notificationsutil import PkgNotifications
 
 logger = logging.getLogger(__name__)
 
@@ -130,12 +131,12 @@ class NfDistributeThread(threading.Thread):
         if local_file_name.endswith(".csar") or local_file_name.endswith(".zip"):
             fileutil.unzip_csar(local_file_name, local_path)
             vendor_vnf_file = ''
-            # find original vendor ETSI package under the ONBOARDING_PACKAGE directory
-            onboarding_package_dir = os.path.join(local_path, "Artifacts/Deployment/ONBOARDED_PACKAGE")
-            if os.path.exists(onboarding_package_dir):
-                files = os.listdir(onboarding_package_dir)
+            # find original vendor ETSI package under the ETSI_PACKAGE directory
+            etsi_package_dir = os.path.join(local_path, "Artifacts/Deployment/ETSI_PACKAGE")
+            if os.path.exists(etsi_package_dir):
+                files = os.listdir(etsi_package_dir)
                 for file_name in files:
-                    a_file = os.path.join(onboarding_package_dir, file_name)
+                    a_file = os.path.join(etsi_package_dir, file_name)
                     if os.path.isfile(a_file) & file_name.endswith(".csar"):
                         vendor_vnf_file = a_file
                         break
@@ -176,11 +177,13 @@ class NfDistributeThread(threading.Thread):
             vnfdModel=vnfd_json,
             localFilePath=local_file_name,
             vnfPackageUri=csar_name,
-            onboardingState=PKG_STATUS.ONBOARDED,
-            operationalState=PKG_STATUS.ENABLED,
-            usageState=PKG_STATUS.NOT_IN_USE
+            onboardingState=const.PKG_STATUS.ONBOARDED,
+            operationalState=const.PKG_STATUS.ENABLED,
+            usageState=const.PKG_STATUS.NOT_IN_USE
         ).save()
         JobUtil.add_job_status(self.job_id, 100, "CSAR(%s) distribute successfully." % self.csar_id)
+        send_notification(self.csar_id, const.PKG_NOTIFICATION_TYPE.ONBOARDING,
+                          const.PKG_CHANGE_TYPE.OP_STATE_CHANGE)
 
     def create_vnfd_zip(self, csar_id, vendor_vnf_file):
         """
@@ -246,7 +249,8 @@ class NfPkgDeleteThread(threading.Thread):
             inst_id=self.csar_id,
             job_id=self.job_id)
         JobUtil.add_job_status(self.job_id, 5, "Start to delete CSAR(%s)." % self.csar_id)
-
+        send_notification(self.csar_id, const.PKG_NOTIFICATION_TYPE.CHANGE,
+                          const.PKG_CHANGE_TYPE.PKG_DELETE)
         VnfPackageModel.objects.filter(vnfPackageId=self.csar_id).delete()
 
         JobUtil.add_job_status(self.job_id, 50, "Delete local CSAR(%s) file." % self.csar_id)
@@ -303,3 +307,9 @@ class NfPackage(object):
             "imageInfo": []
         }
         return [0, csar_info]
+
+
+def send_notification(pkg_id, type, pkg_change_type, operational_state=None):
+    notify = PkgNotifications(type, pkg_id, change_type=pkg_change_type,
+                              operational_state=operational_state)
+    notify.send_notification()