diff options
-rw-r--r-- | lcm/packages/sdc_nf_package.py | 3 | ||||
-rw-r--r-- | lcm/packages/sdc_ns_package.py | 3 | ||||
-rw-r--r-- | lcm/pub/msapi/sdc.py | 22 | ||||
-rw-r--r-- | lcm/pub/utils/restcall.py | 7 |
4 files changed, 27 insertions, 8 deletions
diff --git a/lcm/packages/sdc_nf_package.py b/lcm/packages/sdc_nf_package.py index fe257a93..11f27b34 100644 --- a/lcm/packages/sdc_nf_package.py +++ b/lcm/packages/sdc_nf_package.py @@ -98,7 +98,8 @@ class SdcNfDistributeThread(threading.Thread): artifact = sdc.get_artifact(sdc.ASSETTYPE_RESOURCES, self.csar_id) local_path = os.path.join(CATALOG_ROOT_PATH, self.csar_id) - local_file_name = sdc.download_artifacts(artifact["toscaModelURL"], local_path) + local_file_name = sdc.download_artifacts(artifact["toscaModelURL"], + local_path, "%s.csar" % artifact.get("name", self.csar_id)) vnfd_json = toscaparser.parse_vnfd(local_file_name) vnfd = json.JSONDecoder().decode(vnfd_json) diff --git a/lcm/packages/sdc_ns_package.py b/lcm/packages/sdc_ns_package.py index d8960dd9..9824b39a 100644 --- a/lcm/packages/sdc_ns_package.py +++ b/lcm/packages/sdc_ns_package.py @@ -100,7 +100,8 @@ class SdcNsPackage(object): artifact = sdc.get_artifact(sdc.ASSETTYPE_SERVICES, csar_id) local_path = os.path.join(CATALOG_ROOT_PATH, csar_id) - local_file_name = sdc.download_artifacts(artifact["toscaModelURL"], local_path) + local_file_name = sdc.download_artifacts(artifact["toscaModelURL"], + local_path, "%s.csar" % artifact.get("name", csar_id)) nsd_json = toscaparser.parse_nsd(local_file_name) nsd = json.JSONDecoder().decode(nsd_json) diff --git a/lcm/pub/msapi/sdc.py b/lcm/pub/msapi/sdc.py index 79a48d2a..76f0d0c6 100644 --- a/lcm/pub/msapi/sdc.py +++ b/lcm/pub/msapi/sdc.py @@ -14,6 +14,7 @@ import json import logging +import os from lcm.pub.exceptions import NSLCMException from lcm.pub.utils import restcall @@ -26,7 +27,7 @@ ASSETTYPE_SERVICES = "services" def call_sdc(resource, method, content=''): additional_headers = { - 'X-ECOMP-InstanceID': 'VFC' + 'X-ECOMP-InstanceID': 'VFC', } return restcall.call_req(base_url=SDC_BASE_URL, user=SDC_USER, @@ -79,14 +80,27 @@ def delete_artifact(asset_type, asset_id, artifact_id): raise NSLCMException("Failed to delete artifacts(%s) from sdc." % artifact_id) return json.JSONDecoder().decode(ret[1]) -def download_artifacts(download_url, local_path): +def download_artifacts(download_url, local_path, file_name): + additional_headers = { + 'X-ECOMP-InstanceID': 'VFC', + 'accept': 'application/octet-stream' + } ret = restcall.call_req(base_url=SDC_BASE_URL, user=SDC_USER, passwd=SDC_PASSWD, auth_type=rest_no_auth, resource=download_url, - method="GET") - # TODO: + method="GET", + additional_headers=additional_headers) + if ret[0] != 0: + logger.error("Status code is %s, detail is %s.", ret[2], ret[1]) + raise NSLCMException("Failed to download %s from sdc." % download_url) + local_file_name = os.path.join(local_path, file_name) + local_file = open(local_file_name, 'wb') + local_file.write(ret[1]) + local_file.close() + return local_file_name + diff --git a/lcm/pub/utils/restcall.py b/lcm/pub/utils/restcall.py index d05d30b3..16f89ee8 100644 --- a/lcm/pub/utils/restcall.py +++ b/lcm/pub/utils/restcall.py @@ -49,8 +49,11 @@ def call_req(base_url, user, passwd, auth_type, resource, method, http.follow_all_redirects = True try: resp, resp_content = http.request(full_url, method=method.upper(), body=content, headers=headers) - resp_status, resp_body = resp['status'], resp_content.decode('UTF-8') - logger.debug("[%s][%d]status=%s,resp_body=%s)" % (callid, retry_times, resp_status, resp_body)) + resp_status, resp_body = resp['status'], resp_content + logger.debug("[%s][%d]status=%s)" % (callid, retry_times, resp_status)) + if headers['accept'] == 'application/json': + resp_body = resp_content.decode('UTF-8') + logger.debug("resp_body=%s", resp_body) if resp_status in status_ok_list: ret = [0, resp_body, resp_status] else: |