update for change to etsicatalog
[modeling/etsicatalog.git] / catalog / pub / msapi / sdc.py
similarity index 79%
rename from genericparser/pub/msapi/sdc.py
rename to catalog/pub/msapi/sdc.py
index 81715de..bb473cc 100644 (file)
@@ -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 fileutil
-from genericparser.pub.utils import restcall
+from catalog.pub.config.config import SDC_BASE_URL, SDC_USER, SDC_PASSWD
+from catalog.pub.exceptions import CatalogException
+from catalog.pub.utils import fileutil
+from catalog.pub.utils import restcall
 
 logger = logging.getLogger(__name__)
 
@@ -30,7 +30,7 @@ DISTRIBUTED = "DISTRIBUTED"
 
 def call_sdc(resource, method, content=''):
     additional_headers = {
-        'X-ECOMP-InstanceID': 'Modeling',
+        'X-ECOMP-InstanceID': 'VFC',
     }
     return restcall.call_req(base_url=SDC_BASE_URL,
                              user=SDC_USER,
@@ -67,7 +67,7 @@ def get_artifacts(asset_type):
     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 query artifacts(%s) from sdc." % asset_type)
+        raise CatalogException("Failed to query artifacts(%s) from sdc." % asset_type)
     return json.JSONDecoder().decode(ret[1])
 
 
@@ -77,11 +77,10 @@ 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 CatalogException("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))
+    raise CatalogException("Failed to query artifact(%s,%s) from sdc." % (asset_type, csar_id))
 
 
 def get_asset(asset_type, uuid):
@@ -89,10 +88,10 @@ def get_asset(asset_type, 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))
+        raise CatalogException("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))
+        raise CatalogException("The asset (%s,%s) is not distributed from sdc." % (asset_type, uuid))
     else:
         return asset
 
@@ -103,13 +102,13 @@ def delete_artifact(asset_type, asset_id, artifact_id):
     ret = call_sdc(resource, "DELETE")
     if ret[0] != 0:
         logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
-        raise GenericparserException("Failed to delete artifacts(%s) from sdc." % artifact_id)
+        raise CatalogException("Failed to delete artifacts(%s) from sdc." % artifact_id)
     return json.JSONDecoder().decode(ret[1])
 
 
 def download_artifacts(download_url, local_path, file_name):
     additional_headers = {
-        'X-ECOMP-InstanceID': 'Modeling',
+        'X-ECOMP-InstanceID': 'VFC',
         'accept': 'application/octet-stream'
     }
     ret = restcall.call_req(base_url=SDC_BASE_URL,
@@ -121,7 +120,7 @@ def download_artifacts(download_url, local_path, file_name):
                             additional_headers=additional_headers)
     if ret[0] != 0:
         logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
-        raise GenericparserException("Failed to download %s from sdc." % download_url)
+        raise CatalogException("Failed to download %s from sdc." % download_url)
     fileutil.make_dirs(local_path)
     local_file_name = os.path.join(local_path, file_name)
     local_file = open(local_file_name, 'wb')