diff options
Diffstat (limited to 'genericparser/pub')
-rw-r--r-- | genericparser/pub/msapi/sdc.py | 20 |
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) |