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)
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)
import json
import logging
+import os
from lcm.pub.exceptions import NSLCMException
from lcm.pub.utils import restcall
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,
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
+
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: