diff options
author | 2018-10-18 17:04:43 +0800 | |
---|---|---|
committer | 2018-10-18 17:04:43 +0800 | |
commit | 614f5003265ef06e8dd1e71133f8c5bc3f613583 (patch) | |
tree | 964f8940b733f0b1a17ceebf7296be0a8d63d1a4 | |
parent | b422b4f7d22e815077a518ab5ba3aa42694f9e2c (diff) |
PNF package update Model
update pnfd_id,pnfdVersion,pnfdProvider,pnfdName in model
Change-Id: Icee4144822b4cb77cd32fd317d90384642b66890
Issue-ID: VFC-1156
Signed-off-by: maopengzhang <zhang.maopeng1@zte.com.cn>
-rw-r--r-- | catalog/packages/biz/pnf_descriptor.py | 42 | ||||
-rw-r--r-- | catalog/pub/database/models.py | 1 |
2 files changed, 39 insertions, 4 deletions
diff --git a/catalog/packages/biz/pnf_descriptor.py b/catalog/packages/biz/pnf_descriptor.py index f1dc55b2..e165c403 100644 --- a/catalog/packages/biz/pnf_descriptor.py +++ b/catalog/packages/biz/pnf_descriptor.py @@ -130,16 +130,50 @@ class PnfDescriptor(object): pnfd_json = toscaparser.parse_pnfd(local_file_name) pnfd = json.JSONDecoder().decode(pnfd_json) - pnfd_id = pnfd["metadata"].get("id", '') - if not pnfd_id: - raise CatalogException("PNFDID(metadata.id) of PNF(%s) does not exist." % pnfd_info_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/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' |