Ns descriptor related stuffs. 07/62107/2
authorlaili <lai.li@zte.com.cn>
Thu, 23 Aug 2018 12:52:15 +0000 (20:52 +0800)
committerLi Lai <lai.li@zte.com.cn>
Fri, 24 Aug 2018 05:31:05 +0000 (05:31 +0000)
Implement pnfd content process.

Change-Id: I074f503e98e973de525d7340e62d959b1f2d0086
Issue-ID: VFC-1037
Signed-off-by: laili <lai.li@zte.com.cn>
catalog/packages/biz/pnf_descriptor.py
catalog/pub/utils/toscaparser/__init__.py

index 87b6978..7481291 100644 (file)
@@ -23,6 +23,7 @@ from catalog.pub.utils import fileutil
 from catalog.pub.utils.values import ignore_case_get
 from catalog.pub.database.models import PnfPackageModel
 from catalog.pub.exceptions import CatalogException
+from catalog.pub.utils import toscaparser
 
 logger = logging.getLogger(__name__)
 
@@ -72,6 +73,28 @@ def query_multiple():
     return response_data
 
 
+def process(pnfd_info_id, local_file_name):  # TODO: onboardingState changes
+    pnfd_json = toscaparser.parse_pnfd(local_file_name)
+    pnfd = json.JSONDecoder().decode(pnfd_json)
+
+    pnfd_id = pnfd["metadata"]["id"]
+    if pnfd_id and PnfPackageModel.objects.filter(pnfdId=pnfd_id):  # pnfd_id may not exist
+        raise CatalogException("NS Descriptor (%s) already exists." % pnfd_id)
+
+    PnfPackageModel(
+        pnfPackageId=pnfd_info_id,
+        pnfdId=pnfd_id,
+        pnfdName=pnfd["metadata"].get("name", pnfd_id),
+        pnfdDesginer=pnfd["metadata"].get("vendor", "undefined"),
+        pnfdDescription=pnfd["metadata"].get("description", ""),
+        pnfdVersion=pnfd["metadata"].get("version", "undefined"),
+        nsPackageUri=local_file_name,  # TODO
+        sdcCsarId=pnfd_info_id,
+        localFilePath=local_file_name,
+        pnfdModel=pnfd_json
+    ).save()
+
+
 def upload(files, pnfd_info_id):
     remote_files = files
     for remote_file in remote_files:
index 56c020e..604bb23 100644 (file)
@@ -30,3 +30,7 @@ def parse_vnfd(path, input_parameters=[]):
     strResponse = json.dumps(tosca_obj, default=lambda obj: obj.__dict__)
     strResponse = strResponse.replace(': null', ': ""')
     return strResponse
+
+
+def parse_pnfd(path, input_parameters=[]):
+    pass