diff options
-rw-r--r-- | catalog/packages/biz/pnf_descriptor.py | 23 | ||||
-rw-r--r-- | catalog/pub/utils/toscaparser/__init__.py | 4 |
2 files changed, 27 insertions, 0 deletions
diff --git a/catalog/packages/biz/pnf_descriptor.py b/catalog/packages/biz/pnf_descriptor.py index 87b6978f..74812912 100644 --- a/catalog/packages/biz/pnf_descriptor.py +++ b/catalog/packages/biz/pnf_descriptor.py @@ -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: diff --git a/catalog/pub/utils/toscaparser/__init__.py b/catalog/pub/utils/toscaparser/__init__.py index 56c020ed..604bb23f 100644 --- a/catalog/pub/utils/toscaparser/__init__.py +++ b/catalog/pub/utils/toscaparser/__init__.py @@ -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 |