From 0c9b3a3327db0bda7a60f68279900979488eccce Mon Sep 17 00:00:00 2001 From: dyh Date: Mon, 22 Jul 2019 17:07:56 +0800 Subject: update the logic to distribute service from sdc. 1. Call /sdc/v1/catalog/{assetType}/{uuid}/metadata to get service metadata by given uuid. 2. Check if related resources exist before download CSAR package. Change-Id: I6ea5b9f5d2844b232901ce83eedb574f5bd3d552 Issue-ID: MODELING-189 Signed-off-by: dyh --- genericparser/pub/msapi/sdc.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'genericparser/pub') diff --git a/genericparser/pub/msapi/sdc.py b/genericparser/pub/msapi/sdc.py index e95c1ca..81715de 100644 --- a/genericparser/pub/msapi/sdc.py +++ b/genericparser/pub/msapi/sdc.py @@ -16,10 +16,10 @@ import json import logging import os +from genericparser.pub.config.config import SDC_BASE_URL, SDC_USER, SDC_PASSWD from genericparser.pub.exceptions import GenericparserException -from genericparser.pub.utils import restcall from genericparser.pub.utils import fileutil -from genericparser.pub.config.config import SDC_BASE_URL, SDC_USER, SDC_PASSWD +from genericparser.pub.utils import restcall logger = logging.getLogger(__name__) @@ -77,12 +77,26 @@ def get_artifact(asset_type, csar_id): if artifact["uuid"] == csar_id: if asset_type == ASSETTYPE_SERVICES and \ artifact.get("distributionStatus", None) != DISTRIBUTED: - raise GenericparserException("The artifact (%s,%s) is not distributed from sdc." % (asset_type, csar_id)) + raise GenericparserException( + "The artifact (%s,%s) is not distributed from sdc." % (asset_type, csar_id)) else: return artifact raise GenericparserException("Failed to query artifact(%s,%s) from sdc." % (asset_type, csar_id)) +def get_asset(asset_type, uuid): + resource = "/sdc/v1/catalog/{assetType}/{uuid}/metadata".format(assetType=asset_type, uuid=uuid) + ret = call_sdc(resource, "GET") + if ret[0] != 0: + logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) + raise GenericparserException("Failed to get asset(%s, %s) from sdc." % (asset_type, uuid)) + asset = json.JSONDecoder().decode(ret[1]) + if asset.get("distributionStatus", None) != DISTRIBUTED: + raise GenericparserException("The asset (%s,%s) is not distributed from sdc." % (asset_type, uuid)) + else: + return asset + + def delete_artifact(asset_type, asset_id, artifact_id): resource = "/sdc/v1/catalog/{assetType}/{uuid}/artifacts/{artifactUUID}" resource = resource.format(assetType=asset_type, uuid=asset_id, artifactUUID=artifact_id) -- cgit 1.2.3-korg