summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog/packages/biz/pnf_descriptor.py40
-rw-r--r--catalog/packages/biz/vnf_package.py4
-rw-r--r--catalog/packages/serializers/catalog_serializers.py46
-rw-r--r--catalog/pub/database/models.py1
4 files changed, 79 insertions, 12 deletions
diff --git a/catalog/packages/biz/pnf_descriptor.py b/catalog/packages/biz/pnf_descriptor.py
index 528fd178..e165c403 100644
--- a/catalog/packages/biz/pnf_descriptor.py
+++ b/catalog/packages/biz/pnf_descriptor.py
@@ -130,14 +130,50 @@ class PnfDescriptor(object):
pnfd_json = toscaparser.parse_pnfd(local_file_name)
pnfd = json.JSONDecoder().decode(pnfd_json)
- pnfd_id = pnfd["metadata"]["id"]
+ logger.debug("pnfd_json is %s" % pnfd_json)
+ pnfd_id = ""
+ pnfdVersion = ""
+ pnfdProvider = ""
+ pnfdName = ""
+ if pnfd.get("pnf", "") != "":
+ if pnfd["pnf"].get("properties", "") != "":
+ pnfd_id = pnfd["pnf"].get("properties", "").get("descriptor_id", "")
+ pnfdVersion = pnfd["pnf"].get("properties", "").get("version", "")
+ pnfdProvider = pnfd["pnf"].get("properties", "").get("provider", "")
+ pnfdName = pnfd["pnf"].get("properties", "").get("name", "")
+ if pnfd_id == "":
+ pnfd_id = pnfd["metadata"].get("descriptor_id", "")
+ if pnfd_id == "":
+ pnfd_id = pnfd["metadata"].get("id", "")
+ if pnfd_id == "":
+ pnfd_id = pnfd["metadata"].get("UUID", "")
+ if pnfd_id == "":
+ raise CatalogException('pnfd_id is Null.')
+
+ if pnfdVersion == "":
+ pnfdVersion = pnfd["metadata"].get("template_version", "")
+ if pnfdVersion == "":
+ pnfdVersion = pnfd["metadata"].get("version", "")
+
+ if pnfdProvider == "":
+ pnfdProvider = pnfd["metadata"].get("template_author", "")
+ if pnfdVersion == "":
+ pnfdVersion = pnfd["metadata"].get("provider", "")
+
+ if pnfdName == "":
+ pnfdName = pnfd["metadata"].get("template_name", "")
+ if pnfdVersion == "":
+ pnfdName = pnfd["metadata"].get("name", "")
+
if pnfd_id and PnfPackageModel.objects.filter(pnfdId=pnfd_id):
logger.info('PNFD(%s) already exists.' % pnfd_id)
raise CatalogException("PNFD(%s) already exists." % pnfd_id)
pnf_pkgs.update(
pnfdId=pnfd_id,
- pnfdVersion=pnfd["metadata"].get("version", "undefined"),
+ pnfdName=pnfdName,
+ pnfdVersion=pnfdVersion,
+ pnfVendor=pnfdProvider,
pnfPackageUri=local_file_name,
onboardingState=PKG_STATUS.ONBOARDED,
usageState=PKG_STATUS.NOT_IN_USE,
diff --git a/catalog/packages/biz/vnf_package.py b/catalog/packages/biz/vnf_package.py
index be8edba4..53f7fc0a 100644
--- a/catalog/packages/biz/vnf_package.py
+++ b/catalog/packages/biz/vnf_package.py
@@ -194,7 +194,9 @@ def parse_vnfd_and_save(vnf_pkg_id, vnf_pkg_path):
vnfd_json = toscaparser.parse_vnfd(vnf_pkg_path)
vnfd = json.JSONDecoder().decode(vnfd_json)
- vnfd_id = vnfd["metadata"]["id"]
+ vnfd_id = vnfd["metadata"].get("id", '')
+ if not vnfd_id:
+ raise CatalogException("VNFDID(metadata.id) of VNF(%s) does not exist." % vnf_pkg_id)
if VnfPackageModel.objects.filter(vnfdId=vnfd_id):
logger.error("VNF package(%s) already exists." % vnfd_id)
raise CatalogException("VNF package(%s) already exists." % vnfd_id)
diff --git a/catalog/packages/serializers/catalog_serializers.py b/catalog/packages/serializers/catalog_serializers.py
index 02fc9de2..265661db 100644
--- a/catalog/packages/serializers/catalog_serializers.py
+++ b/catalog/packages/serializers/catalog_serializers.py
@@ -73,31 +73,59 @@ class NsPackageDistributeResponseSerializer(serializers.Serializer):
class NsPackageInfoSerializer(serializers.Serializer):
- nsdId = serializers.CharField(help_text="NSD ID", required=True)
+ nsdId = serializers.CharField(
+ help_text="NSD ID",
+ required=False,
+ allow_null=True
+ )
nsPackageId = serializers.CharField(
- help_text="NS Package ID", allow_blank=True, required=True)
+ help_text="NS Package ID",
+ allow_blank=True,
+ required=False,
+ allow_null=True
+ )
nsdProvider = serializers.CharField(
- help_text="NSD Provider", allow_blank=True, required=True)
+ help_text="NSD Provider",
+ allow_blank=True,
+ required=False,
+ allow_null=True
+ )
nsdVersion = serializers.CharField(
help_text="NSD Version",
allow_blank=True,
- required=True)
+ required=False,
+ allow_null=True
+ )
csarName = serializers.CharField(
help_text="CSAR name",
allow_blank=True,
- required=True)
+ required=False,
+ allow_null=True
+ )
nsdModel = serializers.CharField(
help_text="NSD Model",
allow_blank=True,
- required=True)
+ required=False,
+ allow_null=True
+ )
downloadUrl = serializers.CharField(
- help_text="URL to download NSD Model", required=True)
+ help_text="URL to download NSD Model",
+ required=False,
+ allow_null=True
+ )
class NsPackageSerializer(serializers.Serializer):
- csarId = serializers.CharField(help_text="CSAR ID", required=True)
+ csarId = serializers.CharField(
+ help_text="CSAR ID",
+ required=False,
+ allow_null=True
+ )
packageInfo = NsPackageInfoSerializer(
- help_text="NS Package Info", required=True)
+ help_text="NS Package Info",
+ required=False,
+ allow_null=True
+ )
class NsPackagesSerializer(serializers.ListSerializer):
diff --git a/catalog/pub/database/models.py b/catalog/pub/database/models.py
index d150386d..04e39c29 100644
--- a/catalog/pub/database/models.py
+++ b/catalog/pub/database/models.py
@@ -78,6 +78,7 @@ class PnfPackageModel(models.Model):
userDefinedData = models.TextField(db_column='USERDEFINEDDATA', max_length=1024, blank=True, null=True) # userDefinedData
localFilePath = models.CharField(db_column='LOCALFILEPATH', max_length=300, null=True, blank=True)
pnfdModel = models.TextField(db_column='PNFDMODEL', max_length=65535, blank=True, null=True) # pnfd
+ pnfdName = models.TextField(db_column='PNFDNAME', max_length=65535, blank=True, null=True) # pnfd_name
class Meta:
db_table = 'CATALOG_PNFPACKAGE'