aboutsummaryrefslogtreecommitdiffstats
path: root/genericparser/pub
diff options
context:
space:
mode:
authordyh <dengyuanhong@chinamobile.com>2019-07-22 17:07:56 +0800
committerdyh <dengyuanhong@chinamobile.com>2019-07-22 17:09:53 +0800
commit0c9b3a3327db0bda7a60f68279900979488eccce (patch)
treec7f83bdf5142d2233b59e1bc423421d7b00b089f /genericparser/pub
parent444b802beadb9a7f1f5b03551b67f35cce1d6179 (diff)
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 <dengyuanhong@chinamobile.com>
Diffstat (limited to 'genericparser/pub')
-rw-r--r--genericparser/pub/msapi/sdc.py20
1 files changed, 17 insertions, 3 deletions
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)